File size: 3,746 Bytes
bb9b63f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | from app.utils.phone import count_digits, strip_phone_numbers
class TestCountDigits:
def test_no_digits(self):
assert count_digits("hello world") == 0
def test_all_digits(self):
assert count_digits("1234567") == 7
def test_mixed(self):
assert count_digits("abc123def456") == 6
def test_empty(self):
assert count_digits("") == 0
class TestStripPhoneNumbers:
def test_yemeni_number_with_plus(self):
result = strip_phone_numbers("اتصل على +967712345678")
assert result == "اتصل على [رقم الهاتف]"
def test_yemeni_number_with_00(self):
result = strip_phone_numbers("اتصل على 00967712345678")
assert result == "اتصل على [رقم الهاتف]"
def test_international_with_dashes(self):
result = strip_phone_numbers("Call +1-234-567-8901")
assert result == "Call [رقم الهاتف]"
def test_international_with_spaces(self):
result = strip_phone_numbers("Call +44 20 7946 0958")
assert result == "Call [رقم الهاتف]"
def test_international_with_dots(self):
result = strip_phone_numbers("Call +49.30.1234567")
assert result == "Call [رقم الهاتف]"
def test_international_with_parentheses(self):
result = strip_phone_numbers("Call +1 (234) 567-8901")
assert result == "Call [رقم الهاتف]"
def test_multiple_numbers(self):
result = strip_phone_numbers("Call +967712345678 or +967776543210")
assert result == "Call [رقم الهاتف] or [رقم الهاتف]"
def test_no_phone_numbers(self):
text = "رحلة من صنعاء إلى تعز"
result = strip_phone_numbers(text)
assert result == text
def test_short_number_not_matched(self):
result = strip_phone_numbers("Room 123")
assert result == "Room 123"
def test_empty_string(self):
assert strip_phone_numbers("") == ""
def test_none_returns_none(self):
assert strip_phone_numbers(None) is None
def test_custom_replacement(self):
result = strip_phone_numbers("Call +967712345678", replacement="***")
assert result == "Call ***"
def test_number_at_start(self):
result = strip_phone_numbers("+967712345678 اتصل")
assert result == "[رقم الهاتف] اتصل"
def test_number_at_end(self):
result = strip_phone_numbers("اتصل +967712345678")
assert result == "اتصل [رقم الهاتف]"
def test_number_in_middle_of_text(self):
result = strip_phone_numbers("اتصل على +967712345678 للحجز")
assert result == "اتصل على [رقم الهاتف] للحجز"
def test_yemeni_local_format(self):
result = strip_phone_numbers("0712345678")
assert result == "[رقم الهاتف]"
def test_number_with_country_code_no_plus(self):
result = strip_phone_numbers("967712345678")
assert result == "[رقم الهاتف]"
def test_long_number_with_separators(self):
result = strip_phone_numbers("+1 (555) 123-4567 ext 890")
assert result == "[رقم الهاتف] ext 890"
def test_local_yemeni_9_digit(self):
result = strip_phone_numbers("770026665")
assert result == "[رقم الهاتف]"
def test_local_yemeni_in_message(self):
result = strip_phone_numbers("للتواصل على الرقم 770026665")
assert result == "للتواصل على الرقم [رقم الهاتف]"
def test_local_yemeni_with_dash_prefix(self):
result = strip_phone_numbers("الرقم:-770026665")
assert result == "الرقم:-[رقم الهاتف]"
|