Coverage for tests/test_tutorial/test_dataclasses/test_tutorial002.py: 100%
12 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
1from dirty_equals import IsDict, IsOneOf 1abcde
2from fastapi.testclient import TestClient 1abcde
4from docs_src.dataclasses.tutorial002 import app 1abcde
6client = TestClient(app) 1abcde
9def test_get_item(): 1abcde
10 response = client.get("/items/next") 1abcde
11 assert response.status_code == 200 1abcde
12 assert response.json() == { 1abcde
13 "name": "Island In The Moon",
14 "price": 12.99,
15 "description": "A place to be playin' and havin' fun",
16 "tags": ["breater"],
17 "tax": None,
18 }
21def test_openapi_schema(): 1abcde
22 response = client.get("/openapi.json") 1abcde
23 assert response.status_code == 200 1abcde
24 assert response.json() == { 1abcde
25 "openapi": "3.1.0",
26 "info": {"title": "FastAPI", "version": "0.1.0"},
27 "paths": {
28 "/items/next": {
29 "get": {
30 "summary": "Read Next Item",
31 "operationId": "read_next_item_items_next_get",
32 "responses": {
33 "200": {
34 "description": "Successful Response",
35 "content": {
36 "application/json": {
37 "schema": {"$ref": "#/components/schemas/Item"}
38 }
39 },
40 }
41 },
42 }
43 }
44 },
45 "components": {
46 "schemas": {
47 "Item": {
48 "title": "Item",
49 "required": IsOneOf(
50 ["name", "price", "tags", "description", "tax"],
51 # TODO: remove when deprecating Pydantic v1
52 ["name", "price"],
53 ),
54 "type": "object",
55 "properties": {
56 "name": {"title": "Name", "type": "string"},
57 "price": {"title": "Price", "type": "number"},
58 "tags": IsDict(
59 {
60 "title": "Tags",
61 "type": "array",
62 "items": {"type": "string"},
63 }
64 )
65 | IsDict(
66 # TODO: remove when deprecating Pydantic v1
67 {
68 "title": "Tags",
69 "type": "array",
70 "items": {"type": "string"},
71 }
72 ),
73 "description": IsDict(
74 {
75 "title": "Description",
76 "anyOf": [{"type": "string"}, {"type": "null"}],
77 }
78 )
79 | IsDict(
80 # TODO: remove when deprecating Pydantic v1
81 {"title": "Description", "type": "string"}
82 ),
83 "tax": IsDict(
84 {
85 "title": "Tax",
86 "anyOf": [{"type": "number"}, {"type": "null"}],
87 }
88 )
89 | IsDict(
90 # TODO: remove when deprecating Pydantic v1
91 {"title": "Tax", "type": "number"}
92 ),
93 },
94 }
95 }
96 },
97 }