forked from cybersecurity-team/TorBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_getemails.py
More file actions
57 lines (45 loc) · 1.28 KB
/
Copy pathtest_getemails.py
File metadata and controls
57 lines (45 loc) · 1.28 KB
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
"""
Test module for getemails
"""
from bs4 import BeautifulSoup
from yattag import Doc
from ..getemails import get_mails
def test_get_emails_fail():
"""
Test case for if website doesn't contain any email links
"""
doc, tag, _, line = Doc().ttl()
doc.asis('<!DOCTYPE html>')
with tag('html'):
with tag('body'):
line('a', 'test_anchor')
mock_html = doc.getvalue()
mock_soup = BeautifulSoup(mock_html, 'html.parser')
emails = get_mails(mock_soup)
assert emails == []
def test_get_emails():
"""
Test case for if website has multiple email links
"""
test_emails = ['hello@helloaddress.com',
'test@testemail.com',
'foo@bar.com',
'lol@me.biz']
doc, tag, _, line = Doc().ttl()
doc.asis('<!DOCTYPE html>')
with tag('html'):
with tag('body'):
for email in test_emails:
line('a', 'test_anchor', href=':'.join(('mailto', email)))
mock_html = doc.getvalue()
mock_soup = BeautifulSoup(mock_html, 'html.parser')
emails = get_mails(mock_soup)
assert emails == test_emails
def test_run():
"""
Execute test cases
"""
test_get_emails()
test_get_emails_fail()
if __name__ == '__main__':
test_run()