mirror of
https://github.com/rjNemo/fastapi
synced 2026-06-06 10:36:39 +00:00
* ♻️ Remove required extra steps to test in editor * 🎨 Format lint script * 📝 Remove obsolete extra steps required to test in editor from docs * 🐛 Fix coverage
24 lines
844 B
Python
24 lines
844 B
Python
import os
|
|
import shutil
|
|
|
|
from fastapi.testclient import TestClient
|
|
|
|
|
|
def test_main():
|
|
if os.path.isdir("./static"): # pragma: nocover
|
|
shutil.rmtree("./static")
|
|
if os.path.isdir("./templates"): # pragma: nocover
|
|
shutil.rmtree("./templates")
|
|
shutil.copytree("./docs_src/templates/templates/", "./templates")
|
|
shutil.copytree("./docs_src/templates/static/", "./static")
|
|
from docs_src.templates.tutorial001 import app
|
|
|
|
client = TestClient(app)
|
|
response = client.get("/items/foo")
|
|
assert response.status_code == 200, response.text
|
|
assert b"<h1>Item ID: foo</h1>" in response.content
|
|
response = client.get("/static/styles.css")
|
|
assert response.status_code == 200, response.text
|
|
assert b"color: green;" in response.content
|
|
shutil.rmtree("./templates")
|
|
shutil.rmtree("./static")
|