Home / Function/ test_pydanticv2() — fastapi Function Reference

test_pydanticv2() — fastapi Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  aef90f17_cb00_f2c1_75a3_a15f99f4ca59["test_pydanticv2()"]
  28da70dd_46c1_67e6_3846_754eca0b4f7d["test_inherited_custom_class.py"]
  aef90f17_cb00_f2c1_75a3_a15f99f4ca59 -->|defined in| 28da70dd_46c1_67e6_3846_754eca0b4f7d
  29994725_b549_3d79_be5d_550b318b2879["serialize_a_uuid()"]
  aef90f17_cb00_f2c1_75a3_a15f99f4ca59 -->|calls| 29994725_b549_3d79_be5d_550b318b2879
  style aef90f17_cb00_f2c1_75a3_a15f99f4ca59 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

tests/test_inherited_custom_class.py lines 27–67

def test_pydanticv2():
    from pydantic import field_serializer

    app = FastAPI()

    @app.get("/fast_uuid")
    def return_fast_uuid():
        asyncpg_uuid = MyUuid("a10ff360-3b1e-4984-a26f-d3ab460bdb51")
        assert isinstance(asyncpg_uuid, uuid.UUID)
        assert type(asyncpg_uuid) is not uuid.UUID
        with pytest.raises(TypeError):
            vars(asyncpg_uuid)
        return {"fast_uuid": asyncpg_uuid}

    class SomeCustomClass(BaseModel):
        model_config = {"arbitrary_types_allowed": True}

        a_uuid: MyUuid

        @field_serializer("a_uuid")
        def serialize_a_uuid(self, v):
            return str(v)

    @app.get("/get_custom_class")
    def return_some_user():
        # Test that the fix also works for custom pydantic classes
        return SomeCustomClass(a_uuid=MyUuid("b8799909-f914-42de-91bc-95c819218d01"))

    client = TestClient(app)

    with client:
        response_simple = client.get("/fast_uuid")
        response_pydantic = client.get("/get_custom_class")

    assert response_simple.json() == {
        "fast_uuid": "a10ff360-3b1e-4984-a26f-d3ab460bdb51"
    }

    assert response_pydantic.json() == {
        "a_uuid": "b8799909-f914-42de-91bc-95c819218d01"
    }

Domain

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free