Skip to content

Commit

Permalink
Merge pull request #41 from KurosawaAngel/patch-1
Browse files Browse the repository at this point in the history
fix kwonlyargs
  • Loading branch information
Tishka17 authored Oct 10, 2024
2 parents 9bb5665 + 14574eb commit 9318492
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/dataclass_rest/parse_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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 9318492

Please sign in to comment.