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