support/testing: new python-pydantic runtime test

While in theory, the fastapi tests finds problems with the pydantic
package, it's not obvious that this test should be run when the pydantic
package is updated.

Add a new test that just covers pydantic.

Signed-off-by: Marcus Hoffmann <buildroot@bubu1.eu>
Signed-off-by: Arnout Vandecappelle <arnout@rnout.be>
This commit is contained in:
Marcus Hoffmann
2025-05-14 17:12:45 +02:00
committed by Arnout Vandecappelle
parent c100f6a2fe
commit 45321879e1
3 changed files with 61 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
from datetime import datetime
from pydantic import BaseModel, PositiveInt
class User(BaseModel):
id: int
name: str = "John Doe"
signup_ts: datetime | None
tastes: dict[str, PositiveInt]
external_data = {
"id": 123,
"signup_ts": "2019-06-01 12:22",
"tastes": {
"wine": 9,
b"cheese": 7,
"cabbage": "1",
},
}
user = User(**external_data)
expected_user_dump = {
"id": 123,
"name": "John Doe",
"signup_ts": datetime(2019, 6, 1, 12, 22),
"tastes": {"wine": 9, "cheese": 7, "cabbage": 1},
}
assert user.id == 123
assert user.model_dump() == expected_user_dump