Coverage for tests/test_tutorial/test_conditional_openapi/test_tutorial001.py: 100%
33 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-12-04 08:29 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2025-12-04 08:29 +0000
1import importlib 1opqrstu
3from fastapi.testclient import TestClient 1opqrstu
5from ...utils import needs_pydanticv2 1opqrstu
8def get_client() -> TestClient: 1opqrstu
9 from docs_src.conditional_openapi import tutorial001 1havibwjcxkdylezmfAngB
11 importlib.reload(tutorial001) 1havibwjcxkdylezmfAngB
13 client = TestClient(tutorial001.app) 1havibwjcxkdylezmfAngB
14 return client 1havibwjcxkdylezmfAngB
17@needs_pydanticv2 1opqrstu
18def test_disable_openapi(monkeypatch): 1opqrstu
19 monkeypatch.setenv("OPENAPI_URL", "") 1abcdefg
20 # Load the client after setting the env var
21 client = get_client() 1abcdefg
22 response = client.get("/openapi.json") 1abcdefg
23 assert response.status_code == 404, response.text 1abcdefg
24 response = client.get("/docs") 1abcdefg
25 assert response.status_code == 404, response.text 1abcdefg
26 response = client.get("/redoc") 1abcdefg
27 assert response.status_code == 404, response.text 1abcdefg
30@needs_pydanticv2 1opqrstu
31def test_root(): 1opqrstu
32 client = get_client() 1vwxyzAB
33 response = client.get("/") 1vwxyzAB
34 assert response.status_code == 200 1vwxyzAB
35 assert response.json() == {"message": "Hello World"} 1vwxyzAB
38@needs_pydanticv2 1opqrstu
39def test_default_openapi(): 1opqrstu
40 client = get_client() 1hijklmn
41 response = client.get("/docs") 1hijklmn
42 assert response.status_code == 200, response.text 1hijklmn
43 response = client.get("/redoc") 1hijklmn
44 assert response.status_code == 200, response.text 1hijklmn
45 response = client.get("/openapi.json") 1hijklmn
46 assert response.json() == { 1hijklmn
47 "openapi": "3.1.0",
48 "info": {"title": "FastAPI", "version": "0.1.0"},
49 "paths": {
50 "/": {
51 "get": {
52 "summary": "Root",
53 "operationId": "root__get",
54 "responses": {
55 "200": {
56 "description": "Successful Response",
57 "content": {"application/json": {"schema": {}}},
58 }
59 },
60 }
61 }
62 },
63 }