Home / File/ test_optional_str.py — fastapi Source File

test_optional_str.py — fastapi Source File

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

File python FastAPI Responses 6 imports 24 functions 4 classes

Entity Profile

Dependency Diagram

graph LR
  525d3f7f_bf8a_2cd3_0f9f_371f745561b9["test_optional_str.py"]
  0dda2280_3359_8460_301c_e98c77e78185["typing"]
  525d3f7f_bf8a_2cd3_0f9f_371f745561b9 --> 0dda2280_3359_8460_301c_e98c77e78185
  5befe8bf_65d1_d058_6b78_4a597a8488e9["pytest"]
  525d3f7f_bf8a_2cd3_0f9f_371f745561b9 --> 5befe8bf_65d1_d058_6b78_4a597a8488e9
  534f6e44_61b8_3c38_8b89_6934a6df9802["__init__.py"]
  525d3f7f_bf8a_2cd3_0f9f_371f745561b9 --> 534f6e44_61b8_3c38_8b89_6934a6df9802
  a7c04dee_ee23_5891_b185_47ff6bed036d["testclient.py"]
  525d3f7f_bf8a_2cd3_0f9f_371f745561b9 --> a7c04dee_ee23_5891_b185_47ff6bed036d
  a7f4e7b0_9725_db90_5cbc_7ca8211b323a["inline_snapshot"]
  525d3f7f_bf8a_2cd3_0f9f_371f745561b9 --> a7f4e7b0_9725_db90_5cbc_7ca8211b323a
  6913fbd4_39df_d14b_44bb_522e99b65b90["pydantic"]
  525d3f7f_bf8a_2cd3_0f9f_371f745561b9 --> 6913fbd4_39df_d14b_44bb_522e99b65b90
  style 525d3f7f_bf8a_2cd3_0f9f_371f745561b9 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from typing import Annotated, Optional

import pytest
from fastapi import FastAPI, Header
from fastapi.testclient import TestClient
from inline_snapshot import snapshot
from pydantic import BaseModel, Field

app = FastAPI()

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


@app.get("/optional-str")
async def read_optional_str(p: Annotated[Optional[str], Header()] = None):
    return {"p": p}


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


@app.get("/model-optional-str")
async def read_model_optional_str(p: Annotated[HeaderModelOptionalStr, Header()]):
    return {"p": p.p}


@pytest.mark.parametrize(
    "path",
    ["/optional-str", "/model-optional-str"],
)
def test_optional_str_schema(path: str):
    assert app.openapi()["paths"][path]["get"]["parameters"] == snapshot(
        [
            {
                "required": False,
                "schema": {
                    "anyOf": [{"type": "string"}, {"type": "null"}],
                    "title": "P",
                },
                "name": "p",
                "in": "header",
            }
        ]
    )


@pytest.mark.parametrize(
    "path",
    ["/optional-str", "/model-optional-str"],
)
def test_optional_str_missing(path: str):
    client = TestClient(app)
    response = client.get(path)
    assert response.status_code == 200
    assert response.json() == {"p": None}


@pytest.mark.parametrize(
// ... (269 more lines)

Domain

Subdomains

Dependencies

Frequently Asked Questions

What does test_optional_str.py do?
test_optional_str.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_str.py?
test_optional_str.py defines 24 function(s): read_model_optional_alias, read_model_optional_alias_and_validation_alias, read_model_optional_str, read_model_optional_validation_alias, read_optional_alias, read_optional_alias_and_validation_alias, read_optional_str, read_optional_validation_alias, test_optional_alias_and_validation_alias_by_alias, test_optional_alias_and_validation_alias_by_name, and 14 more.
What does test_optional_str.py depend on?
test_optional_str.py imports 6 module(s): __init__.py, inline_snapshot, pydantic, pytest, testclient.py, typing.
Where is test_optional_str.py in the architecture?
test_optional_str.py is located at tests/test_request_params/test_header/test_optional_str.py (domain: FastAPI, subdomain: Responses, directory: tests/test_request_params/test_header).

Analyze Your Own Codebase

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

Try Supermodel Free