Coverage for tests / test_tutorial / test_templates / test_tutorial001.py: 100%
16 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
1import os 1abgc
2import shutil 1abgc
4from fastapi.testclient import TestClient 1abgc
7def test_main(): 1abgc
8 if os.path.isdir("./static"): # pragma: nocover 1def
9 shutil.rmtree("./static")
10 if os.path.isdir("./templates"): # pragma: nocover 1def
11 shutil.rmtree("./templates")
12 shutil.copytree("./docs_src/templates/templates/", "./templates") 1def
13 shutil.copytree("./docs_src/templates/static/", "./static") 1def
14 from docs_src.templates.tutorial001_py310 import app 1def
16 client = TestClient(app) 1def
17 response = client.get("/items/foo") 1def
18 assert response.status_code == 200, response.text 1abc
19 assert ( 1ab
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") 1abc
24 assert response.status_code == 200, response.text 1abc
25 assert b"color: green;" in response.content 1abc
26 shutil.rmtree("./templates") 1abc
27 shutil.rmtree("./static") 1abc