Debian Codegraph @

tests/test_tutorial/test_behind_a_proxy/test_tutorial003.py

raw
1 from fastapi.testclient import TestClient
2 from inline_snapshot import snapshot
3
4 from docs_src.behind_a_proxy.tutorial003_py310 import app
5
6 client = TestClient(app)
7
8
9 def test_main():
10 response = client.get("/app")
11 assert response.status_code == 200
12 assert response.json() == {"message": "Hello World", "root_path": "/api/v1"}
13
14
15 def test_openapi_schema():
16 response = client.get("/openapi.json")
17 assert response.status_code == 200
18 assert response.json() == snapshot(
19 {
20 "openapi": "3.1.0",
21 "info": {"title": "FastAPI", "version": "0.1.0"},
22 "servers": [
23 {"url": "/api/v1"},
24 {
25 "url": "https://stag.example.com",
26 "description": "Staging environment",
27 },
28 {
29 "url": "https://prod.example.com",
30 "description": "Production environment",
31 },
32 ],
33 "paths": {
34 "/app": {
35 "get": {
36 "summary": "Read Main",
37 "operationId": "read_main_app_get",
38 "responses": {
39 "200": {
40 "description": "Successful Response",
41 "content": {"application/json": {"schema": {}}},
42 }
43 },
44 }
45 }
46 },
47 }
48 )