@@ -142,7 +142,9 @@ class Entry(MocketEntry):
142
142
request_cls = Request
143
143
response_cls = Response
144
144
145
- def __init__ (self , uri , method , responses , match_querystring = True ):
145
+ default_config = {"match_querystring" : True }
146
+
147
+ def __init__ (self , uri , method , responses , match_querystring : bool = True ):
146
148
uri = urlsplit (uri )
147
149
148
150
port = uri .port
@@ -151,7 +153,7 @@ def __init__(self, uri, method, responses, match_querystring=True):
151
153
152
154
super ().__init__ ((uri .hostname , port ), responses )
153
155
self .schema = uri .scheme
154
- self .path = uri .path
156
+ self .path = uri .path or "/"
155
157
self .query = uri .query
156
158
self .method = method .upper ()
157
159
self ._sent_data = b""
@@ -227,16 +229,15 @@ def register(cls, method, uri, *responses, **config):
227
229
if "body" in config or "status" in config :
228
230
raise AttributeError ("Did you mean `Entry.single_register(...)`?" )
229
231
230
- default_config = dict (match_querystring = True , add_trailing_slash = True )
231
- default_config .update (config )
232
- config = default_config
232
+ if config .keys () - cls .default_config .keys ():
233
+ raise KeyError (
234
+ f"Invalid config keys: { config .keys () - cls .default_config .keys ()} "
235
+ )
233
236
234
- if config [ "add_trailing_slash" ] and not urlsplit ( uri ). path :
235
- uri += "/"
237
+ _config = cls . default_config . copy ()
238
+ _config . update ({ k : v for k , v in config . items () if k in _config })
236
239
237
- Mocket .register (
238
- cls (uri , method , responses , match_querystring = config ["match_querystring" ])
239
- )
240
+ Mocket .register (cls (uri , method , responses , ** _config ))
240
241
241
242
@classmethod
242
243
def single_register (
@@ -246,8 +247,9 @@ def single_register(
246
247
body = "" ,
247
248
status = 200 ,
248
249
headers = None ,
249
- match_querystring = True ,
250
250
exception = None ,
251
+ match_querystring = True ,
252
+ ** config ,
251
253
):
252
254
response = (
253
255
exception
@@ -260,4 +262,5 @@ def single_register(
260
262
uri ,
261
263
response ,
262
264
match_querystring = match_querystring ,
265
+ ** config ,
263
266
)
0 commit comments