test_starlette_exception.py — fastapi Source File
Architecture documentation for test_starlette_exception.py, a python file in the fastapi codebase. 4 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 0fe3f8ea_3be3_8a13_6ed5_140ccdf0b591["test_starlette_exception.py"] 534f6e44_61b8_3c38_8b89_6934a6df9802["__init__.py"] 0fe3f8ea_3be3_8a13_6ed5_140ccdf0b591 --> 534f6e44_61b8_3c38_8b89_6934a6df9802 a7c04dee_ee23_5891_b185_47ff6bed036d["testclient.py"] 0fe3f8ea_3be3_8a13_6ed5_140ccdf0b591 --> a7c04dee_ee23_5891_b185_47ff6bed036d a7f4e7b0_9725_db90_5cbc_7ca8211b323a["inline_snapshot"] 0fe3f8ea_3be3_8a13_6ed5_140ccdf0b591 --> a7f4e7b0_9725_db90_5cbc_7ca8211b323a 72a586ac_ceef_ac9f_17ec_0ed0d645b635["starlette.exceptions"] 0fe3f8ea_3be3_8a13_6ed5_140ccdf0b591 --> 72a586ac_ceef_ac9f_17ec_0ed0d645b635 style 0fe3f8ea_3be3_8a13_6ed5_140ccdf0b591 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
from fastapi import FastAPI, HTTPException
from fastapi.testclient import TestClient
from inline_snapshot import snapshot
from starlette.exceptions import HTTPException as StarletteHTTPException
app = FastAPI()
items = {"foo": "The Foo Wrestlers"}
@app.get("/items/{item_id}")
async def read_item(item_id: str):
if item_id not in items:
raise HTTPException(
status_code=404,
detail="Item not found",
headers={"X-Error": "Some custom header"},
)
return {"item": items[item_id]}
@app.get("/http-no-body-statuscode-exception")
async def no_body_status_code_exception():
raise HTTPException(status_code=204)
@app.get("/http-no-body-statuscode-with-detail-exception")
async def no_body_status_code_with_detail_exception():
raise HTTPException(status_code=204, detail="I should just disappear!")
@app.get("/starlette-items/{item_id}")
async def read_starlette_item(item_id: str):
if item_id not in items:
raise StarletteHTTPException(status_code=404, detail="Item not found")
return {"item": items[item_id]}
client = TestClient(app)
def test_get_item():
response = client.get("/items/foo")
assert response.status_code == 200, response.text
assert response.json() == {"item": "The Foo Wrestlers"}
def test_get_item_not_found():
response = client.get("/items/bar")
assert response.status_code == 404, response.text
assert response.headers.get("x-error") == "Some custom header"
assert response.json() == {"detail": "Item not found"}
def test_get_starlette_item():
response = client.get("/starlette-items/foo")
assert response.status_code == 200, response.text
assert response.json() == {"item": "The Foo Wrestlers"}
// ... (150 more lines)
Domain
Subdomains
Functions
- no_body_status_code_exception()
- no_body_status_code_with_detail_exception()
- read_item()
- read_starlette_item()
- test_get_item()
- test_get_item_not_found()
- test_get_starlette_item()
- test_get_starlette_item_not_found()
- test_no_body_status_code_exception_handlers()
- test_no_body_status_code_with_detail_exception_handlers()
- test_openapi_schema()
Dependencies
- __init__.py
- inline_snapshot
- starlette.exceptions
- testclient.py
Source
Frequently Asked Questions
What does test_starlette_exception.py do?
test_starlette_exception.py is a source file in the fastapi codebase, written in python. It belongs to the FastAPI domain, Routing subdomain.
What functions are defined in test_starlette_exception.py?
test_starlette_exception.py defines 11 function(s): no_body_status_code_exception, no_body_status_code_with_detail_exception, read_item, read_starlette_item, test_get_item, test_get_item_not_found, test_get_starlette_item, test_get_starlette_item_not_found, test_no_body_status_code_exception_handlers, test_no_body_status_code_with_detail_exception_handlers, and 1 more.
What does test_starlette_exception.py depend on?
test_starlette_exception.py imports 4 module(s): __init__.py, inline_snapshot, starlette.exceptions, testclient.py.
Where is test_starlette_exception.py in the architecture?
test_starlette_exception.py is located at tests/test_starlette_exception.py (domain: FastAPI, subdomain: Routing, directory: tests).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free