def test_should_return_false_for_non_string_objects(self): # noinspection PyTypeChecker self.assertFalse(is_email(None)) # noinspection PyTypeChecker self.assertFalse(is_email(False)) # noinspection PyTypeChecker self.assertFalse(is_email(0)) # noinspection PyTypeChecker self.assertFalse(is_email([])) # noinspection PyTypeChecker self.assertFalse(is_email({'a': 1}))
def test_should_accept_valid_emails(self): self.assertTrue(is_email('*****@*****.**')) self.assertTrue(is_email('*****@*****.**')) self.assertTrue(is_email('*****@*****.**')) self.assertTrue(is_email('*****@*****.**')) self.assertTrue(is_email('*****@*****.**')) self.assertTrue(is_email('*****@*****.**')) self.assertTrue(is_email('*****@*****.**')) self.assertTrue(is_email('*****@*****.**'))
def test_does_not_try_to_format_email(self): email = '*****@*****.**' self.assertTrue(is_email(email)) self.assertEqual(email, prettify(email)) self.assertEqual('This is the email: {}'.format(email), prettify('this is the email : {}'.format(email))) multiple_emails = [ '*****@*****.**', '*****@*****.**', '*****@*****.**' ] self.assertEqual(prettify(','.join(multiple_emails)), ', '.join(multiple_emails))
def test_head_cannot_end_with_period(self): self.assertFalse(is_email('*****@*****.**'))
def test_domain_extension_should_be_letters_only_from_2_to_4_chars(self): self.assertFalse(is_email('[email protected]')) self.assertFalse(is_email('[email protected]')) self.assertFalse(is_email('me@foo.!!')) self.assertFalse(is_email('me@foo.___')) self.assertFalse(is_email('*****@*****.**'))
def test_tail_length_is_respected(self): # max tail size is 255 invalid_email = 'a@{}.com'.format(255 * 'x') self.assertFalse(is_email(invalid_email))
def test_plus_is_invalid_char_in_tail(self): self.assertFalse(is_email('mymail@foo+bar.com'))
def test_domain_cannot_be_single_char(self): self.assertFalse(is_email('*****@*****.**'))
def test_max_email_length_is_respected(self): invalid_email = ('a' * 320) + '@gmail.com' self.assertFalse(is_email(invalid_email))
def test_with_escape_multiple_at_are_accepted(self): self.assertTrue(is_email('Abc\\@[email protected]'))
def test_tail_cannot_be_uppercase(self): self.assertFalse(is_email('*****@*****.**'))
def test_head_quotes_must_be_correct(self): self.assertFalse(is_email('"*****@*****.**')) self.assertFalse(is_email('no"*****@*****.**')) self.assertFalse(is_email('nope"@gmail.com')) self.assertFalse(is_email('""@gmail.com')) self.assertFalse(is_email('"no"pe"@gmail.com'))
def test_with_quoted_string_multiple_at_are_accepted(self): self.assertTrue(is_email('"Abc@def"@example.com'))
def test_head_can_be_quoted(self): self.assertTrue(is_email('"foo"@example.com'))
def test_empty_spaces_are_allowed_only_if_escaped(self): self.assertFalse(is_email('my [email protected]')) self.assertTrue(is_email('my\\ [email protected]')) self.assertTrue(is_email('"my mail"@gmail.com'))
def test_head_cannot_have_multiple_consecutive_periods(self): self.assertFalse(is_email('*****@*****.**')) self.assertFalse(is_email('*****@*****.**'))
def test_head_cannot_contain_suqare_brackets(self): self.assertFalse(is_email('[[email protected]')) self.assertFalse(is_email('my][email protected]'))
def test_head_can_have_self_escape(self): self.assertTrue(is_email('Joe.\\\\[email protected]'))
def test_tail_cannot_contain_bad_signs(self): self.assertFalse(is_email('me@#foo#.com')) self.assertFalse(is_email('me@foo!.com')) self.assertFalse(is_email('someone@[foo].com'))
def test_string_cannot_be_empty(self): self.assertFalse(is_email('')) self.assertFalse(is_email(' '))
def test_tail_cannot_contain_dots_sequence(self): self.assertFalse(is_email('*****@*****.**')) self.assertFalse(is_email('*****@*****.**'))
def test_tail_is_required(self): self.assertFalse(is_email('name@'))
def test_curly_braces_are_valid_char_in_head(self): self.assertTrue(is_email('my{[email protected]')) self.assertTrue(is_email('my}[email protected]')) self.assertTrue(is_email('{mymail}@gmail.com'))
def test_head_is_required(self): self.assertFalse(is_email('@foo.com'))
def test_head_length_is_respected(self): # max head size is 64 invalid_email = ('a' * 65) + '@gmail.com' self.assertFalse(is_email(invalid_email))
def test_tilde_is_invalid_char_in_tail(self): self.assertFalse(is_email('mymail@gma~il.com'))
def test_plus_is_valid_char_in_head(self): self.assertTrue(is_email('*****@*****.**'))
def test_domain_extension_is_required(self): self.assertFalse(is_email('name@site')) self.assertFalse(is_email('name@site.'))
def test_at_sign_is_required(self): self.assertFalse(is_email('name.site.com'))
def test_head_cannot_start_with_period(self): self.assertFalse(is_email('*****@*****.**'))