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

35 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-04-06 01:24 +0000

1import os 1abcd

2from pathlib import Path 1abcd

3 

4import pytest 1abcd

5from fastapi.testclient import TestClient 1abcd

6 

7from tests.utils import workdir_lock 1abcd

8 

9 

10@pytest.fixture(scope="module") 1abcd

11def client(): 1abcd

12 static_dir: Path = Path(os.getcwd()) / "static" 1efgh

13 print(static_dir) 1efgh

14 static_dir.mkdir(exist_ok=True) 1efgh

15 from docs_src.custom_docs_ui.tutorial001_py310 import app 1efgh

16 

17 with TestClient(app) as client: 1yezfAgBh

18 yield client 1efgh

19 static_dir.rmdir() 1yzAB

20 

21 

22@workdir_lock 1abcd

23def test_swagger_ui_html(client: TestClient): 1abcd

24 response = client.get("/docs") 1ijkl

25 assert response.status_code == 200, response.text 1ijkl

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

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

28 

29 

30@workdir_lock 1abcd

31def test_swagger_ui_oauth2_redirect_html(client: TestClient): 1abcd

32 response = client.get("/docs/oauth2-redirect") 1mnop

33 assert response.status_code == 200, response.text 1mnop

34 assert "window.opener.swaggerUIRedirectOauth2" in response.text 1mnop

35 

36 

37@workdir_lock 1abcd

38def test_redoc_html(client: TestClient): 1abcd

39 response = client.get("/redoc") 1qrst

40 assert response.status_code == 200, response.text 1qrst

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

42 

43 

44@workdir_lock 1abcd

45def test_api(client: TestClient): 1abcd

46 response = client.get("/users/john") 1uvwx

47 assert response.status_code == 200, response.text 1uvwx

48 assert response.json()["message"] == "Hello john" 1uvwx