whFalsa / tests /test_phone.py
codeBOKER's picture
feat: LLM-driven driver message cleanup for phone numbers and names
bb9b63f
Raw
History Blame Contribute Delete
3.75 kB
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 == "ุงู„ุฑู‚ู…:-[ุฑู‚ู… ุงู„ู‡ุงุชู]"