vigiboard / vigiboard / tests / functional / test_search_form_hostgroup.py @ 5dbfa80d
History | View | Annotate | Download (5.35 KB)
1 | 64ed9170 | Vincent QUEMENER | # -*- coding: utf-8 -*-
|
---|---|---|---|
2 | """
|
||
3 | Teste le formulaire de recherche avec un groupe d'hôtes.
|
||
4 | """
|
||
5 | from nose.tools import assert_true, assert_equal |
||
6 | from datetime import datetime |
||
7 | import transaction |
||
8 | |||
9 | from vigiboard.tests import TestController |
||
10 | 5dbfa80d | Francois POIROTTE | from vigilo.models.configure import DBSession |
11 | 7365fb51 | Francois POIROTTE | from vigilo.models import HostGroup, Host, Permission, \ |
12 | 6ab72614 | Vincent QUEMENER | Event, CorrEvent, StateName |
13 | 64ed9170 | Vincent QUEMENER | |
14 | def insert_deps(): |
||
15 | """Insère les dépendances nécessaires aux tests."""
|
||
16 | timestamp = datetime.now() |
||
17 | DBSession.add(StateName(statename=u'OK', order=1)) |
||
18 | DBSession.add(StateName(statename=u'UNKNOWN', order=1)) |
||
19 | DBSession.add(StateName(statename=u'WARNING', order=1)) |
||
20 | DBSession.add(StateName(statename=u'CRITICAL', order=1)) |
||
21 | DBSession.flush() |
||
22 | |||
23 | hostgroup = HostGroup( |
||
24 | name=u'foo',
|
||
25 | ) |
||
26 | DBSession.add(hostgroup) |
||
27 | DBSession.flush() |
||
28 | |||
29 | host = Host( |
||
30 | name=u'bar',
|
||
31 | checkhostcmd=u'',
|
||
32 | description=u'',
|
||
33 | hosttpl=u'',
|
||
34 | mainip=u'127.0.0.1',
|
||
35 | snmpport=42,
|
||
36 | snmpcommunity=u'public',
|
||
37 | snmpversion=u'3',
|
||
38 | weight=42,
|
||
39 | ) |
||
40 | DBSession.add(host) |
||
41 | DBSession.flush() |
||
42 | |||
43 | hostgroup.hosts.append(host) |
||
44 | DBSession.flush() |
||
45 | |||
46 | event = Event( |
||
47 | supitem=host, |
||
48 | timestamp=timestamp, |
||
49 | current_state=StateName.statename_to_value(u'WARNING'),
|
||
50 | message=u'Hello world',
|
||
51 | ) |
||
52 | DBSession.add(event) |
||
53 | DBSession.flush() |
||
54 | |||
55 | correvent = CorrEvent( |
||
56 | impact=42,
|
||
57 | priority=42,
|
||
58 | trouble_ticket=None,
|
||
59 | status=u'None',
|
||
60 | occurrence=42,
|
||
61 | timestamp_active=timestamp, |
||
62 | cause=event, |
||
63 | ) |
||
64 | correvent.events.append(event) |
||
65 | DBSession.add(correvent) |
||
66 | DBSession.flush() |
||
67 | return hostgroup
|
||
68 | |||
69 | class TestSearchFormHostGroup(TestController): |
||
70 | """Teste la récupération d'événements selon le groupe d'hôtes."""
|
||
71 | |||
72 | def test_search_hostgroup_when_allowed(self): |
||
73 | """Teste la recherche par hostgroup avec les bons droits d'accès."""
|
||
74 | # On crée un groupe d'hôte appelé 'foo',
|
||
75 | # contenant un hôte 'bar', ainsi qu'un événement
|
||
76 | # et un événement corrélé sur cet hôte.
|
||
77 | # De plus, on donne l'autorisation aux utilisateurs
|
||
78 | # ayant la permission 'manage' de voir cette alerte.
|
||
79 | hostgroup = insert_deps() |
||
80 | manage = Permission.by_permission_name(u'manage')
|
||
81 | manage.hostgroups.append(hostgroup) |
||
82 | DBSession.flush() |
||
83 | transaction.commit() |
||
84 | |||
85 | # On envoie une requête avec recherche sur le groupe d'hôtes créé,
|
||
86 | # on s'attend à recevoir 1 résultat.
|
||
87 | response = self.app.get('/?hostgroup=foo', |
||
88 | extra_environ={'REMOTE_USER': 'manager'}) |
||
89 | |||
90 | # Il doit y avoir 1 seule ligne de résultats.
|
||
91 | rows = response.lxml.xpath('//table[@class="vigitable"]/tbody/tr')
|
||
92 | print "There are %d rows in the result set" % len(rows) |
||
93 | assert_equal(len(rows), 1) |
||
94 | |||
95 | # Il doit y avoir plusieurs colonnes dans la ligne de résultats.
|
||
96 | cols = response.lxml.xpath('//table[@class="vigitable"]/tbody/tr/td')
|
||
97 | print "There are %d columns in the result set" % len(cols) |
||
98 | assert_true(len(cols) > 1) |
||
99 | |||
100 | def test_search_inexistent_hostgroup(self): |
||
101 | """Teste la recherche par hostgroup sur un groupe inexistant."""
|
||
102 | # On envoie une requête avec recherche sur un groupe d'hôtes
|
||
103 | # qui n'existe pas, on s'attend à n'obtenir aucun résultat.
|
||
104 | response = self.app.get('/?hostgroup=foot', |
||
105 | extra_environ={'REMOTE_USER': 'manager'}) |
||
106 | |||
107 | # Il doit y avoir 1 seule ligne de résultats.
|
||
108 | rows = response.lxml.xpath('//table[@class="vigitable"]/tbody/tr')
|
||
109 | print "There are %d rows in the result set" % len(rows) |
||
110 | assert_equal(len(rows), 1) |
||
111 | |||
112 | # Il doit y avoir 1 seule colonne dans la ligne de résultats.
|
||
113 | # (la colonne contient le texte "Il n'y a aucun événément", traduit)
|
||
114 | cols = response.lxml.xpath('//table[@class="vigitable"]/tbody/tr/td')
|
||
115 | print "There are %d columns in the result set" % len(cols) |
||
116 | assert_equal(len(cols), 1) |
||
117 | |||
118 | def test_search_hostgroup_when_disallowed(self): |
||
119 | """Teste la recherche par hostgroup SANS les droits d'accès."""
|
||
120 | # On crée un groupe d'hôte appelé 'foo',
|
||
121 | # contenant un hôte 'bar', ainsi qu'un événement
|
||
122 | # et un événement corrélé sur cet hôte.
|
||
123 | # MAIS, on NE DONNE PAS l'autorisation aux utilisateurs
|
||
124 | # de voir cette alerte, donc elle ne doit jamais apparaître.
|
||
125 | insert_deps() |
||
126 | transaction.commit() |
||
127 | |||
128 | # On envoie une requête avec recherche sur le groupe d'hôtes créé,
|
||
129 | # mais avec un utilisateur ne disposant pas des permissions adéquates.
|
||
130 | # On s'attend à n'obtenir aucun résultat.
|
||
131 | response = self.app.get('/?hostgroup=foo', |
||
132 | extra_environ={'REMOTE_USER': 'manager'}) |
||
133 | |||
134 | # Il doit y avoir 1 seule ligne de résultats.
|
||
135 | rows = response.lxml.xpath('//table[@class="vigitable"]/tbody/tr')
|
||
136 | print "There are %d rows in the result set" % len(rows) |
||
137 | assert_equal(len(rows), 1) |
||
138 | |||
139 | # Il doit y avoir 1 seule colonne dans la ligne de résultats.
|
||
140 | # (la colonne contient le texte "Il n'y a aucun événément", traduit)
|
||
141 | cols = response.lxml.xpath('//table[@class="vigitable"]/tbody/tr/td')
|
||
142 | print "There are %d columns in the result set" % len(cols) |
||
143 | assert_equal(len(cols), 1) |