-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_emailVerifier.py
56 lines (35 loc) · 1.53 KB
/
test_emailVerifier.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
import unittest
from unittest import TestCase
import re
class emailVerifier():
def verifyemail(email):
try:
useremail = re.search(r'(.*)@(.*)\.(.*)', email, re.I)
useremailver1 = re.search(useremail.group(1), email, re.I)
removespecialchar = re.compile('[\[{}()\]\\\*]')
a = removespecialchar.sub('', useremail.group(1))
b = removespecialchar.sub('', useremail.group(2))
c = removespecialchar.sub('', useremail.group(3))
if not ((re.match(('[\[{}()\]\\\*]'), email))):
if (len(c) <= 3):
print(email, " is a valid email!")
loop4 = False
return True
else:
print(c, "is and invalid domain extention: it must be three letters or less.")
loop4 = False
return False
except:
print(email, "is not a valid email")
return False
class TestEmailVerifier(TestCase):
def test_verifyemail(self):
self.assertTrue(emailVerifier.verifyemail("[email protected]"))
def test_dext_toolong(self):
self.assertFalse(emailVerifier.verifyemail("[email protected]"))
def test_invchar(self):
self.assertFalse(emailVerifier.verifyemail("t[es)[email protected]"))
def test_all(self):
self.assertFalse(emailVerifier.verifyemail("t[es)t @ test.comm"))
if __name__ == 'main__':
unittest.main()