def test_string_in_phone_number(self): with self.assertRaises(forms.ValidationError): PhoneNumberField().clean('BADNUMBER')
def test_phone_number_extension_error(self): with self.assertRaises(forms.ValidationError): PhoneNumberField(allow_extension=False).clean('13035555555ex123')
def test_international_phone_number(self): self.assertEqual(PhoneNumberField().clean('+4991319402813'), '+49 9131 9402813')
def test_phone_number_with_bad_extension(self): with self.assertRaises(forms.ValidationError): PhoneNumberField().clean('13035555555ex1BAD')
def test_phone_number_with_good_extension(self): self.assertEqual(PhoneNumberField().clean('13035555555ex555555'), '(303) 555-5555 ext. 555555')
def test_bad_phone_number(self): with self.assertRaises(forms.ValidationError): PhoneNumberField().clean('978121')
def test_good_phone_number(self): self.assertEqual(PhoneNumberField().clean('13035555555'), '(303) 555-5555')