test_computed_fields.py — fastapi Source File
Architecture documentation for test_computed_fields.py, a python file in the fastapi codebase. 5 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 8a5bb1d8_4ff0_e192_0afd_1c1690b8792d["test_computed_fields.py"] 5befe8bf_65d1_d058_6b78_4a597a8488e9["pytest"] 8a5bb1d8_4ff0_e192_0afd_1c1690b8792d --> 5befe8bf_65d1_d058_6b78_4a597a8488e9 534f6e44_61b8_3c38_8b89_6934a6df9802["__init__.py"] 8a5bb1d8_4ff0_e192_0afd_1c1690b8792d --> 534f6e44_61b8_3c38_8b89_6934a6df9802 a7c04dee_ee23_5891_b185_47ff6bed036d["testclient.py"] 8a5bb1d8_4ff0_e192_0afd_1c1690b8792d --> a7c04dee_ee23_5891_b185_47ff6bed036d a7f4e7b0_9725_db90_5cbc_7ca8211b323a["inline_snapshot"] 8a5bb1d8_4ff0_e192_0afd_1c1690b8792d --> a7f4e7b0_9725_db90_5cbc_7ca8211b323a 6913fbd4_39df_d14b_44bb_522e99b65b90["pydantic"] 8a5bb1d8_4ff0_e192_0afd_1c1690b8792d --> 6913fbd4_39df_d14b_44bb_522e99b65b90 style 8a5bb1d8_4ff0_e192_0afd_1c1690b8792d fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import pytest
from fastapi import FastAPI
from fastapi.testclient import TestClient
from inline_snapshot import snapshot
@pytest.fixture(name="client")
def get_client(request):
separate_input_output_schemas = request.param
app = FastAPI(separate_input_output_schemas=separate_input_output_schemas)
from pydantic import BaseModel, computed_field
class Rectangle(BaseModel):
width: int
length: int
@computed_field
@property
def area(self) -> int:
return self.width * self.length
@app.get("/")
def read_root() -> Rectangle:
return Rectangle(width=3, length=4)
@app.get("/responses", responses={200: {"model": Rectangle}})
def read_responses() -> Rectangle:
return Rectangle(width=3, length=4)
client = TestClient(app)
return client
@pytest.mark.parametrize("client", [True, False], indirect=True)
@pytest.mark.parametrize("path", ["/", "/responses"])
def test_get(client: TestClient, path: str):
response = client.get(path)
assert response.status_code == 200, response.text
assert response.json() == {"width": 3, "length": 4, "area": 12}
@pytest.mark.parametrize("client", [True, False], indirect=True)
def test_openapi_schema(client: TestClient):
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": {
"/": {
"get": {
"summary": "Read Root",
"operationId": "read_root__get",
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Rectangle"
}
}
},
}
},
}
},
"/responses": {
"get": {
"summary": "Read Responses",
"operationId": "read_responses_responses_get",
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Rectangle"
}
}
},
}
},
}
},
},
"components": {
"schemas": {
"Rectangle": {
"properties": {
"width": {"type": "integer", "title": "Width"},
"length": {"type": "integer", "title": "Length"},
"area": {
"type": "integer",
"title": "Area",
"readOnly": True,
},
},
"type": "object",
"required": ["width", "length", "area"],
"title": "Rectangle",
}
}
},
}
)
Domain
Subdomains
Classes
Dependencies
- __init__.py
- inline_snapshot
- pydantic
- pytest
- testclient.py
Source
Frequently Asked Questions
What does test_computed_fields.py do?
test_computed_fields.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_computed_fields.py?
test_computed_fields.py defines 3 function(s): get_client, test_get, test_openapi_schema.
What does test_computed_fields.py depend on?
test_computed_fields.py imports 5 module(s): __init__.py, inline_snapshot, pydantic, pytest, testclient.py.
Where is test_computed_fields.py in the architecture?
test_computed_fields.py is located at tests/test_computed_fields.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