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