Skip to content

Commit 2b59b54

Browse files
author
huangsong
committed
add tests of list response
1 parent 7e44893 commit 2b59b54

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

pydantic_client/schema/method_info.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Callable, Dict, Optional, Type, Union
1+
from typing import Any, Callable, Dict, Optional
22

33
from pydantic import BaseModel
44

@@ -10,5 +10,5 @@ class MethodInfo(BaseModel):
1010
http_method: str
1111
url: str
1212
request_type: Dict[str, Any]
13-
response_type: Optional[Type]
13+
response_type: Optional[Any]
1414
form_body: bool

tests/conftest.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
import typing
23
from aiohttp import ClientSession
34
from httpx import AsyncClient
45
from requests import Session
@@ -12,7 +13,6 @@
1213

1314
config_1 = ClientConfig(
1415
base_url=server_url,
15-
timeout=10
1616
)
1717

1818
config_2 = ClientConfig(
@@ -51,6 +51,10 @@
5151
@pydantic_client_manager.register(config_1)
5252
class R:
5353

54+
@get("/book_list")
55+
def get_books(self) -> typing.List:
56+
...
57+
5458
@get("/books/{book_id}?query={query}")
5559
def get_book(self, book_id: int, query: str) -> Book:
5660
...
@@ -88,6 +92,11 @@ def download(self) -> File:
8892

8993
@pydantic_client_manager.register(config_3)
9094
class AsyncR:
95+
96+
@get("/book_list")
97+
async def get_books(self) -> typing.List:
98+
...
99+
91100
@get("/books/{book_id}?query={query}")
92101
async def get_book(self, book_id: int, query: str) -> Book:
93102
...
@@ -150,7 +159,6 @@ def fastapi_server_url() -> str:
150159
from threading import Thread
151160
host = "localhost"
152161
port = 12098 # TODO: add port availability check
153-
154162
def start_server():
155163
run(app, host=host, port=port)
156164

tests/fastapi_service.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import typing
23

34
from fastapi import FastAPI, Form
45
from starlette.responses import FileResponse
@@ -14,6 +15,11 @@ async def get() -> Book:
1415
return get_the_book()
1516

1617

18+
@app.get("/book_list")
19+
async def get_list() -> typing.List:
20+
return ["1", "2"]
21+
22+
1723
@app.get("/books/{book_id}")
1824
def get_raw_book(book_id: int):
1925
return get_the_book()

tests/test_client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ async def test_get(clients):
1515
assert book.age == 1
1616

1717

18+
@pytest.mark.asyncio
19+
async def test_get(clients):
20+
for cl in clients:
21+
book = cl.get_books()
22+
if inspect.isawaitable(book):
23+
book = await book
24+
assert book == ["1", "2"]
25+
26+
1827
@pytest.mark.asyncio
1928
async def test_get_num_pages(clients):
2029
for cl in clients:

0 commit comments

Comments
 (0)