forked from DedSecInside/TorBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_analyzer.py
More file actions
48 lines (39 loc) · 1.3 KB
/
Copy pathtest_analyzer.py
File metadata and controls
48 lines (39 loc) · 1.3 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
import pytest
import requests_mock
from yattag import Doc
from ..analyzer import LinkTree
from ..link import LinkNode
def create_page(name):
doc, tag, _, line = Doc().ttl()
doc.asis('<!DOCTYPE html>')
with tag('html'):
line('title', name)
with tag('body'):
line('h1', 'Something')
return doc.getvalue()
def create_root_page_with_links(root, links):
doc, tag, _, line = Doc().ttl()
doc.asis('<!DOCTYPE html>')
with tag('html'):
line('title', root)
with tag('body'):
for link in links:
line('a', 'test', href=link)
return doc.getvalue()
@pytest.fixture
def test_links_in_tree():
links = ['http://dog.onion', 'http://cat.onion', 'http://foo.cnion']
with requests_mock.Mocker() as mock_connection:
root_page = create_root_page_with_links('http://root.onion', links)
for link in links:
page = create_page(link)
mock_connection.register_uri('GET', link, text=page)
mock_connection.register_uri('GET', 'http://root.onion', text=root_page)
node = LinkNode('http://root.onion')
tree = LinkTree(node)
for link in links:
assert link in tree
def test_run():
test_links_in_tree()
if __name__ == '__main__':
test_run()