-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollectdflask_tests.py
executable file
·92 lines (76 loc) · 2.34 KB
/
collectdflask_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
#!/usr/bin/env python
try:
import unittest2 as unittest
except ImportError:
import unittest
import collectdflask
from lxml import etree
import os
TEST_DATA_DIR = os.path.join(os.path.dirname(__file__), 'test_data')
collectdflask.app.config['COLLECTD_DATA_DIR'] = TEST_DATA_DIR
class TestDataDirParsing(unittest.TestCase):
def setUp(self):
self.app = collectdflask.app.test_client()
def test_get_hosts(self):
hosts = collectdflask.get_hosts()
self.assertEqual(
hosts,
['host1', 'host2', 'host3'],
)
def test_get_hosts_wildcard(self):
hosts = collectdflask.get_hosts('*')
self.assertEqual(
hosts,
['host1', 'host2', 'host3'],
)
def test_get_host_pattern(self):
hosts = collectdflask.get_hosts('*1')
self.assertEqual(
hosts,
['host1'],
)
def test_get_plugins_for_host(self):
plugins = collectdflask.get_plugins_for_host('host1')
self.assertEqual(
plugins,
['plugin1'],
)
def test_get_plugins_for_host_pattern(self):
plugins = collectdflask.get_plugins_for_host('host3', '*3')
self.assertEqual(
plugins,
['plugin3'],
)
def test_get_plugins_for_host_wildcard(self):
plugins = collectdflask.get_plugins_for_host('host3', '*')
self.assertEqual(
plugins,
['plugin1', 'plugin2', 'plugin3'],
)
def test_multi_instance_plugin(self):
plugins = collectdflask.get_plugins_for_host('host2')
self.assertEqual(
plugins,
['multi', 'plugin1', 'plugin2'],
)
class TestViews(unittest.TestCase):
def setUp(self):
self.app = collectdflask.app.test_client()
def test_index(self):
response = self.app.get('/')
tree = etree.fromstring(response.data)
ul = tree.findall('.//ul/li')
result = {}
for entry in ul:
links = entry.findall('.//a')
result[links[0].text] = [a.text for a in links[1:]]
self.assertEqual(
result,
{
'host1' : ['plugin1'],
'host2' : ['multi', 'plugin1', 'plugin2'],
'host3' : ['plugin1', 'plugin2', 'plugin3'],
},
)
if __name__ == '__main__':
unittest.main()