Пример #1
0
 def test_valid_email_address(self):  # type: () -> None
     schema = EmailAddress()
     for one_email in self.valid_emails:
         self.assertEqual(
             schema.errors(one_email),
             [],
         )
Пример #2
0
 def test_whitelisted_address_via_constructor(self):  # type: () -> None
     whitelisted_domains = ['a-whitelisted-domain']
     schema = EmailAddress(whitelist=whitelisted_domains)
     self.assertEqual(
         schema.errors('a-name@a-whitelisted-domain'),
         [],
     )
Пример #3
0
 def test_non_whitelisted_address(self):  # type: () -> None
     whitelisted_domains = ['a-whitelisted-domain']
     schema = EmailAddress(whitelist=whitelisted_domains)
     self.assertEqual(
         schema.errors('a-name@non-whitelisted-domain'),
         [Error('Not a valid email address (invalid domain field)', pointer='non-whitelisted-domain')],
     )
Пример #4
0
    def test_invalid_email_address(self):  # type: () -> None
        schema = EmailAddress()
        self.assertEqual(
            schema.errors('Abc.example.com'),
            [Error('Not a valid email address (missing @ sign)')],
        )

        self.assertEqual(
            schema.errors('A@b@[email protected]'),
            [Error('Not a valid email address (invalid local user field)', pointer='A@b@c')],
        )
        self.assertEqual(
            schema.errors('a"b(c)d,e:f;g<h>i[j\\k][email protected]'),
            [Error('Not a valid email address (invalid local user field)', pointer='a"b(c)d,e:f;g<h>i[j\\k]l')],
        )
        self.assertEqual(
            schema.errors('just"not"*****@*****.**'),
            [Error('Not a valid email address (invalid local user field)', pointer='just"not"right')],
        )
        self.assertEqual(
            schema.errors('this is"not\[email protected]'),
            [Error('Not a valid email address (invalid local user field)', pointer='this is"not\x07llowed')],
        )
        self.assertEqual(
            schema.errors('this\\ still\"not\\[email protected]'),
            [Error('Not a valid email address (invalid local user field)', pointer='this\\ still"not\\allowed')],
        )
        # self.assertEqual(
        #     schema.errors('*****@*****.**'),
        #     [Error('Not a valid email address (invalid local user field)')],
        # )
        self.assertEqual(
            schema.errors('*****@*****.**'),
            [Error('Not a valid email address (invalid local user field)', pointer='john..doe')]
        )
        self.assertEqual(
            schema.errors('*****@*****.**'),
            [Error('Not a valid email address (invalid domain field)', pointer='example..com')],
        )
        self.assertEqual(
            schema.errors('" "@example.org'),
            [Error('Not a valid email address (invalid local user field)', pointer='" "')],
        )
        # Internationalization, currently not supported
        self.assertEqual(
            schema.errors('Pelé@example.com'),
            [Error('Not a valid email address (invalid local user field)', pointer='Pelé')],
        )
        self.assertEqual(
            schema.errors('δοκιμή@παράδειγμα.δοκιμή'),
            [Error('Not a valid email address (invalid local user field)', pointer='δοκιμή')],
        )
        self.assertEqual(
            schema.errors('我買@屋企.香港'),
            [Error('Not a valid email address (invalid local user field)', pointer='我買')],
        )
        self.assertEqual(
            schema.errors('甲斐@黒川.日本'),
            [Error('Not a valid email address (invalid local user field)', pointer='甲斐')],
        )
        self.assertEqual(
            schema.errors('чебурашка@ящик-с-апельсинами.рф'),
            [Error('Not a valid email address (invalid local user field)', pointer='чебурашка')],
        )
        self.assertEqual(
            schema.errors('संपर्क@डाटामेल.भारत'),
            [Error('Not a valid email address (invalid local user field)', pointer='संपर्क')],
        )
        self.assertEqual(
            schema.errors('nick@[1.2.3.4:56]'),
            [Error('Not a valid email address (invalid domain field)', pointer='[1.2.3.4:56]')]
        )
Пример #5
0
 def test_not_unicode(self):  # type: () -> None
     schema = EmailAddress()
     assert schema.errors(self.valid_emails[0].encode('utf-8')) == [Error('Not a unicode string')]
Пример #6
0
 def test_valid_non_whitelisted_address(self):  # type: () -> None
     schema = EmailAddress()
     self.assertEqual(
         schema.errors('*****@*****.**'),
         [],
     )