Debian Codegraph @

tests/test_tutorial/test_templates/test_tutorial001.py

raw
1 import os
2 import shutil
3
4 from fastapi.testclient import TestClient
5
6 from tests.utils import workdir_lock
7
8
9 @workdir_lock
10 def test_main():
11 if os.path.isdir("./static"): # pragma: nocover
12 shutil.rmtree("./static")
13 if os.path.isdir("./templates"): # pragma: nocover
14 shutil.rmtree("./templates")
15 shutil.copytree("./docs_src/templates/templates/", "./templates")
16 shutil.copytree("./docs_src/templates/static/", "./static")
17 from docs_src.templates.tutorial001_py310 import app
18
19 client = TestClient(app)
20 response = client.get("/items/foo")
21 assert response.status_code == 200, response.text
22 assert (
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")
27 assert response.status_code == 200, response.text
28 assert b"color: green;" in response.content
29 shutil.rmtree("./templates")
30 shutil.rmtree("./static")