test_main.py — fastapi Source File
Architecture documentation for test_main.py, a python file in the fastapi codebase. 2 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 2f4620c4_6a2a_b4c4_1a8a_e4595526d698["test_main.py"] b3808b19_7a5a_7f61_7114_41a3431e487c["main.py"] 2f4620c4_6a2a_b4c4_1a8a_e4595526d698 --> b3808b19_7a5a_7f61_7114_41a3431e487c a7c04dee_ee23_5891_b185_47ff6bed036d["testclient.py"] 2f4620c4_6a2a_b4c4_1a8a_e4595526d698 --> a7c04dee_ee23_5891_b185_47ff6bed036d style 2f4620c4_6a2a_b4c4_1a8a_e4595526d698 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
from fastapi.testclient import TestClient
from .main import app
client = TestClient(app)
def test_read_item():
response = client.get("/items/foo", headers={"X-Token": "coneofsilence"})
assert response.status_code == 200
assert response.json() == {
"id": "foo",
"title": "Foo",
"description": "There goes my hero",
}
def test_read_item_bad_token():
response = client.get("/items/foo", headers={"X-Token": "hailhydra"})
assert response.status_code == 400
assert response.json() == {"detail": "Invalid X-Token header"}
def test_read_nonexistent_item():
response = client.get("/items/baz", headers={"X-Token": "coneofsilence"})
assert response.status_code == 404
assert response.json() == {"detail": "Item not found"}
def test_create_item():
response = client.post(
"/items/",
headers={"X-Token": "coneofsilence"},
json={"id": "foobar", "title": "Foo Bar", "description": "The Foo Barters"},
)
assert response.status_code == 200
assert response.json() == {
"id": "foobar",
"title": "Foo Bar",
"description": "The Foo Barters",
}
def test_create_item_bad_token():
response = client.post(
"/items/",
headers={"X-Token": "hailhydra"},
json={"id": "bazz", "title": "Bazz", "description": "Drop the bazz"},
)
assert response.status_code == 400
assert response.json() == {"detail": "Invalid X-Token header"}
def test_create_existing_item():
response = client.post(
"/items/",
headers={"X-Token": "coneofsilence"},
json={
"id": "foo",
"title": "The Foo ID Stealers",
"description": "There goes my stealer",
},
)
assert response.status_code == 409
assert response.json() == {"detail": "Item already exists"}
Domain
Subdomains
Functions
Dependencies
Source
Frequently Asked Questions
What does test_main.py do?
test_main.py is a source file in the fastapi codebase, written in python. It belongs to the FastAPI domain, Applications subdomain.
What functions are defined in test_main.py?
test_main.py defines 6 function(s): test_create_existing_item, test_create_item, test_create_item_bad_token, test_read_item, test_read_item_bad_token, test_read_nonexistent_item.
What does test_main.py depend on?
test_main.py imports 2 module(s): main.py, testclient.py.
Where is test_main.py in the architecture?
test_main.py is located at docs_src/app_testing/app_b_an_py39/test_main.py (domain: FastAPI, subdomain: Applications, directory: docs_src/app_testing/app_b_an_py39).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free