vigiboard / vigiboard / tests / functional / test_correvents_table.py @ b373a5de
History | View | Annotate | Download (6.56 KB)
1 |
# -*- coding: utf-8 -*-
|
---|---|
2 |
# vim:set expandtab tabstop=4 shiftwidth=4:
|
3 |
# Copyright (C) 2006-2011 CS-SI
|
4 |
# License: GNU GPL v2 <http://www.gnu.org/licenses/gpl-2.0.html>
|
5 |
|
6 |
"""
|
7 |
Test du tableau d'événements de Vigiboard
|
8 |
"""
|
9 |
|
10 |
from nose.tools import assert_true, assert_equal |
11 |
from datetime import datetime |
12 |
import transaction |
13 |
|
14 |
from vigilo.models.session import DBSession |
15 |
from vigilo.models.tables import Event, CorrEvent, DataPermission, \ |
16 |
Permission, StateName, Host, SupItemGroup, \ |
17 |
LowLevelService, User, UserGroup, Permission |
18 |
from vigiboard.tests import TestController |
19 |
|
20 |
from utils import populate_DB |
21 |
|
22 |
class TestEventTable(TestController): |
23 |
"""
|
24 |
Test du tableau d'événements de Vigiboard
|
25 |
"""
|
26 |
def setUp(self): |
27 |
super(TestEventTable, self).setUp() |
28 |
populate_DB() |
29 |
|
30 |
def test_homepage(self): |
31 |
"""
|
32 |
Tableau des événements (page d'accueil).
|
33 |
"""
|
34 |
# L'utilisateur n'est pas authentifié.
|
35 |
response = self.app.get('/', status=401) |
36 |
|
37 |
# L'utilisateur est authentifié avec des permissions réduites.
|
38 |
environ = {'REMOTE_USER': 'limited_access'} |
39 |
response = self.app.get('/', extra_environ=environ) |
40 |
|
41 |
# Il doit y avoir 2 lignes de résultats.
|
42 |
rows = response.lxml.xpath('//table[@class="vigitable"]/tbody/tr')
|
43 |
print "There are %d rows in the result set" % len(rows) |
44 |
assert_equal(len(rows), 2) |
45 |
|
46 |
# Il doit y avoir plusieurs colonnes dans la ligne de résultats.
|
47 |
cols = response.lxml.xpath('//table[@class="vigitable"]/tbody/tr/td')
|
48 |
print "There are %d columns in the result set" % len(cols) |
49 |
assert_true(len(cols) > 1) |
50 |
|
51 |
# L'utilisateur est authentifié avec des permissions plus étendues.
|
52 |
environ = {'REMOTE_USER': 'access'} |
53 |
response = self.app.get('/', extra_environ=environ) |
54 |
|
55 |
# Il doit y avoir 5 lignes de résultats.
|
56 |
rows = response.lxml.xpath('//table[@class="vigitable"]/tbody/tr')
|
57 |
print "There are %d rows in the result set" % len(rows) |
58 |
assert_equal(len(rows), 5) |
59 |
|
60 |
# Il doit y avoir plusieurs colonnes dans la ligne de résultats.
|
61 |
cols = response.lxml.xpath('//table[@class="vigitable"]/tbody/tr/td')
|
62 |
print "There are %d columns in the result set" % len(cols) |
63 |
assert_true(len(cols) > 1) |
64 |
|
65 |
# L'utilisateur fait partie du groupe 'managers'
|
66 |
environ = {'REMOTE_USER': 'manager'} |
67 |
response = self.app.get('/', extra_environ=environ) |
68 |
|
69 |
# Il doit y avoir 5 lignes de résultats.
|
70 |
rows = response.lxml.xpath('//table[@class="vigitable"]/tbody/tr')
|
71 |
print "There are %d rows in the result set" % len(rows) |
72 |
assert_equal(len(rows), 5) |
73 |
|
74 |
# Il doit y avoir plusieurs colonnes dans la ligne de résultats.
|
75 |
cols = response.lxml.xpath('//table[@class="vigitable"]/tbody/tr/td')
|
76 |
print "There are %d columns in the result set" % len(cols) |
77 |
assert_true(len(cols) > 1) |
78 |
|
79 |
def test_correvents_table_for_LLS(self): |
80 |
"""
|
81 |
Tableau des événements corrélés pour un service de bas niveau.
|
82 |
"""
|
83 |
url = '/item/1/%s/%s' % ('group2_host', 'group2_service') |
84 |
|
85 |
# L'utilisateur n'est pas authentifié.
|
86 |
response = self.app.get(url, status=401) |
87 |
|
88 |
# L'utilisateur dispose de permissions restreintes.
|
89 |
# Il n'a pas accès aux événements corrélés sur le service donné.
|
90 |
# Donc, on s'attend à être redirigé avec un message d'erreur.
|
91 |
environ = {'REMOTE_USER': 'limited_access'} |
92 |
response = self.app.get(url, extra_environ=environ, status=302) |
93 |
response = response.follow(status = 200, extra_environ = environ)
|
94 |
assert_true(len(response.lxml.xpath(
|
95 |
'//div[@id="flash"]/div[@class="error"]')))
|
96 |
|
97 |
# L'utilisateur dispose de permissions plus étendues.
|
98 |
# Il doit avoir accès à l'historique.
|
99 |
# Ici, il n'y a qu'un seul événement corrélé pour ce service.
|
100 |
environ = {'REMOTE_USER': 'access'} |
101 |
response = self.app.get(url, extra_environ=environ, status=200) |
102 |
|
103 |
# Il doit y avoir 1 ligne de résultats.
|
104 |
rows = response.lxml.xpath('//table[@class="vigitable"]/tbody/tr')
|
105 |
print "There are %d rows in the result set" % len(rows) |
106 |
assert_equal(len(rows), 1) |
107 |
|
108 |
# L'utilisateur fait partie du groupe 'managers'
|
109 |
# Il doit avoir accès à l'historique.
|
110 |
# Ici, il n'y a qu'un seul événement corrélé pour ce service.
|
111 |
environ = {'REMOTE_USER': 'manager'} |
112 |
response = self.app.get(url, extra_environ=environ, status=200) |
113 |
|
114 |
# Il doit y avoir 1 ligne de résultats.
|
115 |
rows = response.lxml.xpath('//table[@class="vigitable"]/tbody/tr')
|
116 |
print "There are %d rows in the result set" % len(rows) |
117 |
assert_equal(len(rows), 1) |
118 |
|
119 |
def test_correvents_table_for_host(self): |
120 |
"""
|
121 |
Tableau des événements corrélés pour un hôte.
|
122 |
"""
|
123 |
url = '/item/1/%s/' % ('group2_host', ) |
124 |
|
125 |
# L'utilisateur n'est pas authentifié.
|
126 |
response = self.app.get(url, status=401) |
127 |
|
128 |
# L'utilisateur dispose de permissions restreintes.
|
129 |
# Il n'a pas accès aux événements corrélés sur le service donné.
|
130 |
# Donc, on s'attend à être redirigé avec un message d'erreur.
|
131 |
environ = {'REMOTE_USER': 'limited_access'} |
132 |
response = self.app.get(url, extra_environ=environ, status=302) |
133 |
response = response.follow(status = 200, extra_environ = environ)
|
134 |
assert_true(len(response.lxml.xpath(
|
135 |
'//div[@id="flash"]/div[@class="error"]')))
|
136 |
|
137 |
# L'utilisateur dispose de permissions plus étendues.
|
138 |
# Il doit avoir accès à l'historique.
|
139 |
# Ici, il n'y a qu'un seul événement corrélé pour ce service.
|
140 |
environ = {'REMOTE_USER': 'access'} |
141 |
response = self.app.get(url, extra_environ=environ, status=200) |
142 |
|
143 |
# Il doit y avoir 1 ligne de résultats.
|
144 |
rows = response.lxml.xpath('//table[@class="vigitable"]/tbody/tr')
|
145 |
print "There are %d rows in the result set" % len(rows) |
146 |
assert_equal(len(rows), 1) |
147 |
|
148 |
# L'utilisateur fait partie du groupe 'managers'.
|
149 |
# Il doit avoir accès à l'historique.
|
150 |
# Ici, il n'y a qu'un seul événement corrélé pour ce service.
|
151 |
environ = {'REMOTE_USER': 'manager'} |
152 |
response = self.app.get(url, extra_environ=environ, status=200) |
153 |
|
154 |
# Il doit y avoir 1 ligne de résultats.
|
155 |
rows = response.lxml.xpath('//table[@class="vigitable"]/tbody/tr')
|
156 |
print "There are %d rows in the result set" % len(rows) |
157 |
assert_equal(len(rows), 1) |