Home / File/ test_read_with_orm_mode.py — fastapi Source File

test_read_with_orm_mode.py — fastapi Source File

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

File python FastAPI Responses 4 imports 1 functions 4 classes

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

from typing import Any

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


def test_read_with_orm_mode() -> None:
    class PersonBase(BaseModel):
        name: str
        lastname: str

    class Person(PersonBase):
        @property
        def full_name(self) -> str:
            return f"{self.name} {self.lastname}"

        model_config = ConfigDict(from_attributes=True)

    class PersonCreate(PersonBase):
        pass

    class PersonRead(PersonBase):
        full_name: str

        model_config = {"from_attributes": True}

    app = FastAPI()

    @app.post("/people/", response_model=PersonRead)
    def create_person(person: PersonCreate) -> Any:
        db_person = Person.model_validate(person)
        return db_person

    client = TestClient(app)

    person_data = {"name": "Dive", "lastname": "Wilson"}
    response = client.post("/people/", json=person_data)
    data = response.json()
    assert response.status_code == 200, response.text
    assert data["name"] == person_data["name"]
    assert data["lastname"] == person_data["lastname"]
    assert data["full_name"] == person_data["name"] + " " + person_data["lastname"]

Domain

Subdomains

Dependencies

Frequently Asked Questions

What does test_read_with_orm_mode.py do?
test_read_with_orm_mode.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_read_with_orm_mode.py?
test_read_with_orm_mode.py defines 1 function(s): test_read_with_orm_mode.
What does test_read_with_orm_mode.py depend on?
test_read_with_orm_mode.py imports 4 module(s): __init__.py, pydantic, testclient.py, typing.
Where is test_read_with_orm_mode.py in the architecture?
test_read_with_orm_mode.py is located at tests/test_read_with_orm_mode.py (domain: FastAPI, subdomain: Responses, directory: tests).

Analyze Your Own Codebase

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

Try Supermodel Free