-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_filter.py
executable file
·89 lines (77 loc) · 2.35 KB
/
test_filter.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
#!/usr/bin/env python
import unittest
from mcollective import Filter
class TestFilter(unittest.TestCase):
def test_init(self):
f = Filter()
self.assertEqual(f.cf_class, '')
self.assertEqual(f.agent, '')
self.assertEqual(f.identity, '')
self.assertEqual(f.fact, [])
def test_cf_class(self):
f = Filter(cf_class='foo::bar')
self.assertEqual(f.cf_class, 'foo::bar')
self.assertEqual(
f.dump()['cf_class'],
['foo::bar'],
)
def test_agent(self):
f = Filter(agent='smith')
self.assertEqual(f.agent, 'smith')
self.assertEqual(
f.dump()['agent'],
['smith'],
)
def test_identity(self):
f = Filter(identity='the.bourne')
self.assertEqual(f.identity, 'the.bourne')
self.assertEqual(
f.dump()['identity'],
['the.bourne'],
)
def test_fact(self):
f = Filter()
f.add_fact('country', 'uk')
self.assertEqual(f.fact, [{':fact' : 'country', ':value' : 'uk'}])
self.assertEqual(
f.dump()['fact'],
[{':fact' : 'country', ':value' : 'uk'}],
)
def test_add_multiple_facts(self):
f = Filter()
f.add_fact('country', 'us')
f.add_fact('processorcount', '4')
self.assertEqual(f.fact,[
{':fact' : 'country', ':value' : 'us'},
{':fact' : 'processorcount', ':value' : '4'},
])
self.assertEqual(f.dump()['fact'], f.fact)
def test_empty_dump(self):
f = Filter()
d = f.dump()
self.assertEqual(d, {
'cf_class' : [],
'agent' : [],
'identity' : [],
'fact' : [],
})
def test_full_dump(self):
f = Filter(
cf_class='foo::bar',
agent='smith',
identity='the.bourne',
)
f.add_fact('country', 'uk')
f.add_fact('processorcount', '4')
d = f.dump()
self.assertEqual(d, {
'cf_class' : ['foo::bar'],
'agent' : ['smith'],
'identity' : ['the.bourne'],
'fact' : [
{':fact' : 'country', ':value' : 'uk'},
{':fact' : 'processorcount', ':value' : '4'},
],
})
if __name__ == '__main__':
unittest.main()