Debian Codegraph @

tests/test_tutorial/test_events/test_tutorial001.py

raw
1 import pytest
2 from fastapi import FastAPI
3 from fastapi.testclient import TestClient
4 from inline_snapshot import snapshot
5
6
7 @pytest.fixture(name="app", scope="module")
8 def get_app():
9 with pytest.warns(DeprecationWarning):
10 from docs_src.events.tutorial001_py310 import app
11 yield app
12
13
14 def test_events(app: FastAPI):
15 with TestClient(app) as client:
16 response = client.get("/items/foo")
17 assert response.status_code == 200, response.text
18 assert response.json() == {"name": "Fighters"}
19
20
21 def test_openapi_schema(app: FastAPI):
22 with TestClient(app) as client:
23 response = client.get("/openapi.json")
24 assert response.status_code == 200, response.text
25 assert response.json() == snapshot(
26 {
27 "openapi": "3.1.0",
28 "info": {"title": "FastAPI", "version": "0.1.0"},
29 "paths": {
30 "/items/{item_id}": {
31 "get": {
32 "responses": {
33 "200": {
34 "description": "Successful Response",
35 "content": {"application/json": {"schema": {}}},
36 },
37 "422": {
38 "description": "Validation Error",
39 "content": {
40 "application/json": {
41 "schema": {
42 "$ref": "#/components/schemas/HTTPValidationError"
43 }
44 }
45 },
46 },
47 },
48 "summary": "Read Items",
49 "operationId": "read_items_items__item_id__get",
50 "parameters": [
51 {
52 "required": True,
53 "schema": {"title": "Item Id", "type": "string"},
54 "name": "item_id",
55 "in": "path",
56 }
57 ],
58 }
59 }
60 },
61 "components": {
62 "schemas": {
63 "ValidationError": {
64 "title": "ValidationError",
65 "required": ["loc", "msg", "type"],
66 "type": "object",
67 "properties": {
68 "ctx": {"title": "Context", "type": "object"},
69 "input": {"title": "Input"},
70 "loc": {
71 "title": "Location",
72 "type": "array",
73 "items": {
74 "anyOf": [
75 {"type": "string"},
76 {"type": "integer"},
77 ]
78 },
79 },
80 "msg": {"title": "Message", "type": "string"},
81 "type": {"title": "Error Type", "type": "string"},
82 },
83 },
84 "HTTPValidationError": {
85 "title": "HTTPValidationError",
86 "type": "object",
87 "properties": {
88 "detail": {
89 "title": "Detail",
90 "type": "array",
91 "items": {
92 "$ref": "#/components/schemas/ValidationError"
93 },
94 }
95 },
96 },
97 }
98 },
99 }
100 )