Coverage for tests / test_tutorial / test_extending_openapi / test_tutorial001.py: 100%
16 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
1from fastapi.testclient import TestClient 1defg
2from inline_snapshot import snapshot 1defg
4from docs_src.extending_openapi.tutorial001_py310 import app 1defg
6client = TestClient(app) 1defg
9def test(): 1defg
10 response = client.get("/items/") 1hij
11 assert response.status_code == 200, response.text 1hij
12 assert response.json() == [{"name": "Foo"}] 1hij
15def test_openapi_schema(): 1defg
16 response = client.get("/openapi.json") 1abc
17 assert response.status_code == 200, response.text 1abc
18 assert response.json() == snapshot( 1abc
19 {
20 "openapi": "3.1.0",
21 "info": {
22 "title": "Custom title",
23 "summary": "This is a very custom OpenAPI schema",
24 "description": "Here's a longer description of the custom **OpenAPI** schema",
25 "version": "2.5.0",
26 "x-logo": {
27 "url": "https://fastapi.tiangolo.com/img/logo-margin/logo-teal.png"
28 },
29 },
30 "paths": {
31 "/items/": {
32 "get": {
33 "responses": {
34 "200": {
35 "description": "Successful Response",
36 "content": {"application/json": {"schema": {}}},
37 }
38 },
39 "summary": "Read Items",
40 "operationId": "read_items_items__get",
41 }
42 }
43 },
44 }
45 )
46 openapi_schema = response.json() 1abc
47 # Request again to test the custom cache
48 response = client.get("/openapi.json") 1abc
49 assert response.status_code == 200, response.text 1abc
50 assert response.json() == openapi_schema 1abc