@@ -107,23 +107,43 @@ def test_invalidate_cache_user_profile_country_updated(self):
107107 assert cache .get (cache_key ) != country
108108 assert cache .get (cache_key ) is None
109109
110- def test_phone_number_can_only_contain_digits (self ):
111- # validating the profile will fail, because there are letters
112- # in the phone number
113- self .profile .phone_number = 'abc'
114- pytest .raises (ValidationError , self .profile .full_clean )
115- # fail if mixed digits/letters
116- self .profile .phone_number = '1234gb'
117- pytest .raises (ValidationError , self .profile .full_clean )
118- # fail if whitespace
119- self .profile .phone_number = ' 123'
120- pytest .raises (ValidationError , self .profile .full_clean )
121- # fail with special characters
122- self .profile .phone_number = '123!@#$%^&*'
123- pytest .raises (ValidationError , self .profile .full_clean )
124- # valid phone number
125- self .profile .phone_number = '123456789'
126- try :
127- self .profile .full_clean ()
128- except ValidationError :
129- self .fail ("This phone number should be valid." )
110+ def test_valid_phone_numbers (self ):
111+ """
112+ Test that valid phone numbers are accepted.
113+
114+ Expected behavior:
115+ - The phone number '+123456789' should be considered valid.
116+ - The phone number '123456789' (without '+') should also be valid.
117+
118+ This test verifies that valid phone numbers are accepted by the profile model validation.
119+ """
120+ valid_numbers = ['+123456789' , '123456789' ]
121+
122+ for number in valid_numbers :
123+ self .profile .phone_number = number
124+
125+ try :
126+ self .profile .full_clean ()
127+ except ValidationError :
128+ self .fail ("This phone number should be valid." )
129+
130+ def test_invalid_phone_numbers (self ):
131+ """
132+ Test that invalid phone numbers raise ValidationError.
133+
134+ Expected behavior:
135+ - Phone numbers with letters, mixed digits/letters, whitespace,
136+ or special characters should raise a ValidationError.
137+
138+ This test verifies that invalid phone numbers are rejected by the profile model validation.
139+ """
140+ invalid_phone_numbers = [
141+ 'abc' , # Letters in the phone number
142+ '1234gb' , # Mixed digits and letters
143+ ' 123' , # Whitespace
144+ '123!@#$%^&*' # Special characters
145+ ]
146+
147+ for number in invalid_phone_numbers :
148+ self .profile .phone_number = number
149+ pytest .raises (ValidationError , self .profile .full_clean )
0 commit comments