Coverage for tests / test_tutorial / test_custom_docs_ui / test_tutorial001.py: 100%

30 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-02-12 18:15 +0000

1import os 1abdc

2from pathlib import Path 1abdc

3 

4import pytest 1abdc

5from fastapi.testclient import TestClient 1abdc

6 

7 

8@pytest.fixture(scope="module") 1abdc

9def client(): 1abdc

10 static_dir: Path = Path(os.getcwd()) / "static" 1abc

11 print(static_dir) 1abc

12 static_dir.mkdir(exist_ok=True) 1abc

13 from docs_src.custom_docs_ui.tutorial001_py310 import app 1abc

14 

15 with TestClient(app) as client: 1abc

16 yield client 1abc

17 static_dir.rmdir() 1abc

18 

19 

20def test_swagger_ui_html(client: TestClient): 1abdc

21 response = client.get("/docs") 1efg

22 assert response.status_code == 200, response.text 1efg

23 assert "https://unpkg.com/swagger-ui-dist@5/swagger-ui-bundle.js" in response.text 1efg

24 assert "https://unpkg.com/swagger-ui-dist@5/swagger-ui.css" in response.text 1efg

25 

26 

27def test_swagger_ui_oauth2_redirect_html(client: TestClient): 1abdc

28 response = client.get("/docs/oauth2-redirect") 1hij

29 assert response.status_code == 200, response.text 1hij

30 assert "window.opener.swaggerUIRedirectOauth2" in response.text 1hij

31 

32 

33def test_redoc_html(client: TestClient): 1abdc

34 response = client.get("/redoc") 1klm

35 assert response.status_code == 200, response.text 1klm

36 assert "https://unpkg.com/redoc@2/bundles/redoc.standalone.js" in response.text 1klm

37 

38 

39def test_api(client: TestClient): 1abdc

40 response = client.get("/users/john") 1nop

41 assert response.status_code == 200, response.text 1nop

42 assert response.json()["message"] == "Hello john" 1nop