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 2024-08-08 03:53 +0000

1import os 1abcde

2from pathlib import Path 1abcde

3 

4import pytest 1abcde

5from fastapi.testclient import TestClient 1abcde

6 

7 

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.tutorial002 import app 1abcde

14 

15 with TestClient(app) as client: 1abcde

16 yield client 1abcde

17 static_dir.rmdir() 1abcde

18 

19 

20def test_swagger_ui_html(client: TestClient): 1abcde

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

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

23 assert "/static/swagger-ui-bundle.js" in response.text 1abcde

24 assert "/static/swagger-ui.css" in response.text 1abcde

25 

26 

27def test_swagger_ui_oauth2_redirect_html(client: TestClient): 1abcde

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

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

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

31 

32 

33def test_redoc_html(client: TestClient): 1abcde

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

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

36 assert "/static/redoc.standalone.js" in response.text 1abcde

37 

38 

39def test_api(client: TestClient): 1abcde

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

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

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