This repository has been archived by the owner on Aug 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
tests.py
154 lines (138 loc) · 6.55 KB
/
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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import saltobserver
import unittest
from redis import Redis
from scripts.generate_return_data import ReturnDataGenerator
class SaltobserverTestCase(unittest.TestCase):
redis = Redis(connection_pool=saltobserver.redis_pool)
rdg = ReturnDataGenerator(redis=Redis(connection_pool=saltobserver.redis_pool), minion_list=['some.minion.example.com', 'someother.minion.example.com'])
def setUp(self):
saltobserver.app.config['TESTING'] = True
self.redis.flushall()
self.app = saltobserver.app.test_client()
def tearDown(self):
# self.redis.flushall()
pass
def test_index_redirect(self):
rv = self.app.get('/', follow_redirects=True)
assert rv.status_code == 200
assert '<title>Salt Observer: state.highstate</title>' in rv.data
def test_searches(self):
# function search
rv = self.app.get('/functions/')
assert rv.status_code == 200
assert '<title>Salt Observer: Search Functions</title>' in rv.data
rv = self.app.get('/functions/?function=state.highstate')
assert rv.location == "http://localhost/functions/state.highstate/"
# job search
rv = self.app.get('/jobs/')
assert rv.status_code == 200
assert '<title>Salt Observer: Search Jobs</title>' in rv.data
rv = self.app.get('/jobs/?jid=12345')
assert rv.location == "http://localhost/jobs/12345/"
# history search
rv = self.app.get('/history/')
assert rv.status_code == 200
assert '<title>Salt Observer: Search History</title>' in rv.data
rv = self.app.get('/history/?minion=some.minion.example.com&function=test.ping')
assert rv.location == "http://localhost/history/some.minion.example.com/test.ping/"
def test_empty_function(self):
rv = self.app.get('/functions/state.highstate/')
assert '''<h1>0</h1>
<div class="count-title">
...Minions have run this function.
</div>''' in rv.data
def test_empty_job(self):
rv = self.app.get('/jobs/12345/')
assert '''<h1>0</h1>
<div class="count-title">
...Minions have run this job.
</div>''' in rv.data
def test_empty_history(self):
rv = self.app.get('/history/some.minion.example.com/state.highstate/')
assert '''<h1>0</h1>
<div class="count-title">
jobs for some.minion.example.com
</div>''' in rv.data
def test_count_function(self):
self.rdg.generate(fun="state.highstate")
rv = self.app.get('/functions/state.highstate/')
assert '''<h1>2</h1>
<div class="count-title">
...Minions have run this function.
</div>''' in rv.data
assert '''<h1>2</h1>
<div class="count-title">
...of them successfully.
</div>''' in rv.data
self.rdg.generate(fun="state.highstate", fail=True)
rv = self.app.get('/functions/state.highstate/')
assert '''<h1>2</h1>
<div class="count-title">
...Minions have run this function.
</div>''' in rv.data
assert '''<h1>0</h1>
<div class="count-title">
...of them successfully.
</div>''' in rv.data
# cover the case where a minion has never run the particular function
ReturnDataGenerator(redis=Redis(connection_pool=saltobserver.redis_pool), minion_list=["onemore.minion.example.com"]).generate(jid="20150118142103074916", fun="test.ping")
rv = self.app.get('/functions/state.highstate/')
assert '''<h1>2</h1>
<div class="count-title">
...Minions have run this function.
</div>''' in rv.data
# cover the case where a jid is omitted because it's no valid timestamp
self.rdg.generate(jid="1234", fun="state.highstate")
rv = self.app.get('/functions/state.highstate/')
assert '''<h1>0</h1>
<div class="count-title">
...Minions have run this function.
</div>''' in rv.data
def test_count_job(self):
self.rdg.generate(jid="20150118142103074916", fun="state.highstate")
rv = self.app.get('/jobs/20150118142103074916/')
assert '''<h1>2</h1>
<div class="count-title">
...Minions have run this job.
</div>''' in rv.data
ReturnDataGenerator(redis=Redis(connection_pool=saltobserver.redis_pool), minion_list=["onemore.minion.example.com"]).generate(jid="20150118142103074916", fun="state.highstate")
rv = self.app.get('/jobs/20150118142103074916/')
assert '''<h1>3</h1>
<div class="count-title">
...Minions have run this job.
</div>''' in rv.data
# cover the case where the jid does not parse as a timestamp
self.rdg.generate(jid="12347", fun="test.ping")
rv = self.app.get('/jobs/12347/')
assert '''<h1>2</h1>
<div class="count-title">
...Minions have run this job.
</div>''' in rv.data
def test_count_history(self):
self.rdg.generate(fun="state.highstate")
self.rdg.generate(fun="test.ping")
rv = self.app.get('/history/some.minion.example.com/state.highstate/')
assert '''<h1>1</h1>
<div class="count-title">
job for some.minion.example.com
</div>''' in rv.data
self.rdg.generate(fun="state.highstate")
rv = self.app.get('/history/some.minion.example.com/state.highstate/')
assert '''<h1>2</h1>
<div class="count-title">
jobs for some.minion.example.com
</div>''' in rv.data
# test with a faked jid, which causes time.strptime parsing to fail in views.py
self.rdg.generate(jid="12345", fun="state.highstate")
rv = self.app.get('/history/some.minion.example.com/state.highstate/')
assert '''<h1>2</h1>
<div class="count-title">
jobs for some.minion.example.com
</div>''' in rv.data
def test_get_data(self):
self.rdg.generate(jid="12345", fun="state.highstate")
rv = self.app.get('/_get_function_data/some.minion.example.com/12345/')
assert rv.mimetype == "application/json"
assert '"id": "some.minion.example.com"' in rv.data
if __name__ == '__main__':
unittest.main()