From 091927342942fb1aa57bf45a8815155488519731 Mon Sep 17 00:00:00 2001 From: Angel <145038102+KurosawaAngel@users.noreply.github.com> Date: Tue, 8 Oct 2024 06:48:39 +0500 Subject: [PATCH 1/2] fix kwonlyargs --- src/dataclass_rest/parse_func.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dataclass_rest/parse_func.py b/src/dataclass_rest/parse_func.py index acbffab..43a99ee 100644 --- a/src/dataclass_rest/parse_func.py +++ b/src/dataclass_rest/parse_func.py @@ -31,7 +31,7 @@ def create_query_params_type( ) -> Type: fields = {} self_processed = False - for x in spec.args: + for x in spec.args + spec.kwonlyargs: if not self_processed: self_processed = True continue From 14574ebde2f6fe8cc0a62027e06526286c7dbd74 Mon Sep 17 00:00:00 2001 From: Kurosawa <145038102+KurosawaAngel@users.noreply.github.com> Date: Wed, 9 Oct 2024 00:35:26 +0500 Subject: [PATCH 2/2] add test --- tests/requests/test_params.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/requests/test_params.py b/tests/requests/test_params.py index d91fc56..89466ef 100644 --- a/tests/requests/test_params.py +++ b/tests/requests/test_params.py @@ -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]