@@ -41,6 +41,19 @@ async def test_url_matching(httpx_mock: HTTPXMock):
4141 assert response .content == b""
4242
4343
44+ @pytest .mark .asyncio
45+ async def test_url_query_string_matching (httpx_mock : HTTPXMock ):
46+ httpx_mock .add_response (url = "http://test_url?a=1&b=2" )
47+
48+ async with httpx .AsyncClient () as client :
49+ response = await client .post ("http://test_url?a=1&b=2" )
50+ assert response .content == b""
51+
52+ # Parameters order should not matter
53+ response = await client .get ("http://test_url?b=2&a=1" )
54+ assert response .content == b""
55+
56+
4457@pytest .mark .asyncio
4558async def test_url_not_matching (httpx_mock : HTTPXMock ):
4659 httpx_mock .add_response (url = "http://test_url" )
@@ -58,6 +71,24 @@ async def test_url_not_matching(httpx_mock: HTTPXMock):
5871 httpx_mock .reset (assert_all_responses_were_requested = False )
5972
6073
74+ @pytest .mark .asyncio
75+ async def test_url_query_string_not_matching (httpx_mock : HTTPXMock ):
76+ httpx_mock .add_response (url = "http://test_url?a=1&a=2" )
77+
78+ async with httpx .AsyncClient () as client :
79+ with pytest .raises (httpx .TimeoutException ) as exception_info :
80+ # Same parameter order matters as it corresponds to a list on server side
81+ await client .get ("http://test_url?a=2&a=1" )
82+ assert (
83+ str (exception_info .value )
84+ == """No response can be found for GET request on http://test_url?a=2&a=1 amongst:
85+ Match all requests on http://test_url?a=1&a=2"""
86+ )
87+
88+ # Clean up responses to avoid assertion failure
89+ httpx_mock .reset (assert_all_responses_were_requested = False )
90+
91+
6192@pytest .mark .asyncio
6293async def test_method_matching (httpx_mock : HTTPXMock ):
6394 httpx_mock .add_response (method = "get" )
0 commit comments