From 876fc6d3d609b9bf963a809950e5d1e6b86b035b Mon Sep 17 00:00:00 2001 From: chiri <2alivemafia@gmail.com> Date: Thu, 31 Oct 2024 19:30:30 +0300 Subject: [PATCH] add tests --- tests/requests/test_parse_func.py | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/requests/test_parse_func.py diff --git a/tests/requests/test_parse_func.py b/tests/requests/test_parse_func.py new file mode 100644 index 0000000..9a434e7 --- /dev/null +++ b/tests/requests/test_parse_func.py @@ -0,0 +1,34 @@ +#from __future__ import annotations + +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