Home / File/ test_required_str.py — fastapi Source File

test_required_str.py — fastapi Source File

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

File python FastAPI Routing 8 imports 24 functions 4 classes

Entity Profile

Dependency Diagram

graph LR
  45768896_4720_0ffe_18a6_a9be9369e316["test_required_str.py"]
  1877f2a6_b800_9b18_3a1c_81db1771b81d["utils.py"]
  45768896_4720_0ffe_18a6_a9be9369e316 --> 1877f2a6_b800_9b18_3a1c_81db1771b81d
  5fadf4ad_2b8a_4b4f_fde9_555fff6ad722["get_body_model_name"]
  45768896_4720_0ffe_18a6_a9be9369e316 --> 5fadf4ad_2b8a_4b4f_fde9_555fff6ad722
  0dda2280_3359_8460_301c_e98c77e78185["typing"]
  45768896_4720_0ffe_18a6_a9be9369e316 --> 0dda2280_3359_8460_301c_e98c77e78185
  5befe8bf_65d1_d058_6b78_4a597a8488e9["pytest"]
  45768896_4720_0ffe_18a6_a9be9369e316 --> 5befe8bf_65d1_d058_6b78_4a597a8488e9
  752ca3d8_e45b_84ed_d1a1_588cbc236b65["dirty_equals"]
  45768896_4720_0ffe_18a6_a9be9369e316 --> 752ca3d8_e45b_84ed_d1a1_588cbc236b65
  534f6e44_61b8_3c38_8b89_6934a6df9802["__init__.py"]
  45768896_4720_0ffe_18a6_a9be9369e316 --> 534f6e44_61b8_3c38_8b89_6934a6df9802
  a7c04dee_ee23_5891_b185_47ff6bed036d["testclient.py"]
  45768896_4720_0ffe_18a6_a9be9369e316 --> a7c04dee_ee23_5891_b185_47ff6bed036d
  6913fbd4_39df_d14b_44bb_522e99b65b90["pydantic"]
  45768896_4720_0ffe_18a6_a9be9369e316 --> 6913fbd4_39df_d14b_44bb_522e99b65b90
  style 45768896_4720_0ffe_18a6_a9be9369e316 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from typing import Annotated

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

from .utils import get_body_model_name

app = FastAPI()

# =====================================================================================
# Without aliases


@app.post("/required-str", operation_id="required_str")
async def read_required_str(p: Annotated[str, Form()]):
    return {"p": p}


class FormModelRequiredStr(BaseModel):
    p: str


@app.post("/model-required-str", operation_id="model_required_str")
async def read_model_required_str(p: Annotated[FormModelRequiredStr, Form()]):
    return {"p": p.p}


@pytest.mark.parametrize(
    "path",
    ["/required-str", "/model-required-str"],
)
def test_required_str_schema(path: str):
    openapi = app.openapi()
    body_model_name = get_body_model_name(openapi, path)

    assert app.openapi()["components"]["schemas"][body_model_name] == {
        "properties": {
            "p": {"title": "P", "type": "string"},
        },
        "required": ["p"],
        "title": body_model_name,
        "type": "object",
    }


@pytest.mark.parametrize(
    "path",
    ["/required-str", "/model-required-str"],
)
def test_required_str_missing(path: str):
    client = TestClient(app)
    response = client.post(path)
    assert response.status_code == 422
    assert response.json() == {
        "detail": [
            {
                "type": "missing",
// ... (356 more lines)

Domain

Subdomains

Dependencies

Frequently Asked Questions

What does test_required_str.py do?
test_required_str.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_required_str.py?
test_required_str.py defines 24 function(s): read_model_required_alias, read_model_required_alias_and_validation_alias, read_model_required_str, read_model_required_validation_alias, read_required_alias, read_required_alias_and_validation_alias, read_required_str, read_required_validation_alias, test_required_alias_and_validation_alias_by_alias, test_required_alias_and_validation_alias_by_name, and 14 more.
What does test_required_str.py depend on?
test_required_str.py imports 8 module(s): __init__.py, dirty_equals, get_body_model_name, pydantic, pytest, testclient.py, typing, utils.py.
Where is test_required_str.py in the architecture?
test_required_str.py is located at tests/test_request_params/test_form/test_required_str.py (domain: FastAPI, subdomain: Routing, directory: tests/test_request_params/test_form).

Analyze Your Own Codebase

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

Try Supermodel Free