-
Notifications
You must be signed in to change notification settings - Fork 19
/
test.py
102 lines (72 loc) · 3.17 KB
/
test.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
# -*- coding: utf-8 -*-
import unittest
from emailahoy import VerifyEmail
from emailahoy import query_mx
from emailahoy import verify_email_address
import sys
import logging
class TestEmailVerificationFunctions(unittest.TestCase):
def setUp(self):
""" Instantiate the class """
self.e = VerifyEmail()
self.log= logging.getLogger( "TestEmailVerificationFunctions" )
def test_class_based_invalid_email(self):
""" Test the existence of an invalid email address (class based)"""
email = 'non-existing-email@cnn.com'
self.log.debug("Testing classy invalid email address (%s)" % email)
status = self.e.verify(
email=email,
from_host='neekware.com',
from_email='info@neekware.com'
)
self.log.debug(status)
self.assertEquals(self.e.EMAIL_NOT_FOUND, status)
def test_class_based_valid_email(self):
""" Test the existence of a valid email address (class based)"""
email = 'vinnie@cnn.com'
self.log.debug("Testing classy valid email address (%s)" % email)
status = self.e.verify(
email=email,
from_host='neekware.com',
from_email='info@neekware.com'
)
self.log.debug(status)
self.assertEquals(self.e.EMAIL_FOUND, status)
def test_function_based_invalid_email(self):
""" Test the existence of an invalid email address (function based)"""
email = 'non-existing-email@cnn.com'
self.log.debug("Testing invalid email address (%s)" % email)
found = verify_email_address(
email=email,
from_host='neekware.com',
from_email='info@neekware.com'
)
# email doesn't exists
self.assertEquals(found, False)
def test_function_based_valid_email(self):
""" Test the existence of a valid email address (function based)"""
email = 'vinnie@cnn.com'
self.log.debug("Testing valid email address (%s)" % email)
found = verify_email_address(
email=email,
from_host='neekware.com',
from_email='info@neekware.com'
)
# email exists
self.assertEquals(found, True)
def test_mx_query_invalid_domain(self):
""" Query mx of an invalid domain name """
domain = 'invalid_domain_address.com'
self.log.debug("Testing MX Query for invalid domain (%s)" % domain)
mx = query_mx(domain)
self.assertEquals(len(mx), 0)
def test_mx_query_valid_domain(self):
""" Query mx of a valid domain name """
domain = 'cnn.com'
self.log.debug("Testing MX Query for valid domain (%s)" % domain)
mx = query_mx(domain)
self.assertNotEqual(len(mx), 0)
if __name__ == '__main__':
logging.basicConfig( stream=sys.stderr )
logging.getLogger( "TestEmailVerificationFunctions" ).setLevel( logging.DEBUG )
unittest.main()