Coverage for tests/test_tutorial/test_custom_docs_ui/test_tutorial002.py: 100%
30 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-05-05 00:03 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2025-05-05 00:03 +0000
1import os 1abcdef
2from pathlib import Path 1abcdef
4import pytest 1abcdef
5from fastapi.testclient import TestClient 1abcdef
8@pytest.fixture(scope="module") 1abcdef
9def client(): 1abcdef
10 static_dir: Path = Path(os.getcwd()) / "static" 1abcdef
11 print(static_dir) 1abcdef
12 static_dir.mkdir(exist_ok=True) 1abcdef
13 from docs_src.custom_docs_ui.tutorial002 import app 1abcdef
15 with TestClient(app) as client: 1abcdef
16 yield client 1abcdef
17 static_dir.rmdir() 1abcdef
20def test_swagger_ui_html(client: TestClient): 1abcdef
21 response = client.get("/docs") 1ghijkl
22 assert response.status_code == 200, response.text 1ghijkl
23 assert "/static/swagger-ui-bundle.js" in response.text 1ghijkl
24 assert "/static/swagger-ui.css" in response.text 1ghijkl
27def test_swagger_ui_oauth2_redirect_html(client: TestClient): 1abcdef
28 response = client.get("/docs/oauth2-redirect") 1mnopqr
29 assert response.status_code == 200, response.text 1mnopqr
30 assert "window.opener.swaggerUIRedirectOauth2" in response.text 1mnopqr
33def test_redoc_html(client: TestClient): 1abcdef
34 response = client.get("/redoc") 1stuvwx
35 assert response.status_code == 200, response.text 1stuvwx
36 assert "/static/redoc.standalone.js" in response.text 1stuvwx
39def test_api(client: TestClient): 1abcdef
40 response = client.get("/users/john") 1yzABCD
41 assert response.status_code == 200, response.text 1yzABCD
42 assert response.json()["message"] == "Hello john" 1yzABCD