Coverage for tests / test_tutorial / test_templates / test_tutorial001.py: 100%
18 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-04-06 01:24 +0000
« prev ^ index » next coverage.py v7.13.3, created at 2026-04-06 01:24 +0000
1import os 1efgh
2import shutil 1efgh
4from fastapi.testclient import TestClient 1efgh
6from tests.utils import workdir_lock 1efgh
9@workdir_lock 1efgh
10def test_main(): 1efgh
11 if os.path.isdir("./static"): # pragma: nocover 1abcd
12 shutil.rmtree("./static")
13 if os.path.isdir("./templates"): # pragma: nocover 1abcd
14 shutil.rmtree("./templates")
15 shutil.copytree("./docs_src/templates/templates/", "./templates") 1abcd
16 shutil.copytree("./docs_src/templates/static/", "./static") 1abcd
17 from docs_src.templates.tutorial001_py310 import app 1abcd
19 client = TestClient(app) 1abcd
20 response = client.get("/items/foo") 1abcd
21 assert response.status_code == 200, response.text 1abcd
22 assert ( 1abc
23 b'<h1><a href="http://testserver/items/foo">Item ID: foo</a></h1>'
24 in response.content
25 )
26 response = client.get("/static/styles.css") 1abcd
27 assert response.status_code == 200, response.text 1abcd
28 assert b"color: green;" in response.content 1abcd
29 shutil.rmtree("./templates") 1abcd
30 shutil.rmtree("./static") 1abcd