test_union_body.py — fastapi Source File
Architecture documentation for test_union_body.py, a python file in the fastapi codebase. 5 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 5bdcd235_beb0_edf1_0e51_f0ed90902764["test_union_body.py"] 0dda2280_3359_8460_301c_e98c77e78185["typing"] 5bdcd235_beb0_edf1_0e51_f0ed90902764 --> 0dda2280_3359_8460_301c_e98c77e78185 534f6e44_61b8_3c38_8b89_6934a6df9802["__init__.py"] 5bdcd235_beb0_edf1_0e51_f0ed90902764 --> 534f6e44_61b8_3c38_8b89_6934a6df9802 a7c04dee_ee23_5891_b185_47ff6bed036d["testclient.py"] 5bdcd235_beb0_edf1_0e51_f0ed90902764 --> a7c04dee_ee23_5891_b185_47ff6bed036d a7f4e7b0_9725_db90_5cbc_7ca8211b323a["inline_snapshot"] 5bdcd235_beb0_edf1_0e51_f0ed90902764 --> a7f4e7b0_9725_db90_5cbc_7ca8211b323a 6913fbd4_39df_d14b_44bb_522e99b65b90["pydantic"] 5bdcd235_beb0_edf1_0e51_f0ed90902764 --> 6913fbd4_39df_d14b_44bb_522e99b65b90 style 5bdcd235_beb0_edf1_0e51_f0ed90902764 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
from typing import Optional, Union
from fastapi import FastAPI
from fastapi.testclient import TestClient
from inline_snapshot import snapshot
from pydantic import BaseModel
app = FastAPI()
class Item(BaseModel):
name: Optional[str] = None
class OtherItem(BaseModel):
price: int
@app.post("/items/")
def save_union_body(item: Union[OtherItem, Item]):
return {"item": item}
client = TestClient(app)
def test_post_other_item():
response = client.post("/items/", json={"price": 100})
assert response.status_code == 200, response.text
assert response.json() == {"item": {"price": 100}}
def test_post_item():
response = client.post("/items/", json={"name": "Foo"})
assert response.status_code == 200, response.text
assert response.json() == {"item": {"name": "Foo"}}
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": {
"/items/": {
"post": {
"responses": {
"200": {
"description": "Successful Response",
"content": {"application/json": {"schema": {}}},
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
// ... (77 more lines)
Domain
Subdomains
Dependencies
- __init__.py
- inline_snapshot
- pydantic
- testclient.py
- typing
Source
Frequently Asked Questions
What does test_union_body.py do?
test_union_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_union_body.py?
test_union_body.py defines 4 function(s): save_union_body, test_openapi_schema, test_post_item, test_post_other_item.
What does test_union_body.py depend on?
test_union_body.py imports 5 module(s): __init__.py, inline_snapshot, pydantic, testclient.py, typing.
Where is test_union_body.py in the architecture?
test_union_body.py is located at tests/test_union_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