remove emailstr to vavoid additional deps

This commit is contained in:
collerek
2021-04-20 11:59:36 +02:00
parent 5e38426694
commit 8b951a48be

View File

@ -3,7 +3,7 @@ from typing import Optional
import databases
import pytest
import sqlalchemy
from pydantic import EmailStr, HttpUrl, ValidationError
from pydantic import HttpUrl
import ormar
from tests.settings import DATABASE_URL
@ -23,15 +23,12 @@ class Test(ormar.Model):
def __init__(self, **kwargs):
# you need to pop non - db fields as ormar will complain that it's unknown field
email = kwargs.pop("email", self.__fields__["email"].get_default())
url = kwargs.pop("url", self.__fields__["url"].get_default())
super().__init__(**kwargs)
self.email = email
self.url = url
id: int = ormar.Integer(primary_key=True)
name: str = ormar.String(max_length=200)
email: Optional[EmailStr] # field optional - default to None
url: HttpUrl = "www.example.com" # field with default
@ -47,19 +44,17 @@ def create_test_database():
@pytest.mark.asyncio
async def test_working_with_pydantic_fields():
async with database:
test = Test(name="Test", email="aka@go2.com")
test = Test(name="Test")
assert test.name == "Test"
assert test.email == "aka@go2.com"
assert test.url == "www.example.com"
test.email = "sdta@ada.pt"
assert test.email == "sdta@ada.pt"
test.url = "www.sdta.ada.pt"
assert test.url == "www.sdta.ada.pt"
await test.save()
test_check = await Test.objects.get()
assert test_check.name == "Test"
assert test_check.email is None
assert test_check.url == "www.example.com"
# TODO add validate assignment to pydantic config