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")