Skip to content

Commit 9318492

Browse files
authored
Merge pull request #41 from KurosawaAngel/patch-1
fix kwonlyargs
2 parents 9bb5665 + 14574eb commit 9318492

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/dataclass_rest/parse_func.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def create_query_params_type(
3131
) -> Type:
3232
fields = {}
3333
self_processed = False
34-
for x in spec.args:
34+
for x in spec.args + spec.kwonlyargs:
3535
if not self_processed:
3636
self_processed = True
3737
continue

tests/requests/test_params.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,35 @@ def post_x(self, body: RequestBody) -> None:
8686
assert client.post_x(RequestBody(x=1, y="test")) is None
8787
assert mocker.called_once
8888
assert mocker.request_history[0].json() == {"x": 1, "y": "test"}
89+
90+
91+
def test_kwonly_param(session: requests.Session, mocker: requests_mock.Mocker):
92+
class Api(RequestsClient):
93+
@post("/post/")
94+
def post(
95+
self,
96+
*,
97+
body: RequestBody,
98+
) -> None:
99+
raise NotImplementedError
100+
101+
@get("/get/{id}")
102+
def get_x(self, *, id: str, param: str = "1") -> List[int]:
103+
raise NotImplementedError
104+
105+
mocker.post(
106+
url="http://example.com/post/",
107+
text="null",
108+
complete_qs=True,
109+
)
110+
mocker.get(
111+
url="http://example.com/get/x?param=1",
112+
text="[0]",
113+
complete_qs=True,
114+
)
115+
client = Api(base_url="http://example.com", session=session)
116+
assert client.post(body=RequestBody(x=1, y="test")) is None
117+
assert mocker.called_once
118+
assert mocker.request_history[0].json() == {"x": 1, "y": "test"}
119+
120+
assert client.get_x(id="x") == [0]

0 commit comments

Comments
 (0)