Skip to content

Commit 9961e9b

Browse files
authored
Handle multiple routes using MuitiItems pattern with ANY (#289)
1 parent e51c2a6 commit 9961e9b

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

respx/patterns.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,21 +288,33 @@ class MultiItemsMixin:
288288
value: Any
289289

290290
def _multi_items(
291-
self, value: Any, *, parse_any: bool = False
291+
self, value: Any, *, parse_any: bool = False, encode_any: bool = False
292292
) -> Tuple[Tuple[str, Tuple[Any, ...]], ...]:
293293
return tuple(
294294
(
295295
key,
296296
tuple(
297-
ANY if parse_any and v == str(ANY) else v
297+
(
298+
ANY
299+
if parse_any and v == str(ANY)
300+
else str(ANY)
301+
if encode_any and v == ANY
302+
else v
303+
)
298304
for v in value.get_list(key)
299305
),
300306
)
301307
for key in sorted(value.keys())
302308
)
303309

304310
def __hash__(self):
305-
return hash((self.__class__, self.lookup, self._multi_items(self.value)))
311+
return hash(
312+
(
313+
self.__class__,
314+
self.lookup,
315+
self._multi_items(self.value, encode_any=True),
316+
)
317+
)
306318

307319
def _eq(self, value: Any) -> Match:
308320
value_items = self._multi_items(self.value, parse_any=True)

tests/test_api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ def test_files_post_body():
276276
with respx.mock:
277277
url = "https://foo.bar/"
278278
file = ("file", ("filename.txt", b"...", "text/plain", {"X-Foo": "bar"}))
279+
respx.post(url + "other", files={"file": mock.ANY}) # Non-matching ANY
279280
route = respx.post(url, files={"file": mock.ANY}) % 201
280281
response = httpx.post(url, files=[file])
281282
assert response.status_code == 201

0 commit comments

Comments
 (0)