WIP on README
This commit is contained in:
parent
09c91fb756
commit
7c0bea751b
7 changed files with 319 additions and 49 deletions
50
tests/test_pydantic_integrations.py
Normal file
50
tests/test_pydantic_integrations.py
Normal file
|
@ -0,0 +1,50 @@
|
|||
import abc
|
||||
import datetime
|
||||
from collections import namedtuple
|
||||
|
||||
import pytest
|
||||
from pydantic import EmailStr, ValidationError
|
||||
|
||||
from redis_om.model import HashModel, Field
|
||||
from redis_om.model.migrations.migrator import Migrator
|
||||
|
||||
|
||||
today = datetime.date.today()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def m(key_prefix):
|
||||
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
|
||||
|
||||
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,
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue