-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusage_sync.py
More file actions
41 lines (31 loc) · 1.31 KB
/
Copy pathusage_sync.py
File metadata and controls
41 lines (31 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from __future__ import annotations
from typing import assert_type
from generated.my_client import AsyncClient, Client
from generated.my_client.types import Book
client = Client(base_url="http://testserver")
async_client = AsyncClient(base_url="http://testserver")
book = client.get("/books/{book_id}")(params={"book_id": 1})
assert_type(book, Book)
assert_type(book["id"], int)
assert_type(book["title"], str)
assert_type(book["in_print"], bool)
assert_type(book["tags"], list[str])
books = client.get("/books")(query={"limit": 5})
assert_type(books, list[Book])
assert_type(books[0]["title"], str)
created = client.post("/books")(body={"title": "Dawn", "tags": ["sf"]})
assert_type(created, Book)
assert_type(created["tags"], list[str])
async def use_async_client() -> None:
book = await async_client.get("/books/{book_id}")(params={"book_id": 1})
assert_type(book, Book)
assert_type(book["id"], int)
assert_type(book["title"], str)
assert_type(book["in_print"], bool)
assert_type(book["tags"], list[str])
books = await async_client.get("/books")(query={"limit": 5})
assert_type(books, list[Book])
assert_type(books[0]["title"], str)
created = await async_client.post("/books")(body={"title": "Dawn", "tags": ["sf"]})
assert_type(created, Book)
assert_type(created["tags"], list[str])