From 39b4851deff351d2d606891eaaa883ac9100a9eb Mon Sep 17 00:00:00 2001 From: Andrey Tikhonov <17@itishka.org> Date: Fri, 17 May 2024 17:11:30 +0200 Subject: [PATCH] more strict matching --- requirements_dev.txt | 1 - tests/requests/test_factory.py | 4 ++-- tests/requests/test_params.py | 16 ++++++++-------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/requirements_dev.txt b/requirements_dev.txt index 48476ff..23604f7 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -3,7 +3,6 @@ typing_extensions aiohttp requests requests-mock -nose2 mypy pytest pytest-asyncio \ No newline at end of file diff --git a/tests/requests/test_factory.py b/tests/requests/test_factory.py index 05bf77a..4a5d762 100644 --- a/tests/requests/test_factory.py +++ b/tests/requests/test_factory.py @@ -46,8 +46,9 @@ def post_x(self, long_param: str, body: RequestBody) -> ResponseBody: raise NotImplementedError() mocker.patch( - url="http://example.com/post/", + url="http://example.com/post/?LONG.PARAM=hello", text="""{"int-param": 1, "selection": "TWO"}""", + complete_qs=True, ) client = Api(base_url="http://example.com", session=session) result = client.post_x( @@ -56,4 +57,3 @@ def post_x(self, long_param: str, body: RequestBody) -> ResponseBody: assert result == ResponseBody(int_param=1, selection=Selection.TWO) assert mocker.called_once assert mocker.request_history[0].json() == {"intParam": 42, "selection": "ONE"} - assert mocker.request_history[0].query == "LONG.PARAM=hello" diff --git a/tests/requests/test_params.py b/tests/requests/test_params.py index 6b0b958..50a8573 100644 --- a/tests/requests/test_params.py +++ b/tests/requests/test_params.py @@ -15,8 +15,8 @@ def get_x(self) -> list[int]: def post_x(self) -> list[int]: raise NotImplementedError() - mocker.get("http://example.com/get", text="[1,2]") - mocker.post("http://example.com/post", text="[1,2,3]") + mocker.get("http://example.com/get", text="[1,2]", complete_qs=True) + mocker.post("http://example.com/post", text="[1,2,3]", complete_qs=True) client = Api(base_url="http://example.com", session=session) assert client.get_x() == [1, 2] assert client.post_x() == [1, 2, 3] @@ -28,8 +28,8 @@ class Api(RequestsClient): def post_x(self, id) -> list[int]: raise NotImplementedError() - mocker.post("http://example.com/post/1", text="[1]") - mocker.post("http://example.com/post/2", text="[1,2]") + mocker.post("http://example.com/post/1", text="[1]", complete_qs=True) + mocker.post("http://example.com/post/2", text="[1,2]", complete_qs=True) client = Api(base_url="http://example.com", session=session) assert client.post_x(1) == [1] assert client.post_x(2) == [1, 2] @@ -41,9 +41,9 @@ class Api(RequestsClient): def post_x(self, id: str, param: Optional[int]) -> list[int]: raise NotImplementedError() - mocker.post("http://example.com/post/x?", text="[0]") - mocker.post("http://example.com/post/x?param=1", text="[1]") - mocker.post("http://example.com/post/x?param=2", text="[1,2]") + mocker.post("http://example.com/post/x?", text="[0]", complete_qs=True) + mocker.post("http://example.com/post/x?param=1", text="[1]", complete_qs=True) + mocker.post("http://example.com/post/x?param=2", text="[1,2]", complete_qs=True) client = Api(base_url="http://example.com", session=session) assert client.post_x("x", None) == [0] assert client.post_x("x", 1) == [1] @@ -62,7 +62,7 @@ class Api(RequestsClient): def post_x(self, body: RequestBody) -> None: raise NotImplementedError() - mocker.post("http://example.com/post/", text="null") + mocker.post("http://example.com/post/", text="null", complete_qs=True) client = Api(base_url="http://example.com", session=session) assert client.post_x(RequestBody(x=1, y="test")) is None assert mocker.called_once