Debian Codegraph @

tests/test_additional_response_extra.py

raw
1 from fastapi import APIRouter, FastAPI
2 from fastapi.testclient import TestClient
3 from inline_snapshot import snapshot
4
5 router = APIRouter()
6
7 sub_router = APIRouter()
8
9 app = FastAPI()
10
11
12 @sub_router.get("/")
13 def read_item():
14 return {"id": "foo"}
15
16
17 router.include_router(sub_router, prefix="/items")
18
19 app.include_router(router)
20
21 client = TestClient(app)
22
23
24 def test_path_operation():
25 response = client.get("/items/")
26 assert response.status_code == 200, response.text
27 assert response.json() == {"id": "foo"}
28
29
30 def test_openapi_schema():
31 response = client.get("/openapi.json")
32 assert response.status_code == 200, response.text
33 assert response.json() == snapshot(
34 {
35 "openapi": "3.1.0",
36 "info": {"title": "FastAPI", "version": "0.1.0"},
37 "paths": {
38 "/items/": {
39 "get": {
40 "responses": {
41 "200": {
42 "description": "Successful Response",
43 "content": {"application/json": {"schema": {}}},
44 }
45 },
46 "summary": "Read Item",
47 "operationId": "read_item_items__get",
48 }
49 }
50 },
51 }
52 )