Home / File/ test_forms_single_model.py — fastapi Source File

test_forms_single_model.py — fastapi Source File

Architecture documentation for test_forms_single_model.py, a python file in the fastapi codebase. 4 imports, 0 dependents.

File python FastAPI Applications 4 imports 8 functions 2 classes

Entity Profile

Dependency Diagram

graph LR
  9040b4f3_c3f5_c14a_b0ec_0bf00390d9d7["test_forms_single_model.py"]
  0dda2280_3359_8460_301c_e98c77e78185["typing"]
  9040b4f3_c3f5_c14a_b0ec_0bf00390d9d7 --> 0dda2280_3359_8460_301c_e98c77e78185
  534f6e44_61b8_3c38_8b89_6934a6df9802["__init__.py"]
  9040b4f3_c3f5_c14a_b0ec_0bf00390d9d7 --> 534f6e44_61b8_3c38_8b89_6934a6df9802
  a7c04dee_ee23_5891_b185_47ff6bed036d["testclient.py"]
  9040b4f3_c3f5_c14a_b0ec_0bf00390d9d7 --> a7c04dee_ee23_5891_b185_47ff6bed036d
  6913fbd4_39df_d14b_44bb_522e99b65b90["pydantic"]
  9040b4f3_c3f5_c14a_b0ec_0bf00390d9d7 --> 6913fbd4_39df_d14b_44bb_522e99b65b90
  style 9040b4f3_c3f5_c14a_b0ec_0bf00390d9d7 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from typing import Annotated, Optional

from fastapi import FastAPI, Form
from fastapi.testclient import TestClient
from pydantic import BaseModel, Field

app = FastAPI()


class FormModel(BaseModel):
    username: str
    lastname: str
    age: Optional[int] = None
    tags: list[str] = ["foo", "bar"]
    alias_with: str = Field(alias="with", default="nothing")


class FormModelExtraAllow(BaseModel):
    param: str

    model_config = {"extra": "allow"}


@app.post("/form/")
def post_form(user: Annotated[FormModel, Form()]):
    return user


@app.post("/form-extra-allow/")
def post_form_extra_allow(params: Annotated[FormModelExtraAllow, Form()]):
    return params


client = TestClient(app)


def test_send_all_data():
    response = client.post(
        "/form/",
        data={
            "username": "Rick",
            "lastname": "Sanchez",
            "age": "70",
            "tags": ["plumbus", "citadel"],
            "with": "something",
        },
    )
    assert response.status_code == 200, response.text
    assert response.json() == {
        "username": "Rick",
        "lastname": "Sanchez",
        "age": 70,
        "tags": ["plumbus", "citadel"],
        "with": "something",
    }


def test_defaults():
    response = client.post("/form/", data={"username": "Rick", "lastname": "Sanchez"})
    assert response.status_code == 200, response.text
// ... (82 more lines)

Domain

Subdomains

Dependencies

Frequently Asked Questions

What does test_forms_single_model.py do?
test_forms_single_model.py is a source file in the fastapi codebase, written in python. It belongs to the FastAPI domain, Applications subdomain.
What functions are defined in test_forms_single_model.py?
test_forms_single_model.py defines 8 function(s): post_form, post_form_extra_allow, test_defaults, test_extra_param_list, test_extra_param_single, test_invalid_data, test_no_data, test_send_all_data.
What does test_forms_single_model.py depend on?
test_forms_single_model.py imports 4 module(s): __init__.py, pydantic, testclient.py, typing.
Where is test_forms_single_model.py in the architecture?
test_forms_single_model.py is located at tests/test_forms_single_model.py (domain: FastAPI, subdomain: Applications, directory: tests).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free