-
Notifications
You must be signed in to change notification settings - Fork 3
/
tests.py
102 lines (69 loc) · 3.48 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import unittest
import sys
import mock
from email_normalizer import normalize, _get_mx_servers, _load_domains
class NormalizerTest(unittest.TestCase):
def test_to_lower(self):
self.assertEqual(normalize('[email protected]'), '[email protected]')
def test_resolving(self):
with mock.patch('email_normalizer._get_mx_servers') as patched_method, \
mock.patch('email_normalizer.google.GoogleNormalizer.normalize') as google_normalize:
patched_method.return_value = ['mx.google.com']
normalize('test@under_google_mx.com')
self.failUnless(patched_method.called)
self.assertTrue(google_normalize.called)
def test_wrong_domain(self):
domain = 'not_existing.domain'
self.assertEqual(_get_mx_servers(domain), [])
def test_default(self):
self.assertEqual(normalize('[email protected]', resolve=False), '[email protected]')
def test_duplicated_domains(self):
with mock.patch('email_normalizer.google.GoogleNormalizer.domains', ['samedomain.com']), \
mock.patch('email_normalizer.yandex.YandexNormalizer.domains', ['samedomain.com']):
self.assertRaises(ValueError, _load_domains)
class YandexNormalizerTests(unittest.TestCase):
def test_ya(self):
self.assertEqual(normalize('[email protected]'), '[email protected]')
def test_narod(self):
self.assertEqual(normalize('[email protected]'), '[email protected]')
def test_yandexcom(self):
self.assertEqual(normalize('[email protected]'), '[email protected]')
def test_yandexby(self):
self.assertEqual(normalize('[email protected]'), '[email protected]')
def test_yandexkz(self):
self.assertEqual(normalize('[email protected]'), '[email protected]')
def test_yandexua(self):
self.assertEqual(normalize('[email protected]'), '[email protected]')
def test_extra(self):
self.assertEqual(normalize('[email protected]'), '[email protected]')
class FastMailNormalizerTests(unittest.TestCase):
def test_extra(self):
self.assertEqual(normalize('[email protected]'), '[email protected]')
def test_domain_segments(self):
self.assertEqual(normalize('[email protected]'), '[email protected]')
class GoogleNormalizerTests(unittest.TestCase):
def test_dots_remove(self):
self.assertEqual(normalize('[email protected]'), '[email protected]')
def test_extra(self):
self.assertEqual(normalize('[email protected]'), '[email protected]')
class MicrosoftNormalizerTests(unittest.TestCase):
def test_extra(self):
self.assertEqual(normalize('[email protected]'), '[email protected]')
class YahooNormalizerTests(unittest.TestCase):
def test_extra(self):
self.assertEqual(normalize('[email protected]'), '[email protected]')
class RamblerNormalizerTests(unittest.TestCase):
def test_extra(self):
self.assertEqual(normalize('[email protected]'), '[email protected]')
if __name__ == '__main__':
suite = unittest.TestSuite((
unittest.makeSuite(YandexNormalizerTests),
unittest.makeSuite(NormalizerTest),
unittest.makeSuite(FastMailNormalizerTests),
unittest.makeSuite(GoogleNormalizerTests),
unittest.makeSuite(MicrosoftNormalizerTests),
unittest.makeSuite(YahooNormalizerTests),
unittest.makeSuite(RamblerNormalizerTests),
))
result = unittest.TextTestRunner().run(suite)
sys.exit(not result.wasSuccessful())