Home / File/ test_multi_body_errors.py — fastapi Source File

test_multi_body_errors.py — fastapi Source File

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

File python FastAPI Applications 6 imports 5 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  789994cf_4c09_9ccd_b82e_26362f9d8f29["test_multi_body_errors.py"]
  f9d54b01_68e2_bbed_c8ee_3f6749520bcb["decimal"]
  789994cf_4c09_9ccd_b82e_26362f9d8f29 --> f9d54b01_68e2_bbed_c8ee_3f6749520bcb
  752ca3d8_e45b_84ed_d1a1_588cbc236b65["dirty_equals"]
  789994cf_4c09_9ccd_b82e_26362f9d8f29 --> 752ca3d8_e45b_84ed_d1a1_588cbc236b65
  534f6e44_61b8_3c38_8b89_6934a6df9802["__init__.py"]
  789994cf_4c09_9ccd_b82e_26362f9d8f29 --> 534f6e44_61b8_3c38_8b89_6934a6df9802
  a7c04dee_ee23_5891_b185_47ff6bed036d["testclient.py"]
  789994cf_4c09_9ccd_b82e_26362f9d8f29 --> a7c04dee_ee23_5891_b185_47ff6bed036d
  a7f4e7b0_9725_db90_5cbc_7ca8211b323a["inline_snapshot"]
  789994cf_4c09_9ccd_b82e_26362f9d8f29 --> a7f4e7b0_9725_db90_5cbc_7ca8211b323a
  6913fbd4_39df_d14b_44bb_522e99b65b90["pydantic"]
  789994cf_4c09_9ccd_b82e_26362f9d8f29 --> 6913fbd4_39df_d14b_44bb_522e99b65b90
  style 789994cf_4c09_9ccd_b82e_26362f9d8f29 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from decimal import Decimal

from dirty_equals import IsOneOf
from fastapi import FastAPI
from fastapi.testclient import TestClient
from inline_snapshot import snapshot
from pydantic import BaseModel, condecimal

app = FastAPI()


class Item(BaseModel):
    name: str
    age: condecimal(gt=Decimal(0.0))  # type: ignore


@app.post("/items/")
def save_item_no_body(item: list[Item]):
    return {"item": item}


client = TestClient(app)


def test_put_correct_body():
    response = client.post("/items/", json=[{"name": "Foo", "age": 5}])
    assert response.status_code == 200, response.text
    assert response.json() == snapshot(
        {
            "item": [
                {
                    "name": "Foo",
                    "age": "5",
                }
            ]
        }
    )


def test_jsonable_encoder_requiring_error():
    response = client.post("/items/", json=[{"name": "Foo", "age": -1.0}])
    assert response.status_code == 422, response.text
    assert response.json() == {
        "detail": [
            {
                "type": "greater_than",
                "loc": ["body", 0, "age"],
                "msg": "Input should be greater than 0",
                "input": -1.0,
                "ctx": {"gt": 0},
            }
        ]
    }


def test_put_incorrect_body_multiple():
    response = client.post("/items/", json=[{"age": "five"}, {"age": "six"}])
    assert response.status_code == 422, response.text
    assert response.json() == {
        "detail": [
// ... (132 more lines)

Domain

Subdomains

Classes

Dependencies

Frequently Asked Questions

What does test_multi_body_errors.py do?
test_multi_body_errors.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_multi_body_errors.py?
test_multi_body_errors.py defines 5 function(s): save_item_no_body, test_jsonable_encoder_requiring_error, test_openapi_schema, test_put_correct_body, test_put_incorrect_body_multiple.
What does test_multi_body_errors.py depend on?
test_multi_body_errors.py imports 6 module(s): __init__.py, decimal, dirty_equals, inline_snapshot, pydantic, testclient.py.
Where is test_multi_body_errors.py in the architecture?
test_multi_body_errors.py is located at tests/test_multi_body_errors.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