Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
KurosawaAngel committed Oct 8, 2024
1 parent 0919273 commit 14574eb
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/requests/test_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,35 @@ def post_x(self, body: RequestBody) -> None:
assert client.post_x(RequestBody(x=1, y="test")) is None
assert mocker.called_once
assert mocker.request_history[0].json() == {"x": 1, "y": "test"}


def test_kwonly_param(session: requests.Session, mocker: requests_mock.Mocker):
class Api(RequestsClient):
@post("/post/")
def post(
self,
*,
body: RequestBody,
) -> None:
raise NotImplementedError

@get("/get/{id}")
def get_x(self, *, id: str, param: str = "1") -> List[int]:
raise NotImplementedError

mocker.post(
url="http://example.com/post/",
text="null",
complete_qs=True,
)
mocker.get(
url="http://example.com/get/x?param=1",
text="[0]",
complete_qs=True,
)
client = Api(base_url="http://example.com", session=session)
assert client.post(body=RequestBody(x=1, y="test")) is None
assert mocker.called_once
assert mocker.request_history[0].json() == {"x": 1, "y": "test"}

assert client.get_x(id="x") == [0]

0 comments on commit 14574eb

Please sign in to comment.