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-12-04 08:29 +0000

1import os 1abcdefg

2from pathlib import Path 1abcdefg

3 

4import pytest 1abcdefg

5from fastapi.testclient import TestClient 1abcdefg

6 

7 

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

9def client(): 1abcdefg

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

11 print(static_dir) 1abcdefg

12 static_dir.mkdir(exist_ok=True) 1abcdefg

13 from docs_src.custom_docs_ui.tutorial001 import app 1abcdefg

14 

15 with TestClient(app) as client: 1abcdefg

16 yield client 1abcdefg

17 static_dir.rmdir() 1abcdefg

18 

19 

20def test_swagger_ui_html(client: TestClient): 1abcdefg

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

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

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

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

25 

26 

27def test_swagger_ui_oauth2_redirect_html(client: TestClient): 1abcdefg

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

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

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

31 

32 

33def test_redoc_html(client: TestClient): 1abcdefg

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

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

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

37 

38 

39def test_api(client: TestClient): 1abcdefg

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

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

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