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

16 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-12-04 08:29 +0000

1import os 1abcdefg

2import shutil 1abcdefg

3 

4from fastapi.testclient import TestClient 1abcdefg

5 

6 

7def test_main(): 1abcdefg

8 if os.path.isdir("./static"): # pragma: nocover 1hijklmn

9 shutil.rmtree("./static") 

10 if os.path.isdir("./templates"): # pragma: nocover 1hijklmn

11 shutil.rmtree("./templates") 

12 shutil.copytree("./docs_src/templates/templates/", "./templates") 1hijklmn

13 shutil.copytree("./docs_src/templates/static/", "./static") 1hijklmn

14 from docs_src.templates.tutorial001 import app 1hijklmn

15 

16 client = TestClient(app) 1hijklmn

17 response = client.get("/items/foo") 1hijklmn

18 assert response.status_code == 200, response.text 1abcdefg

19 assert ( 1abcdefg

20 b'<h1><a href="http://testserver/items/foo">Item ID: foo</a></h1>' 

21 in response.content 

22 ) 

23 response = client.get("/static/styles.css") 1abcdefg

24 assert response.status_code == 200, response.text 1abcdefg

25 assert b"color: green;" in response.content 1abcdefg

26 shutil.rmtree("./templates") 1abcdefg

27 shutil.rmtree("./static") 1abcdefg