Revision dbbb7938
Remise en forme du test + passage systématique de "last_modification" au contrôleur.
Ceci en vue d'ajouter des validateurs sur la méthode /update.
Également, correction de typos ("ids" au lieu de "id").
git-svn-id: https://vigilo-dev.si.c-s.fr/svn@2420 b22e2e97-25c9-44ff-b637-2e5ceca36478
vigiboard/tests/functional/test_root.py | ||
---|---|---|
85 | 85 |
|
86 | 86 |
return ([host1, host2], [service1, service2]) |
87 | 87 |
|
88 |
def add_correvent_caused_by(supitem, |
|
88 |
def add_correvent_caused_by(supitem, timestamp,
|
|
89 | 89 |
correvent_status=u"None", event_status=u"WARNING"): |
90 | 90 |
""" |
91 | 91 |
Ajoute dans la base de données un évènement corrélé causé |
... | ... | |
106 | 106 |
# Ajout d'un événement corrélé |
107 | 107 |
aggregate = CorrEvent( |
108 | 108 |
idcause = event.idevent, |
109 |
timestamp_active = datetime.now(),
|
|
109 |
timestamp_active = timestamp,
|
|
110 | 110 |
priority = 1, |
111 | 111 |
status = correvent_status) |
112 | 112 |
aggregate.events.append(event) |
... | ... | |
133 | 133 |
(hosts, services) = populate_DB() |
134 | 134 |
|
135 | 135 |
# On ajoute 2 évènements corrélés causés par ces hôtes |
136 |
correvent1_id = add_correvent_caused_by(hosts[0])
|
|
137 |
correvent2_id = add_correvent_caused_by(hosts[1])
|
|
138 |
|
|
136 |
timestamp = datetime.now()
|
|
137 |
correvent1_id = add_correvent_caused_by(hosts[0], timestamp)
|
|
138 |
correvent2_id = add_correvent_caused_by(hosts[1], timestamp) |
|
139 | 139 |
transaction.commit() |
140 | 140 |
|
141 | 141 |
### 1er cas : L'utilisateur n'est pas connecté. |
142 | 142 |
# On vérifie que le plugin retourne bien une erreur 401. |
143 | 143 |
response = self.app.post( |
144 |
'/update', |
|
145 |
{"ids" : str(correvent1_id) + "," + str(correvent2_id), |
|
146 |
"ack" : u'NoChange', |
|
147 |
"trouble_ticket" : u"foo"}, |
|
148 |
status = 401) |
|
144 |
'/update', { |
|
145 |
"id" : str(correvent1_id) + "," + str(correvent2_id), |
|
146 |
"last_modification": mktime(timestamp.timetuple()), |
|
147 |
"trouble_ticket" : u"foo", |
|
148 |
"ack" : u'NoChange', |
|
149 |
}, status = 401) |
|
149 | 150 |
|
150 | 151 |
### 2ème cas : L'utilisateur utilisé pour |
151 | 152 |
# se connecter à Vigiboard est 'editor'. |
... | ... | |
155 | 156 |
# ce qu'un message d'erreur précise à l'utilisateur qu'il |
156 | 157 |
# n'a pas la permission de modifier ces évènements. |
157 | 158 |
response = self.app.post( |
158 |
'/update', |
|
159 |
{"id" : str(correvent1_id) + "," + str(correvent2_id), |
|
160 |
"ack" : u'NoChange', |
|
161 |
"trouble_ticket" : u"foo"}, |
|
162 |
status = 302, |
|
163 |
extra_environ = environ) |
|
164 |
|
|
165 |
response = response.follow( |
|
166 |
status=200, |
|
167 |
extra_environ = environ) |
|
159 |
'/update', { |
|
160 |
"id" : str(correvent1_id) + "," + str(correvent2_id), |
|
161 |
"ack" : u'NoChange', |
|
162 |
"trouble_ticket" : u"foo", |
|
163 |
"last_modification": mktime(timestamp.timetuple()), |
|
164 |
}, status = 302, extra_environ = environ) |
|
165 |
|
|
166 |
response = response.follow(status=200, extra_environ = environ) |
|
168 | 167 |
assert_true(response.lxml.xpath( |
169 | 168 |
'//div[@id="flash"]/div[@class="error"]')) |
170 | 169 |
|
... | ... | |
176 | 175 |
# et à ce qu'un message informe l'utilisateur que les |
177 | 176 |
# évènements corrélés sélectionnées ont bien été mis à jour. |
178 | 177 |
response = self.app.post( |
179 |
'/update', |
|
180 |
{"id" : str(correvent1_id) + "," + str(correvent2_id), |
|
181 |
"ack" : u'NoChange', |
|
182 |
"trouble_ticket" : u"foo"}, |
|
183 |
status = 302, |
|
184 |
extra_environ = environ) |
|
185 |
|
|
186 |
response = response.follow( |
|
187 |
status=200, |
|
188 |
extra_environ = environ) |
|
178 |
'/update', { |
|
179 |
"id" : str(correvent1_id) + "," + str(correvent2_id), |
|
180 |
"last_modification": mktime(timestamp.timetuple()), |
|
181 |
"trouble_ticket" : u"foo", |
|
182 |
"ack" : u'NoChange', |
|
183 |
}, status = 302, extra_environ = environ) |
|
184 |
|
|
185 |
response = response.follow(status=200, extra_environ = environ) |
|
189 | 186 |
assert_false(response.lxml.xpath( |
190 | 187 |
'//div[@id="flash"]/div[@class="error"]')) |
191 | 188 |
assert_true(response.lxml.xpath( |
... | ... | |
209 | 206 |
(hosts, services) = populate_DB() |
210 | 207 |
|
211 | 208 |
# On ajoute 2 évènements corrélés causés par ces hôtes |
212 |
correvent1_id = add_correvent_caused_by(services[0]) |
|
213 |
correvent2_id = add_correvent_caused_by(services[1]) |
|
209 |
timestamp = datetime.now() |
|
210 |
correvent1_id = add_correvent_caused_by(services[0], timestamp) |
|
211 |
correvent2_id = add_correvent_caused_by(services[1], timestamp) |
|
214 | 212 |
|
215 | 213 |
transaction.commit() |
216 | 214 |
|
217 | 215 |
### 1er cas : L'utilisateur n'est pas connecté. |
218 | 216 |
# On vérifie que le plugin retourne bien une erreur 401. |
219 | 217 |
response = self.app.post( |
220 |
'/update', |
|
221 |
{"ids" : str(correvent1_id) + "," + str(correvent2_id), |
|
222 |
"ack" : u'NoChange', |
|
223 |
"trouble_ticket" : u"foo"}, |
|
224 |
status = 401) |
|
218 |
'/update', { |
|
219 |
"id" : str(correvent1_id) + "," + str(correvent2_id), |
|
220 |
"last_modification": mktime(timestamp.timetuple()), |
|
221 |
"trouble_ticket" : u"foo", |
|
222 |
"ack" : u'NoChange', |
|
223 |
}, status = 401) |
|
225 | 224 |
|
226 | 225 |
### 2ème cas : L'utilisateur utilisé pour |
227 | 226 |
# se connecter à Vigiboard est 'editor'. |
... | ... | |
231 | 230 |
# ce qu'un message d'erreur précise à l'utilisateur qu'il |
232 | 231 |
# n'a pas la permission de modifier ces évènements. |
233 | 232 |
response = self.app.post( |
234 |
'/update', |
|
235 |
{"id" : str(correvent1_id) + "," + str(correvent2_id), |
|
236 |
"ack" : u'NoChange', |
|
237 |
"trouble_ticket" : u"foo"}, |
|
238 |
status = 302, |
|
239 |
extra_environ = environ) |
|
240 |
|
|
241 |
response = response.follow( |
|
242 |
status=200, |
|
243 |
extra_environ = environ) |
|
233 |
'/update', { |
|
234 |
"id" : str(correvent1_id) + "," + str(correvent2_id), |
|
235 |
"last_modification": mktime(timestamp.timetuple()), |
|
236 |
"trouble_ticket" : u"foo", |
|
237 |
"ack" : u'NoChange', |
|
238 |
}, status = 302, extra_environ = environ) |
|
239 |
|
|
240 |
response = response.follow(status=200, extra_environ = environ) |
|
244 | 241 |
assert_true(response.lxml.xpath( |
245 | 242 |
'//div[@id="flash"]/div[@class="error"]')) |
246 | 243 |
|
... | ... | |
252 | 249 |
# et à ce qu'un message informe l'utilisateur que les |
253 | 250 |
# évènements corrélés sélectionnées ont bien été mis à jour. |
254 | 251 |
response = self.app.post( |
255 |
'/update', |
|
256 |
{"id" : str(correvent1_id) + "," + str(correvent2_id), |
|
257 |
"ack" : u'NoChange', |
|
258 |
"trouble_ticket" : u"foo"}, |
|
259 |
status = 302, |
|
260 |
extra_environ = environ) |
|
261 |
|
|
262 |
response = response.follow( |
|
263 |
status=200, |
|
264 |
extra_environ = environ) |
|
252 |
'/update', { |
|
253 |
"id" : str(correvent1_id) + "," + str(correvent2_id), |
|
254 |
"last_modification": mktime(timestamp.timetuple()), |
|
255 |
"trouble_ticket" : u"foo", |
|
256 |
"ack" : u'NoChange', |
|
257 |
}, status = 302, extra_environ = environ) |
|
258 |
|
|
259 |
response = response.follow(status=200, extra_environ = environ) |
|
265 | 260 |
assert_false(response.lxml.xpath( |
266 | 261 |
'//div[@id="flash"]/div[@class="error"]')) |
267 | 262 |
assert_true(response.lxml.xpath( |
... | ... | |
284 | 279 |
(hosts, services) = populate_DB() |
285 | 280 |
|
286 | 281 |
# On ajoute 2 évènements corrélés causés par ces hôtes |
287 |
correvent1_id = add_correvent_caused_by(hosts[0])
|
|
288 |
correvent2_id = add_correvent_caused_by(hosts[1])
|
|
289 |
|
|
282 |
timestamp = datetime.now()
|
|
283 |
correvent1_id = add_correvent_caused_by(hosts[0], timestamp)
|
|
284 |
correvent2_id = add_correvent_caused_by(hosts[1], timestamp) |
|
290 | 285 |
transaction.commit() |
291 | 286 |
|
292 | 287 |
### 1er cas : L'utilisateur n'est pas connecté. |
293 | 288 |
# On vérifie que le plugin retourne bien une erreur 401. |
294 | 289 |
response = self.app.post( |
295 |
'/update', |
|
296 |
{"ids" : str(correvent1_id) + "," + str(correvent2_id), |
|
297 |
"ack" : u'Acknowledged', |
|
298 |
"trouble_ticket" : ""}, |
|
299 |
status = 401) |
|
290 |
'/update', { |
|
291 |
"id" : str(correvent1_id) + "," + str(correvent2_id), |
|
292 |
"last_modification": mktime(timestamp.timetuple()), |
|
293 |
"trouble_ticket" : "", |
|
294 |
"ack" : u'Acknowledged', |
|
295 |
}, status = 401) |
|
300 | 296 |
|
301 | 297 |
### 2ème cas : L'utilisateur utilisé pour |
302 | 298 |
# se connecter à Vigiboard est 'editor'. |
... | ... | |
306 | 302 |
# ce qu'un message d'erreur précise à l'utilisateur qu'il |
307 | 303 |
# n'a pas la permission de modifier ces évènements. |
308 | 304 |
response = self.app.post( |
309 |
'/update', |
|
310 |
{"id" : str(correvent1_id) + "," + str(correvent2_id), |
|
311 |
"ack" : u'Acknowledged', |
|
312 |
"trouble_ticket" : ""}, |
|
313 |
status = 302, |
|
314 |
extra_environ = environ) |
|
315 |
|
|
316 |
response = response.follow( |
|
317 |
status=200, |
|
318 |
extra_environ = environ) |
|
305 |
'/update', { |
|
306 |
"id" : str(correvent1_id) + "," + str(correvent2_id), |
|
307 |
"last_modification": mktime(timestamp.timetuple()), |
|
308 |
"trouble_ticket" : "", |
|
309 |
"ack" : u'Acknowledged', |
|
310 |
}, status = 302, extra_environ = environ) |
|
311 |
|
|
312 |
response = response.follow(status=200, extra_environ = environ) |
|
319 | 313 |
assert_true(response.lxml.xpath( |
320 | 314 |
'//div[@id="flash"]/div[@class="error"]')) |
321 | 315 |
|
... | ... | |
327 | 321 |
# et à ce qu'un message informe l'utilisateur que les |
328 | 322 |
# évènements corrélés sélectionnées ont bien été mis à jour. |
329 | 323 |
response = self.app.post( |
330 |
'/update', |
|
331 |
{"id" : str(correvent1_id) + "," + str(correvent2_id), |
|
332 |
"ack" : u'Acknowledged', |
|
333 |
"trouble_ticket" : ""}, |
|
334 |
status = 302, |
|
335 |
extra_environ = environ) |
|
336 |
|
|
337 |
response = response.follow( |
|
338 |
status=200, |
|
339 |
extra_environ = environ) |
|
324 |
'/update', { |
|
325 |
"id" : str(correvent1_id) + "," + str(correvent2_id), |
|
326 |
"last_modification": mktime(timestamp.timetuple()), |
|
327 |
"trouble_ticket" : "", |
|
328 |
"ack" : u'Acknowledged', |
|
329 |
}, status = 302, extra_environ = environ) |
|
330 |
|
|
331 |
response = response.follow(status=200, extra_environ = environ) |
|
340 | 332 |
assert_false(response.lxml.xpath( |
341 | 333 |
'//div[@id="flash"]/div[@class="error"]')) |
342 | 334 |
assert_true(response.lxml.xpath( |
... | ... | |
360 | 352 |
(hosts, services) = populate_DB() |
361 | 353 |
|
362 | 354 |
# On ajoute 2 évènements corrélés causés par ces hôtes |
363 |
correvent1_id = add_correvent_caused_by(services[0]) |
|
364 |
correvent2_id = add_correvent_caused_by(services[1]) |
|
355 |
timestamp = datetime.now() |
|
356 |
correvent1_id = add_correvent_caused_by(services[0], timestamp) |
|
357 |
correvent2_id = add_correvent_caused_by(services[1], timestamp) |
|
365 | 358 |
|
366 | 359 |
transaction.commit() |
367 | 360 |
|
368 | 361 |
### 1er cas : L'utilisateur n'est pas connecté. |
369 | 362 |
# On vérifie que le plugin retourne bien une erreur 401. |
370 | 363 |
response = self.app.post( |
371 |
'/update', |
|
372 |
{"ids" : str(correvent1_id) + "," + str(correvent2_id), |
|
373 |
"ack" : u'Acknowledged', |
|
374 |
"trouble_ticket" : ""}, |
|
375 |
status = 401) |
|
364 |
'/update', { |
|
365 |
"id" : str(correvent1_id) + "," + str(correvent2_id), |
|
366 |
"last_modification": mktime(timestamp.timetuple()), |
|
367 |
"trouble_ticket" : "", |
|
368 |
"ack" : u'Acknowledged', |
|
369 |
}, status = 401) |
|
376 | 370 |
|
377 | 371 |
### 2ème cas : L'utilisateur utilisé pour |
378 | 372 |
# se connecter à Vigiboard est 'editor'. |
... | ... | |
382 | 376 |
# ce qu'un message d'erreur précise à l'utilisateur qu'il |
383 | 377 |
# n'a pas la permission de modifier ces évènements. |
384 | 378 |
response = self.app.post( |
385 |
'/update', |
|
386 |
{"id" : str(correvent1_id) + "," + str(correvent2_id), |
|
387 |
"ack" : u'Acknowledged', |
|
388 |
"trouble_ticket" : ""}, |
|
389 |
status = 302, |
|
390 |
extra_environ = environ) |
|
391 |
|
|
392 |
response = response.follow( |
|
393 |
status=200, |
|
394 |
extra_environ = environ) |
|
379 |
'/update', { |
|
380 |
"id" : str(correvent1_id) + "," + str(correvent2_id), |
|
381 |
"last_modification": mktime(timestamp.timetuple()), |
|
382 |
"trouble_ticket" : "", |
|
383 |
"ack" : u'Acknowledged', |
|
384 |
}, status = 302, extra_environ = environ) |
|
385 |
|
|
386 |
response = response.follow(status=200, extra_environ = environ) |
|
395 | 387 |
assert_true(response.lxml.xpath( |
396 | 388 |
'//div[@id="flash"]/div[@class="error"]')) |
397 | 389 |
|
... | ... | |
403 | 395 |
# et à ce qu'un message informe l'utilisateur que les |
404 | 396 |
# évènements corrélés sélectionnées ont bien été mis à jour. |
405 | 397 |
response = self.app.post( |
406 |
'/update', |
|
407 |
{"id" : str(correvent1_id) + "," + str(correvent2_id), |
|
408 |
"ack" : u'Acknowledged', |
|
409 |
"trouble_ticket" : ""}, |
|
410 |
status = 302, |
|
411 |
extra_environ = environ) |
|
412 |
|
|
413 |
response = response.follow( |
|
414 |
status=200, |
|
415 |
extra_environ = environ) |
|
398 |
'/update', { |
|
399 |
"id" : str(correvent1_id) + "," + str(correvent2_id), |
|
400 |
"last_modification": mktime(timestamp.timetuple()), |
|
401 |
"trouble_ticket" : "", |
|
402 |
"ack" : u'Acknowledged', |
|
403 |
}, status = 302, extra_environ = environ) |
|
404 |
|
|
405 |
response = response.follow(status=200, extra_environ = environ) |
|
416 | 406 |
assert_false(response.lxml.xpath( |
417 | 407 |
'//div[@id="flash"]/div[@class="error"]')) |
418 | 408 |
assert_true(response.lxml.xpath( |
... | ... | |
435 | 425 |
(hosts, services) = populate_DB() |
436 | 426 |
|
437 | 427 |
# On ajoute 2 évènements corrélés causés par ces hôtes |
438 |
correvent1_id = add_correvent_caused_by(services[0]) |
|
439 |
correvent2_id = add_correvent_caused_by(services[1]) |
|
428 |
timestamp = datetime.now() |
|
429 |
correvent1_id = add_correvent_caused_by(services[0], timestamp) |
|
430 |
correvent2_id = add_correvent_caused_by(services[1], timestamp) |
|
440 | 431 |
|
441 | 432 |
# Date de modification du premier évènement corrélé |
442 | 433 |
later_date = datetime.now() |
... | ... | |
464 | 455 |
# à ce qu'un message d'erreur avise l'utilisateur que des |
465 | 456 |
# changements sont intervenus depuis le chargement de la page. |
466 | 457 |
response = self.app.post( |
467 |
'/update', |
|
468 |
{"id" : str(correvent1_id), |
|
469 |
"ack" : u'Acknowledged', |
|
470 |
"trouble_ticket" : "", |
|
471 |
"last_modification" : date}, |
|
472 |
status = 302, |
|
473 |
extra_environ = environ) |
|
474 |
|
|
475 |
response = response.follow( |
|
476 |
status=200, |
|
477 |
extra_environ = environ) |
|
458 |
'/update', { |
|
459 |
"id" : str(correvent1_id), |
|
460 |
"last_modification" : date, |
|
461 |
"trouble_ticket" : "", |
|
462 |
"ack" : u'Acknowledged', |
|
463 |
}, status = 302, extra_environ = environ) |
|
464 |
|
|
465 |
response = response.follow(status=200, extra_environ = environ) |
|
478 | 466 |
assert_true(response.lxml.xpath( |
479 | 467 |
'//div[@id="flash"]/div[@class="warning"]')) |
480 | 468 |
|
Also available in: Unified diff