Home / File/ test_optional_list.py — fastapi Source File

test_optional_list.py — fastapi Source File

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

File python FastAPI Responses 7 imports 32 functions 4 classes

Entity Profile

Dependency Diagram

graph LR
  e5136429_9a94_4b13_0278_d22fff767687["test_optional_list.py"]
  9f6ffe39_b348_5643_336e_8d6ee8bb59bb["utils.py"]
  e5136429_9a94_4b13_0278_d22fff767687 --> 9f6ffe39_b348_5643_336e_8d6ee8bb59bb
  28b7c1b7_b1b8_c344_dea4_80c78da77e28["get_body_model_name"]
  e5136429_9a94_4b13_0278_d22fff767687 --> 28b7c1b7_b1b8_c344_dea4_80c78da77e28
  0dda2280_3359_8460_301c_e98c77e78185["typing"]
  e5136429_9a94_4b13_0278_d22fff767687 --> 0dda2280_3359_8460_301c_e98c77e78185
  5befe8bf_65d1_d058_6b78_4a597a8488e9["pytest"]
  e5136429_9a94_4b13_0278_d22fff767687 --> 5befe8bf_65d1_d058_6b78_4a597a8488e9
  534f6e44_61b8_3c38_8b89_6934a6df9802["__init__.py"]
  e5136429_9a94_4b13_0278_d22fff767687 --> 534f6e44_61b8_3c38_8b89_6934a6df9802
  a7c04dee_ee23_5891_b185_47ff6bed036d["testclient.py"]
  e5136429_9a94_4b13_0278_d22fff767687 --> a7c04dee_ee23_5891_b185_47ff6bed036d
  6913fbd4_39df_d14b_44bb_522e99b65b90["pydantic"]
  e5136429_9a94_4b13_0278_d22fff767687 --> 6913fbd4_39df_d14b_44bb_522e99b65b90
  style e5136429_9a94_4b13_0278_d22fff767687 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from typing import Annotated, Optional

import pytest
from fastapi import Body, FastAPI
from fastapi.testclient import TestClient
from pydantic import BaseModel, Field

from .utils import get_body_model_name

app = FastAPI()

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


@app.post("/optional-list-str", operation_id="optional_list_str")
async def read_optional_list_str(
    p: Annotated[Optional[list[str]], Body(embed=True)] = None,
):
    return {"p": p}


class BodyModelOptionalListStr(BaseModel):
    p: Optional[list[str]] = None


@app.post("/model-optional-list-str", operation_id="model_optional_list_str")
async def read_model_optional_list_str(p: BodyModelOptionalListStr):
    return {"p": p.p}


@pytest.mark.parametrize(
    "path",
    ["/optional-list-str", "/model-optional-list-str"],
)
def test_optional_list_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": {
                "anyOf": [
                    {"items": {"type": "string"}, "type": "array"},
                    {"type": "null"},
                ],
                "title": "P",
            },
        },
        "title": body_model_name,
        "type": "object",
    }


def test_optional_list_str_missing():
    client = TestClient(app)
    response = client.post("/optional-list-str")
    assert response.status_code == 200, response.text
    assert response.json() == {"p": None}

// ... (397 more lines)

Domain

Subdomains

Dependencies

Frequently Asked Questions

What does test_optional_list.py do?
test_optional_list.py is a source file in the fastapi codebase, written in python. It belongs to the FastAPI domain, Responses subdomain.
What functions are defined in test_optional_list.py?
test_optional_list.py defines 32 function(s): read_model_optional_list_alias, read_model_optional_list_alias_and_validation_alias, read_model_optional_list_str, read_model_optional_list_validation_alias, read_optional_list_alias, read_optional_list_alias_and_validation_alias, read_optional_list_str, read_optional_list_validation_alias, test_model_optional_list_alias_and_validation_alias_missing, test_model_optional_list_alias_missing, and 22 more.
What does test_optional_list.py depend on?
test_optional_list.py imports 7 module(s): __init__.py, get_body_model_name, pydantic, pytest, testclient.py, typing, utils.py.
Where is test_optional_list.py in the architecture?
test_optional_list.py is located at tests/test_request_params/test_body/test_optional_list.py (domain: FastAPI, subdomain: Responses, directory: tests/test_request_params/test_body).

Analyze Your Own Codebase

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

Try Supermodel Free