-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_key_collector.py
130 lines (105 loc) · 6.06 KB
/
test_key_collector.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
from mock import patch
import isi_sdk_7_2
import unittest
import stat_key_browser.key_collector as key_collector
class TestKeyCollector(unittest.TestCase):
def test_key_list_to_dict(self):
as_list = [{'key': 'keyname', 'data': 'stuff'}]
as_dict = key_collector._key_list_to_dict(as_list)
assert(as_dict['keyname'] == {'key': 'keyname', 'data': 'stuff'})
def test_squash_keys_1(self):
keys = {'a.a': {}, 'a.b': {}, 'a.1': {}, 'a.2': {}, 'c.1.a': {}}
expected = {'a.a': {}, 'a.b': {}, 'a.N': {}, 'c.1.a': {}}
results = key_collector._squash_keys(keys)
assert(results == expected)
def test_squash_keys_2(self):
keys = {'a.a': {}, 'a.b': {}, 'a.1': {}, 'a.2': {}, 'c.1.a': {},
'a.4': {}, 'a.9999999': {}}
expected = {'a.a': {}, 'a.b': {}, 'a.N': {}, 'c.1.a': {}}
results = key_collector._squash_keys(keys)
assert(results == expected)
def test_squash_keys_desc_1(self):
keys = {'a.a': {}, 'a.1': {'key': 'a.1', 'description': 'index 1'}, 'a.2': {'key': 'a.2', 'description': 'index 2'}}
expected = {'a.a': {}, 'a.N': {'key': 'a.N', 'description': 'index N'}}
results = key_collector._squash_keys(keys)
assert(results == expected)
def test_get_indexed_key_names(self):
keys = {'a.a': {}, 'a.b': {}, 'a.1': {}, 'a.2': {}, 'c.1.a': {}}
expected = ['a.1', 'a.2']
results = key_collector._get_indexed_key_names(keys)
assert(results.sort() == expected.sort())
def test_basename_1(self):
assert('a.b.c' == key_collector._basename('a.b.c.1'))
def test_basename_2(self):
assert('a.b' == key_collector._basename('a.b.c'))
def test_basename_3(self):
assert('a' == key_collector._basename('a.b'))
def test_basename_4(self):
assert('' == key_collector._basename('a'))
def test_basename_5(self):
assert('a!,___' == key_collector._basename('a!,___.!!$#'))
def test_squash_description_1(self):
desc = 'Input transfers per second for disk with index 10'
expected = 'Input transfers per second for disk with index N'
results = key_collector._squash_description(desc)
assert(results == expected)
def test_squash_description_2(self):
desc = 'Input errors per second for interface 15'
expected = 'Input errors per second for interface N'
results = key_collector._squash_description(desc)
assert(results == expected)
def test_squash_description_3(self):
desc = 'no: of read accesses in bin 4 44'
expected = 'no: of read accesses in bin 4 N'
results = key_collector._squash_description(desc)
assert(results == expected)
def test_squash_description_4(self):
desc = 'Reading in Celsius of temperature sensor number 25'
expected = 'Reading in Celsius of temperature sensor number N'
results = key_collector._squash_description(desc)
assert(results == expected)
def test_squash_description_5(self):
desc = 'missing stat'
expected = 'missing stat'
results = key_collector._squash_description(desc)
assert(results == expected)
def test_squash_description_6(self):
desc = 'True if interface number 10 is internal'
expected = 'True if interface number N is internal'
results = key_collector._squash_description(desc)
assert(results == expected)
def test_squash_description_7(self):
desc = 'Status of battery with index 1. 0 = Unknown, 1 = Unable to communicate with battery charger, 2 = Charger unable to operate, 3 = Battery pack disconnected, 4 = Charge paused due to temperature error, 5 = Charge C/10 paused due to temperature error, 6 = Good, 7 = Battery unable to accept charge, 8 = Battery charging normally, 9 = Good, 10 = Good, 11 = Battery charge circuit shutdown, 12 = Good, 13 = Battery tray removed, 14 = Battery failed, 15 = Battery overcharged'
expected = 'Status of battery with index N. 0 = Unknown, 1 = Unable to communicate with battery charger, 2 = Charger unable to operate, 3 = Battery pack disconnected, 4 = Charge paused due to temperature error, 5 = Charge C/10 paused due to temperature error, 6 = Good, 7 = Battery unable to accept charge, 8 = Battery charging normally, 9 = Good, 10 = Good, 11 = Battery charge circuit shutdown, 12 = Good, 13 = Battery tray removed, 14 = Battery failed, 15 = Battery overcharged'
results = key_collector._squash_description(desc)
assert(results == expected)
def test_deabbreviate_1(self):
key_dict = {'a': {'aggregation_type': 'avg'}}
key_collector.deabbreviate(key_dict)
self.assertEqual('average', key_dict['a']['aggregation_type'])
def test_deabbreviate_2(self):
key_dict = {'a': {'aggregation_type': 'max'}}
key_collector.deabbreviate(key_dict)
self.assertEqual('maximum', key_dict['a']['aggregation_type'])
def test_deabbreviate_3(self):
key_dict = {'a': {'key': 'max'}}
key_collector.deabbreviate(key_dict)
self.assertEqual('max', key_dict['a']['key'])
@patch('stat_key_browser.key_collector._get_key_list')
def test_get_key_dict_1(self, mock_method):
mock_method.return_value = [{'key': 'a.a'}]
result = key_collector._get_key_dict('testing123', 'user1', 'pass1')
assert 'a.a' in result
mock_method.assert_called_with('testing123', 'user1', 'pass1')
@patch.object(isi_sdk_7_2, 'ApiClient')
def test_get_key_list_1(self, mock_method):
key_collector._get_key_list('testing123', 'user', 'pass')
mock_method.assert_called_with('https://testing123:8080')
@patch('stat_key_browser.key_collector._get_key_dict')
def test_get_tagged_squashed(self, mock_method):
mock_method.return_value = {'a.a': {}, 'a.b': {}}
results = key_collector.get_tagged_squashed_dict('testing123', 'user1',
'pass1')
assert 'a.a' in results
assert 'a.b' in results
mock_method.assert_called_with('testing123', 'user1', 'pass1')