-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from chirizxc/develop
fix parse_func
- Loading branch information
Showing
2 changed files
with
60 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from dataclasses import dataclass | ||
from typing import List, Optional | ||
|
||
import requests | ||
import requests_mock | ||
|
||
from dataclass_rest import get, post | ||
from dataclass_rest.http.requests import RequestsClient | ||
|
||
|
||
@dataclass | ||
class TestBody: | ||
value: int | ||
|
||
|
||
def test_string_hints(session: requests.Session, mocker: requests_mock.Mocker): | ||
class Api(RequestsClient): | ||
@get("/items/{item_id}") | ||
def get_item(self, item_id: "str") -> "List[int]": | ||
raise NotImplementedError | ||
|
||
@post("/items") | ||
def create_item(self, body: "TestBody") -> "Optional[int]": | ||
raise NotImplementedError | ||
|
||
mocker.get( | ||
"http://example.com/items/1", | ||
text="[1, 2, 3]", | ||
complete_qs=True, | ||
) | ||
mocker.post("http://example.com/items", text="1", complete_qs=True) | ||
|
||
client = Api(base_url="http://example.com", session=session) | ||
|
||
assert client.get_item("1") == [1, 2, 3] | ||
assert client.create_item(TestBody(value=5)) == 1 |