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