-
Notifications
You must be signed in to change notification settings - Fork 122
/
Copy pathtest_pydantic_integrations.py
50 lines (38 loc) · 1.1 KB
/
test_pydantic_integrations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import abc
import datetime
from collections import namedtuple
import pytest
import pytest_asyncio
from aredis_om import Field, HashModel, Migrator
from tests._compat import EmailStr, ValidationError
today = datetime.date.today()
@pytest_asyncio.fixture
async def m(key_prefix, redis):
class BaseHashModel(HashModel, abc.ABC):
class Meta:
global_key_prefix = key_prefix
class Member(BaseHashModel):
first_name: str
last_name: str
email: EmailStr = Field(index=True)
join_date: datetime.date
age: int
await Migrator().run()
return namedtuple("Models", ["Member"])(Member)
def test_email_str(m):
with pytest.raises(ValidationError):
m.Member(
first_name="Andrew",
last_name="Brookins",
email="not an email!",
age=38,
join_date=today,
)
with pytest.raises(ValidationError):
m.Member(
first_name="Andrew",
last_name="Brookins",
email="andrew@bad-domain",
age=38,
join_date=today,
)