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.

31 lines
842 B
Python

import pytest
from htmx_contact.models import Contact
from htmx_contact.models import _is_valid_phone_number
@pytest.mark.parametrize(
"phone,expected",
[
("(555)555-5555", True),
("+1(555)555-5555", True),
("213-467-9085", True),
("1-555-555-5555", True),
("+15555555555", True),
# Too few digits
("15555555", False),
("not a phone number", False),
# Too many digits
("(555) 555-555a", False),
("+1555555555a", False),
("(555) 555-5555 x123", True),
],
)
def test_is_valid_phone_number(phone, expected):
assert _is_valid_phone_number(phone) == expected
def test_setting_incorrect_phone_raises_error_in_contact():
with pytest.raises(ValueError):
Contact(first_name="Fake", last_name="Fake", phone="not a number")