diff --git a/respx/patterns.py b/respx/patterns.py index c5b351d..2ed5525 100644 --- a/respx/patterns.py +++ b/respx/patterns.py @@ -289,13 +289,19 @@ class MultiItemsMixin: value: Any def _multi_items( - self, value: Any, *, parse_any: bool = False + self, value: Any, *, parse_any: bool = False, encode_any: bool = False ) -> Tuple[Tuple[str, Tuple[Any, ...]], ...]: return tuple( ( key, tuple( - ANY if parse_any and v == str(ANY) else v + ( + ANY + if parse_any and v == str(ANY) + else str(ANY) + if encode_any and v == ANY + else v + ) for v in value.get_list(key) ), ) @@ -303,7 +309,13 @@ def _multi_items( ) def __hash__(self): - return hash((self.__class__, self.lookup, self._multi_items(self.value))) + return hash( + ( + self.__class__, + self.lookup, + self._multi_items(self.value, encode_any=True), + ) + ) def _eq(self, value: Any) -> Match: value_items = self._multi_items(self.value, parse_any=True) diff --git a/tests/test_api.py b/tests/test_api.py index 81ca4b2..e9ed702 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -276,6 +276,7 @@ def test_files_post_body(): with respx.mock: url = "https://foo.bar/" file = ("file", ("filename.txt", b"...", "text/plain", {"X-Foo": "bar"})) + respx.post(url + "other", files={"file": mock.ANY}) # Non-matching ANY route = respx.post(url, files={"file": mock.ANY}) % 201 response = httpx.post(url, files=[file]) assert response.status_code == 201