Coverage for tests / test_tutorial / test_conditional_openapi / test_tutorial001.py: 100%
30 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
1import importlib 1jklm
3from fastapi.testclient import TestClient 1jklm
4from inline_snapshot import snapshot 1jklm
7def get_client() -> TestClient: 1jklm
8 from docs_src.conditional_openapi import tutorial001_py310 1dagebhfci
10 importlib.reload(tutorial001_py310) 1dagebhfci
12 client = TestClient(tutorial001_py310.app) 1dagebhfci
13 return client 1dagebhfci
16def test_disable_openapi(monkeypatch): 1jklm
17 monkeypatch.setenv("OPENAPI_URL", "") 1abc
18 # Load the client after setting the env var
19 client = get_client() 1abc
20 response = client.get("/openapi.json") 1abc
21 assert response.status_code == 404, response.text 1abc
22 response = client.get("/docs") 1abc
23 assert response.status_code == 404, response.text 1abc
24 response = client.get("/redoc") 1abc
25 assert response.status_code == 404, response.text 1abc
28def test_root(): 1jklm
29 client = get_client() 1ghi
30 response = client.get("/") 1ghi
31 assert response.status_code == 200 1ghi
32 assert response.json() == {"message": "Hello World"} 1ghi
35def test_default_openapi(): 1jklm
36 client = get_client() 1def
37 response = client.get("/docs") 1def
38 assert response.status_code == 200, response.text 1def
39 response = client.get("/redoc") 1def
40 assert response.status_code == 200, response.text 1def
41 response = client.get("/openapi.json") 1def
42 assert response.json() == snapshot( 1def
43 {
44 "openapi": "3.1.0",
45 "info": {"title": "FastAPI", "version": "0.1.0"},
46 "paths": {
47 "/": {
48 "get": {
49 "summary": "Root",
50 "operationId": "root__get",
51 "responses": {
52 "200": {
53 "description": "Successful Response",
54 "content": {"application/json": {"schema": {}}},
55 }
56 },
57 }
58 }
59 },
60 }
61 )