Impl simple email and phone number validation
This commit is contained in:
@ -17,4 +17,6 @@ urllib3==2.4.0
|
|||||||
pydantic==2.11.3
|
pydantic==2.11.3
|
||||||
langchain==0.3.23
|
langchain==0.3.23
|
||||||
langchain-groq==0.3.2
|
langchain-groq==0.3.2
|
||||||
email-validator==2.2.0
|
email-validator==2.2.0
|
||||||
|
pydantic-extra-types==2.10.3
|
||||||
|
phonenumbers==9.0.3
|
@ -2,11 +2,22 @@ from datetime import date
|
|||||||
|
|
||||||
from pydantic import ValidationError
|
from pydantic import ValidationError
|
||||||
import pytest
|
import pytest
|
||||||
from tests.dummy import dummy_passport
|
from tests.dummy import dummy_account, dummy_passport
|
||||||
from validation.from_passport import FromPassport
|
from validation.from_passport import FromPassport
|
||||||
|
|
||||||
|
|
||||||
def test_check_expiry_date_after_issue_date() -> None:
|
def test_check_expiry_date_after_issue_date() -> None:
|
||||||
dummy = dummy_passport()
|
dummy = dummy_passport()
|
||||||
with pytest.raises(ValidationError):
|
with pytest.raises(ValidationError):
|
||||||
dummy.expiry_date = date(1900, 1, 1)
|
dummy.expiry_date = date(1900, 1, 1)
|
||||||
|
|
||||||
|
def test_invalid_email() -> None:
|
||||||
|
dummy = dummy_account()
|
||||||
|
with pytest.raises(ValidationError):
|
||||||
|
dummy.email = "this is not a valid email account"
|
||||||
|
|
||||||
|
def test_invalid_phone_number() -> None:
|
||||||
|
dummy = dummy_account()
|
||||||
|
with pytest.raises(ValidationError):
|
||||||
|
dummy.phone_number = "This should be invalid"
|
||||||
|
dummy.phone_number = "+41 32 333 33 33"
|
@ -1,6 +1,6 @@
|
|||||||
from typing import Literal, Optional, Self
|
from typing import Literal, Optional, Self
|
||||||
from pydantic import BaseModel, ConfigDict, EmailStr, Field, model_validator
|
from pydantic import BaseModel, ConfigDict, EmailStr, Field, model_validator
|
||||||
|
from pydantic_extra_types.phone_numbers import PhoneNumber
|
||||||
|
|
||||||
class FromAccount(BaseModel):
|
class FromAccount(BaseModel):
|
||||||
"""
|
"""
|
||||||
@ -32,5 +32,5 @@ class FromAccount(BaseModel):
|
|||||||
country: str = Field(min_length=1)
|
country: str = Field(min_length=1)
|
||||||
|
|
||||||
name: str = Field(min_length=1)
|
name: str = Field(min_length=1)
|
||||||
phone_number: str = Field(min_length=6)
|
phone_number: PhoneNumber
|
||||||
email: EmailStr
|
email: EmailStr
|
@ -1,2 +1,7 @@
|
|||||||
# TODO
|
# TODO
|
||||||
# account.reference_currency corresponds to passport.country
|
# account.reference_currency corresponds to passport.country
|
||||||
|
|
||||||
|
# account.country ~ passport.country
|
||||||
|
|
||||||
|
# account.city is in account.country
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user