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>
(cherry picked from commit 45321879e1)
Signed-off-by: Thomas Perale <thomas.perale@mind.be>
33 lines
632 B
Python
33 lines
632 B
Python
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
|