Skip to content

Commit

Permalink
more strict matching
Browse files Browse the repository at this point in the history
  • Loading branch information
Tishka17 committed May 17, 2024
1 parent baf55c9 commit 39b4851
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
1 change: 0 additions & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ typing_extensions
aiohttp
requests
requests-mock
nose2
mypy
pytest
pytest-asyncio
4 changes: 2 additions & 2 deletions tests/requests/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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"
16 changes: 8 additions & 8 deletions tests/requests/test_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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
Expand Down

0 comments on commit 39b4851

Please sign in to comment.