vigiboard / vigiboard / tests / functional / test_search_form_misc.py @ 0dcb87f7
History | View | Annotate | Download (5.62 KB)
1 |
# -*- coding: utf-8 -*-
|
---|---|
2 |
"""
|
3 |
Teste le formulaire de recherche avec divers champs.
|
4 |
"""
|
5 |
from pylons.i18n import ugettext as _ |
6 |
from nose.tools import assert_true, assert_equal |
7 |
from datetime import datetime |
8 |
import transaction |
9 |
|
10 |
from vigiboard.tests import TestController |
11 |
from vigilo.models.session import DBSession |
12 |
from vigilo.models.tables import SupItemGroup, Host, Permission, \ |
13 |
Event, CorrEvent, StateName, \ |
14 |
User, UserGroup, DataPermission |
15 |
from vigilo.models.tables.grouphierarchy import GroupHierarchy |
16 |
|
17 |
def insert_deps(): |
18 |
"""Insère les dépendances nécessaires aux tests."""
|
19 |
timestamp = datetime.now() |
20 |
|
21 |
host = Host( |
22 |
name=u'bar',
|
23 |
checkhostcmd=u'',
|
24 |
description=u'',
|
25 |
hosttpl=u'',
|
26 |
address=u'127.0.0.1',
|
27 |
snmpport=42,
|
28 |
snmpcommunity=u'public',
|
29 |
snmpversion=u'3',
|
30 |
weight=42,
|
31 |
) |
32 |
DBSession.add(host) |
33 |
DBSession.flush() |
34 |
|
35 |
hostgroup = SupItemGroup(name=u'foo')
|
36 |
hostgroup.supitems.append(host) |
37 |
DBSession.add(hostgroup) |
38 |
DBSession.flush() |
39 |
|
40 |
DBSession.add(GroupHierarchy( |
41 |
parent=hostgroup, |
42 |
child=hostgroup, |
43 |
hops=0,
|
44 |
)) |
45 |
DBSession.flush() |
46 |
|
47 |
event = Event( |
48 |
supitem=host, |
49 |
timestamp=timestamp, |
50 |
current_state=StateName.statename_to_value(u'WARNING'),
|
51 |
message=u'Hello world',
|
52 |
) |
53 |
DBSession.add(event) |
54 |
DBSession.flush() |
55 |
|
56 |
correvent = CorrEvent( |
57 |
impact=42,
|
58 |
priority=42,
|
59 |
trouble_ticket=u'FOO BAR BAZ',
|
60 |
status=u'None',
|
61 |
occurrence=42,
|
62 |
timestamp_active=timestamp, |
63 |
cause=event, |
64 |
) |
65 |
correvent.events.append(event) |
66 |
DBSession.add(correvent) |
67 |
DBSession.flush() |
68 |
|
69 |
# On donne l'accès aux données.
|
70 |
usergroup = UserGroup.by_group_name(u'users')
|
71 |
DBSession.add(DataPermission( |
72 |
group=hostgroup, |
73 |
usergroup=usergroup, |
74 |
access=u'r',
|
75 |
)) |
76 |
DBSession.flush() |
77 |
return timestamp
|
78 |
|
79 |
|
80 |
class TestSearchFormMisc(TestController): |
81 |
"""Teste la récupération d'événements selon le nom d'hôte."""
|
82 |
def setUp(self): |
83 |
super(TestSearchFormMisc, self).setUp() |
84 |
perm = Permission.by_permission_name(u'vigiboard-access')
|
85 |
user = User( |
86 |
user_name=u'user',
|
87 |
fullname=u'',
|
88 |
email=u'some.random@us.er',
|
89 |
) |
90 |
usergroup = UserGroup( |
91 |
group_name=u'users',
|
92 |
) |
93 |
user.usergroups.append(usergroup) |
94 |
usergroup.permissions.append(perm) |
95 |
DBSession.add(user) |
96 |
DBSession.add(usergroup) |
97 |
DBSession.flush() |
98 |
|
99 |
def test_search_by_output(self): |
100 |
"""Teste la recherche sur le message issu de Nagios."""
|
101 |
insert_deps() |
102 |
transaction.commit() |
103 |
|
104 |
# Permet également de vérifier que la recherche est
|
105 |
# insensible à la casse.
|
106 |
response = self.app.get('/?output=hello*', |
107 |
extra_environ={'REMOTE_USER': 'user'}) |
108 |
|
109 |
# Il doit y avoir 1 seule ligne de résultats.
|
110 |
rows = response.lxml.xpath('//table[@class="vigitable"]/tbody/tr')
|
111 |
print "There are %d rows in the result set" % len(rows) |
112 |
assert_equal(len(rows), 1) |
113 |
|
114 |
# Il doit y avoir plusieurs colonnes dans la ligne de résultats.
|
115 |
cols = response.lxml.xpath('//table[@class="vigitable"]/tbody/tr/td')
|
116 |
print "There are %d columns in the result set" % len(cols) |
117 |
assert_true(len(cols) > 1) |
118 |
|
119 |
def test_search_by_trouble_ticket(self): |
120 |
"""Teste la recherche sur le ticket d'incident."""
|
121 |
insert_deps() |
122 |
transaction.commit() |
123 |
|
124 |
# Permet également de vérifier que la recherche est
|
125 |
# insensible à la casse.
|
126 |
response = self.app.get('/?trouble_ticket=*bar*', |
127 |
extra_environ={'REMOTE_USER': 'user'}) |
128 |
transaction.commit() |
129 |
|
130 |
# Il doit y avoir 1 seule ligne de résultats.
|
131 |
rows = response.lxml.xpath('//table[@class="vigitable"]/tbody/tr')
|
132 |
print "There are %d rows in the result set" % len(rows) |
133 |
assert_equal(len(rows), 1) |
134 |
|
135 |
# Il doit y avoir plusieurs colonnes dans la ligne de résultats.
|
136 |
cols = response.lxml.xpath('//table[@class="vigitable"]/tbody/tr/td')
|
137 |
print "There are %d columns in the result set" % len(cols) |
138 |
assert_true(len(cols) > 1) |
139 |
|
140 |
def test_search_by_dates(self): |
141 |
"""Teste la recherche par dates."""
|
142 |
timestamp = insert_deps() |
143 |
transaction.commit() |
144 |
|
145 |
# Préparation des dates/heures.
|
146 |
# On réutilise le formattage attendu par le contrôleur
|
147 |
# (donc dépendant de la locale des tests, "fr" par défaut).
|
148 |
# TRANSLATORS: Format de date et heure.
|
149 |
from_date = timestamp.strftime(str(_("%Y-%m-%d %I:%M:%S %p"))) |
150 |
# TRANSLATORS: Format de date et heure.
|
151 |
to_date = datetime.max.strftime(str(_("%Y-%m-%d %I:%M:%S %p"))) |
152 |
|
153 |
# Permet également de vérifier que la recherche
|
154 |
# par date est inclusive.
|
155 |
response = self.app.get(
|
156 |
'/?from_date=%(from_date)s&to_date=%(to_date)s' % {
|
157 |
'from_date': from_date,
|
158 |
'to_date': to_date,
|
159 |
}, |
160 |
extra_environ={'REMOTE_USER': 'user'}) |
161 |
transaction.commit() |
162 |
|
163 |
# Il doit y avoir 1 seule ligne de résultats.
|
164 |
rows = response.lxml.xpath('//table[@class="vigitable"]/tbody/tr')
|
165 |
print "There are %d rows in the result set" % len(rows) |
166 |
assert_equal(len(rows), 1) |
167 |
|
168 |
# Il doit y avoir plusieurs colonnes dans la ligne de résultats.
|
169 |
cols = response.lxml.xpath('//table[@class="vigitable"]/tbody/tr/td')
|
170 |
print "There are %d columns in the result set" % len(cols) |
171 |
assert_true(len(cols) > 1) |
172 |
|