test_union_forms.py — fastapi Source File
Architecture documentation for test_union_forms.py, a python file in the fastapi codebase. 5 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 011d8797_cc26_2e3a_cf84_44b49ef9936b["test_union_forms.py"] 0dda2280_3359_8460_301c_e98c77e78185["typing"] 011d8797_cc26_2e3a_cf84_44b49ef9936b --> 0dda2280_3359_8460_301c_e98c77e78185 534f6e44_61b8_3c38_8b89_6934a6df9802["__init__.py"] 011d8797_cc26_2e3a_cf84_44b49ef9936b --> 534f6e44_61b8_3c38_8b89_6934a6df9802 a7c04dee_ee23_5891_b185_47ff6bed036d["testclient.py"] 011d8797_cc26_2e3a_cf84_44b49ef9936b --> a7c04dee_ee23_5891_b185_47ff6bed036d a7f4e7b0_9725_db90_5cbc_7ca8211b323a["inline_snapshot"] 011d8797_cc26_2e3a_cf84_44b49ef9936b --> a7f4e7b0_9725_db90_5cbc_7ca8211b323a 6913fbd4_39df_d14b_44bb_522e99b65b90["pydantic"] 011d8797_cc26_2e3a_cf84_44b49ef9936b --> 6913fbd4_39df_d14b_44bb_522e99b65b90 style 011d8797_cc26_2e3a_cf84_44b49ef9936b fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
from typing import Annotated, Union
from fastapi import FastAPI, Form
from fastapi.testclient import TestClient
from inline_snapshot import snapshot
from pydantic import BaseModel
app = FastAPI()
class UserForm(BaseModel):
name: str
email: str
class CompanyForm(BaseModel):
company_name: str
industry: str
@app.post("/form-union/")
def post_union_form(data: Annotated[Union[UserForm, CompanyForm], Form()]):
return {"received": data}
client = TestClient(app)
def test_post_user_form():
response = client.post(
"/form-union/", data={"name": "John Doe", "email": "john@example.com"}
)
assert response.status_code == 200, response.text
assert response.json() == {
"received": {"name": "John Doe", "email": "john@example.com"}
}
def test_post_company_form():
response = client.post(
"/form-union/", data={"company_name": "Tech Corp", "industry": "Technology"}
)
assert response.status_code == 200, response.text
assert response.json() == {
"received": {"company_name": "Tech Corp", "industry": "Technology"}
}
def test_invalid_form_data():
response = client.post(
"/form-union/",
data={"name": "John", "company_name": "Tech Corp"},
)
assert response.status_code == 422, response.text
def test_empty_form():
response = client.post("/form-union/")
assert response.status_code == 422, response.text
// ... (104 more lines)
Domain
Subdomains
Functions
Classes
Dependencies
- __init__.py
- inline_snapshot
- pydantic
- testclient.py
- typing
Source
Frequently Asked Questions
What does test_union_forms.py do?
test_union_forms.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_forms.py?
test_union_forms.py defines 6 function(s): post_union_form, test_empty_form, test_invalid_form_data, test_openapi_schema, test_post_company_form, test_post_user_form.
What does test_union_forms.py depend on?
test_union_forms.py imports 5 module(s): __init__.py, inline_snapshot, pydantic, testclient.py, typing.
Where is test_union_forms.py in the architecture?
test_union_forms.py is located at tests/test_union_forms.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