test_response_code_no_body.py — fastapi Source File
Architecture documentation for test_response_code_no_body.py, a python file in the fastapi codebase. 5 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 869096b5_7189_9202_7052_8e630d9bb7b3["test_response_code_no_body.py"] 534f6e44_61b8_3c38_8b89_6934a6df9802["__init__.py"] 869096b5_7189_9202_7052_8e630d9bb7b3 --> 534f6e44_61b8_3c38_8b89_6934a6df9802 967b6712_70e2_f5fa_f671_7c149857a445["responses.py"] 869096b5_7189_9202_7052_8e630d9bb7b3 --> 967b6712_70e2_f5fa_f671_7c149857a445 a7c04dee_ee23_5891_b185_47ff6bed036d["testclient.py"] 869096b5_7189_9202_7052_8e630d9bb7b3 --> a7c04dee_ee23_5891_b185_47ff6bed036d a7f4e7b0_9725_db90_5cbc_7ca8211b323a["inline_snapshot"] 869096b5_7189_9202_7052_8e630d9bb7b3 --> a7f4e7b0_9725_db90_5cbc_7ca8211b323a 6913fbd4_39df_d14b_44bb_522e99b65b90["pydantic"] 869096b5_7189_9202_7052_8e630d9bb7b3 --> 6913fbd4_39df_d14b_44bb_522e99b65b90 style 869096b5_7189_9202_7052_8e630d9bb7b3 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
from fastapi import FastAPI
from fastapi.responses import JSONResponse
from fastapi.testclient import TestClient
from inline_snapshot import snapshot
from pydantic import BaseModel
app = FastAPI()
class JsonApiResponse(JSONResponse):
media_type = "application/vnd.api+json"
class Error(BaseModel):
status: str
title: str
class JsonApiError(BaseModel):
errors: list[Error]
@app.get(
"/a",
status_code=204,
response_class=JsonApiResponse,
responses={500: {"description": "Error", "model": JsonApiError}},
)
async def a():
pass
@app.get("/b", responses={204: {"description": "No Content"}})
async def b():
pass # pragma: no cover
client = TestClient(app)
def test_get_response():
response = client.get("/a")
assert response.status_code == 204, response.text
assert "content-length" not in response.headers
assert response.content == b""
def test_openapi_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == snapshot(
{
"openapi": "3.1.0",
"info": {"title": "FastAPI", "version": "0.1.0"},
"paths": {
"/a": {
"get": {
"responses": {
"500": {
"description": "Error",
"content": {
"application/vnd.api+json": {
"schema": {
"$ref": "#/components/schemas/JsonApiError"
}
}
},
},
"204": {"description": "Successful Response"},
},
"summary": "A",
"operationId": "a_a_get",
}
},
"/b": {
"get": {
"responses": {
"204": {"description": "No Content"},
"200": {
"description": "Successful Response",
"content": {"application/json": {"schema": {}}},
},
},
"summary": "B",
"operationId": "b_b_get",
}
},
},
"components": {
"schemas": {
"Error": {
"title": "Error",
"required": ["status", "title"],
"type": "object",
"properties": {
"status": {"title": "Status", "type": "string"},
"title": {"title": "Title", "type": "string"},
},
},
"JsonApiError": {
"title": "JsonApiError",
"required": ["errors"],
"type": "object",
"properties": {
"errors": {
"title": "Errors",
"type": "array",
"items": {"$ref": "#/components/schemas/Error"},
}
},
},
}
},
}
)
Domain
Subdomains
Classes
Dependencies
- __init__.py
- inline_snapshot
- pydantic
- responses.py
- testclient.py
Source
Frequently Asked Questions
What does test_response_code_no_body.py do?
test_response_code_no_body.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_response_code_no_body.py?
test_response_code_no_body.py defines 4 function(s): a, b, test_get_response, test_openapi_schema.
What does test_response_code_no_body.py depend on?
test_response_code_no_body.py imports 5 module(s): __init__.py, inline_snapshot, pydantic, responses.py, testclient.py.
Where is test_response_code_no_body.py in the architecture?
test_response_code_no_body.py is located at tests/test_response_code_no_body.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