Coverage for tests/test_tutorial/test_conditional_openapi/test_tutorial001.py: 100%
33 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
1import importlib 1abcde
3from fastapi.testclient import TestClient 1abcde
5from ...utils import needs_pydanticv2 1abcde
8def get_client() -> TestClient: 1abcde
9 from docs_src.conditional_openapi import tutorial001 1abcde
11 importlib.reload(tutorial001) 1abcde
13 client = TestClient(tutorial001.app) 1abcde
14 return client 1abcde
17@needs_pydanticv2 1abcde
18def test_disable_openapi(monkeypatch): 1abcde
19 monkeypatch.setenv("OPENAPI_URL", "") 1abcde
20 # Load the client after setting the env var
21 client = get_client() 1abcde
22 response = client.get("/openapi.json") 1abcde
23 assert response.status_code == 404, response.text 1abcde
24 response = client.get("/docs") 1abcde
25 assert response.status_code == 404, response.text 1abcde
26 response = client.get("/redoc") 1abcde
27 assert response.status_code == 404, response.text 1abcde
30@needs_pydanticv2 1abcde
31def test_root(): 1abcde
32 client = get_client() 1abcde
33 response = client.get("/") 1abcde
34 assert response.status_code == 200 1abcde
35 assert response.json() == {"message": "Hello World"} 1abcde
38@needs_pydanticv2 1abcde
39def test_default_openapi(): 1abcde
40 client = get_client() 1abcde
41 response = client.get("/docs") 1abcde
42 assert response.status_code == 200, response.text 1abcde
43 response = client.get("/redoc") 1abcde
44 assert response.status_code == 200, response.text 1abcde
45 response = client.get("/openapi.json") 1abcde
46 assert response.json() == { 1abcde
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 }