Home / File/ test_serialize_response.py — fastapi Source File

test_serialize_response.py — fastapi Source File

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

File python FastAPI Applications 4 imports 6 functions 1 classes

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

from typing import Optional

from fastapi import FastAPI
from fastapi.testclient import TestClient
from pydantic import BaseModel

app = FastAPI()


class Item(BaseModel):
    name: str
    price: Optional[float] = None
    owner_ids: Optional[list[int]] = None


@app.get("/items/valid", response_model=Item)
def get_valid():
    return {"name": "valid", "price": 1.0}


@app.get("/items/coerce", response_model=Item)
def get_coerce():
    return {"name": "coerce", "price": "1.0"}


@app.get("/items/validlist", response_model=list[Item])
def get_validlist():
    return [
        {"name": "foo"},
        {"name": "bar", "price": 1.0},
        {"name": "baz", "price": 2.0, "owner_ids": [1, 2, 3]},
    ]


client = TestClient(app)


def test_valid():
    response = client.get("/items/valid")
    response.raise_for_status()
    assert response.json() == {"name": "valid", "price": 1.0, "owner_ids": None}


def test_coerce():
    response = client.get("/items/coerce")
    response.raise_for_status()
    assert response.json() == {"name": "coerce", "price": 1.0, "owner_ids": None}


def test_validlist():
    response = client.get("/items/validlist")
    response.raise_for_status()
    assert response.json() == [
        {"name": "foo", "price": None, "owner_ids": None},
        {"name": "bar", "price": 1.0, "owner_ids": None},
        {"name": "baz", "price": 2.0, "owner_ids": [1, 2, 3]},
    ]

Domain

Subdomains

Classes

Dependencies

Frequently Asked Questions

What does test_serialize_response.py do?
test_serialize_response.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_serialize_response.py?
test_serialize_response.py defines 6 function(s): get_coerce, get_valid, get_validlist, test_coerce, test_valid, test_validlist.
What does test_serialize_response.py depend on?
test_serialize_response.py imports 4 module(s): __init__.py, pydantic, testclient.py, typing.
Where is test_serialize_response.py in the architecture?
test_serialize_response.py is located at tests/test_serialize_response.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