You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
849 B
Python

import pytest
from pydantic import ValidationError
from htmx_contact.validators import NewContactValidator
from htmx_contact.validators import repack_validation_errors
def test_new_contact_errors():
with pytest.raises(ValidationError) as error:
NewContactValidator(first_name="Drew", last_name="bednar", phone="666-7777-3333", email="not a valid email")
assert len(error.value.errors()) == 2
def test_repackage_errors():
with pytest.raises(ValidationError) as error:
NewContactValidator(first_name="Drew", last_name="bednar", phone="666-7777-3333", email="not a valid email")
repackaged_errors = repack_validation_errors(error.value.errors())
assert len(repackaged_errors) == 2
assert 'not a valid phone number' in repackaged_errors['phone']
assert 'not a valid email' in repackaged_errors['email']