Home / Function/ test_pydanticv2() — fastapi Function Reference

test_pydanticv2() — fastapi Function Reference

Architecture documentation for the test_pydanticv2() function in test_datetime_custom_encoder.py from the fastapi codebase.

Entity Profile

Dependency Diagram

graph TD
  4a2e1995_b5ba_18a5_57e1_3c34cb62d315["test_pydanticv2()"]
  ba3bdf28_df52_2d09_627b_a8d890f2909e["test_datetime_custom_encoder.py"]
  4a2e1995_b5ba_18a5_57e1_3c34cb62d315 -->|defined in| ba3bdf28_df52_2d09_627b_a8d890f2909e
  9e7a1140_4d31_531d_9149_bdff2264fcff["serialize_datetime()"]
  4a2e1995_b5ba_18a5_57e1_3c34cb62d315 -->|calls| 9e7a1140_4d31_531d_9149_bdff2264fcff
  style 4a2e1995_b5ba_18a5_57e1_3c34cb62d315 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

tests/test_datetime_custom_encoder.py lines 8–28

def test_pydanticv2():
    from pydantic import field_serializer

    class ModelWithDatetimeField(BaseModel):
        dt_field: datetime

        @field_serializer("dt_field")
        def serialize_datetime(self, dt_field: datetime):
            return dt_field.replace(microsecond=0, tzinfo=timezone.utc).isoformat()

    app = FastAPI()
    model = ModelWithDatetimeField(dt_field=datetime(2019, 1, 1, 8))

    @app.get("/model", response_model=ModelWithDatetimeField)
    def get_model():
        return model

    client = TestClient(app)
    with client:
        response = client.get("/model")
    assert response.json() == {"dt_field": "2019-01-01T08:00:00+00:00"}

Domain

Subdomains

Frequently Asked Questions

What does test_pydanticv2() do?
test_pydanticv2() is a function in the fastapi codebase, defined in tests/test_datetime_custom_encoder.py.
Where is test_pydanticv2() defined?
test_pydanticv2() is defined in tests/test_datetime_custom_encoder.py at line 8.
What does test_pydanticv2() call?
test_pydanticv2() calls 1 function(s): serialize_datetime.

Analyze Your Own Codebase

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

Try Supermodel Free