-
Notifications
You must be signed in to change notification settings - Fork 197
Expand file tree
/
Copy pathutils_tests.py
More file actions
84 lines (72 loc) · 2.6 KB
/
Copy pathutils_tests.py
File metadata and controls
84 lines (72 loc) · 2.6 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
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
"""
SoftLayer.tests.utils_tests
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tests shared code
:license: MIT, see LICENSE for more details.
"""
from SoftLayer import testing
from SoftLayer import utils
TEST_FILTER = {
'virtualGuests': {
'provisionDate': {
'operation': 'orderBy',
'options': [
{'name': 'sort', 'value': ['DESC']},
{'name': 'sortOrder', 'value': [1]}
]
},
'maxMemory': {
'operation': 'orderBy',
'options': [
{'name': 'sort', 'value': ['ASC']},
{'name': 'sortOrder', 'value': [0]}
]
},
},
'hardware': {
'sparePoolBillingItem': {
'id': {'operation': 'not null'}
}
},
'someProperty': {
'provisionDate': {
'operation': '> sysdate - 30'
}
}
}
class TestUtils(testing.TestCase):
def test_find_key_simple(self):
"""Simple test case"""
test_dict = {"key1": "value1", "nested": {"key2": "value2", "key3": "value4"}}
result = utils.has_key_value(test_dict, "key2", "value2")
self.assertIsNotNone(result)
self.assertTrue(result)
def test_find_object_filter(self):
"""Find first orderBy operation in a real-ish object filter"""
result = utils.has_key_value(TEST_FILTER)
self.assertIsNotNone(result)
self.assertTrue(result)
def test_not_found(self):
"""Nothing to be found"""
test_dict = {"key1": "value1", "nested": {"key2": "value2", "key3": "value4"}}
result = utils.has_key_value(test_dict, "key23", "value2")
self.assertFalse(result)
def test_fix_filter(self):
original_filter = {}
fixed_filter = utils.fix_filter(original_filter)
self.assertIsNotNone(fixed_filter)
self.assertEqual(fixed_filter.get('id'), utils.query_filter_orderby())
# testing to make sure original doesn't get changed by the function call
self.assertIsNone(original_filter.get('id'))
def test_billing_filter(self):
billing_filter = {
'allTopLevelBillingItems': {
'cancellationDate': {'operation': 'is null'},
'id': {'operation': 'orderBy', 'options': [{'name': 'sort', 'value': ['ASC']}]}
}
}
fixed_filter = utils.fix_filter(billing_filter)
# Make sure we didn't add any more items
self.assertEqual(len(fixed_filter), 1)
self.assertEqual(len(fixed_filter.get('allTopLevelBillingItems')), 2)
self.assertDictEqual(fixed_filter, billing_filter)