test_crud_app() — fastapi Function Reference
Architecture documentation for the test_crud_app() function in test_tutorial002.py from the fastapi codebase.
Entity Profile
Dependency Diagram
graph TD 73c7c2b6_1aa6_2018_0151_e41419f5fa06["test_crud_app()"] 24c45a29_accd_8258_a7da_ddf6ea0170f4["test_tutorial002.py"] 73c7c2b6_1aa6_2018_0151_e41419f5fa06 -->|defined in| 24c45a29_accd_8258_a7da_ddf6ea0170f4 style 73c7c2b6_1aa6_2018_0151_e41419f5fa06 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
tests/test_tutorial/test_sql_databases/test_tutorial002.py lines 50–147
def test_crud_app(client: TestClient):
# TODO: this warns that SQLModel.from_orm is deprecated in Pydantic v1, refactor
# this if using obj.model_validate becomes independent of Pydantic v2
with warnings.catch_warnings(record=True):
warnings.simplefilter("always")
# No heroes before creating
response = client.get("heroes/")
assert response.status_code == 200, response.text
assert response.json() == []
# Create a hero
response = client.post(
"/heroes/",
json={
"id": 9000,
"name": "Dead Pond",
"age": 30,
"secret_name": "Dive Wilson",
},
)
assert response.status_code == 200, response.text
assert response.json() == snapshot(
{"age": 30, "id": IsInt(), "name": "Dead Pond"}
)
assert response.json()["id"] != 9000, (
"The ID should be generated by the database"
)
# Read a hero
hero_id = response.json()["id"]
response = client.get(f"/heroes/{hero_id}")
assert response.status_code == 200, response.text
assert response.json() == snapshot(
{"name": "Dead Pond", "age": 30, "id": IsInt()}
)
# Read all heroes
# Create more heroes first
response = client.post(
"/heroes/",
json={"name": "Spider-Boy", "age": 18, "secret_name": "Pedro Parqueador"},
)
assert response.status_code == 200, response.text
response = client.post(
"/heroes/", json={"name": "Rusty-Man", "secret_name": "Tommy Sharp"}
)
assert response.status_code == 200, response.text
response = client.get("/heroes/")
assert response.status_code == 200, response.text
assert response.json() == snapshot(
[
{"name": "Dead Pond", "age": 30, "id": IsInt()},
{"name": "Spider-Boy", "age": 18, "id": IsInt()},
{"name": "Rusty-Man", "age": None, "id": IsInt()},
]
)
response = client.get("/heroes/?offset=1&limit=1")
assert response.status_code == 200, response.text
assert response.json() == snapshot(
[{"name": "Spider-Boy", "age": 18, "id": IsInt()}]
)
# Update a hero
response = client.patch(
f"/heroes/{hero_id}", json={"name": "Dog Pond", "age": None}
)
assert response.status_code == 200, response.text
assert response.json() == snapshot(
{"name": "Dog Pond", "age": None, "id": Is(hero_id)}
)
# Get updated hero
response = client.get(f"/heroes/{hero_id}")
assert response.status_code == 200, response.text
assert response.json() == snapshot(
{"name": "Dog Pond", "age": None, "id": Is(hero_id)}
)
# Delete a hero
Domain
Subdomains
Source
Frequently Asked Questions
What does test_crud_app() do?
test_crud_app() is a function in the fastapi codebase, defined in tests/test_tutorial/test_sql_databases/test_tutorial002.py.
Where is test_crud_app() defined?
test_crud_app() is defined in tests/test_tutorial/test_sql_databases/test_tutorial002.py at line 50.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free