vigigraph / vigigraph / tests / functional / test_graph_selection_form.py @ 56b77667
History | View | Annotate | Download (19 KB)
1 | fc33fcfb | Vincent QUEMENER | # -*- coding: utf-8 -*-
|
---|---|---|---|
2 | 56b77667 | Francois POIROTTE | # Copyright (C) 2006-2020 CS-SI
|
3 | 90a1f4ab | Aurelien BOMPARD | # License: GNU GPL v2 <http://www.gnu.org/licenses/gpl-2.0.html>
|
4 | |||
5 | fc33fcfb | Vincent QUEMENER | """
|
6 | b6d2af46 | Vincent QUEMENER | Suite de tests de l'arbre de sélection des graphes et groupes de graphes.
|
7 | fc33fcfb | Vincent QUEMENER | """
|
8 | import transaction |
||
9 | |||
10 | from vigigraph.tests import TestController |
||
11 | from vigilo.models.session import DBSession |
||
12 | fae18e45 | Vincent QUEMENER | from vigilo.models.tables import Host, Graph, GraphGroup |
13 | 8d86738e | Aurelien BOMPARD | from vigigraph.tests.functional.helpers import populateDB, addGraphs |
14 | fae18e45 | Vincent QUEMENER | |
15 | |||
16 | b6d2af46 | Vincent QUEMENER | class TestGraphTree(TestController): |
17 | fc33fcfb | Vincent QUEMENER | """
|
18 | b6d2af46 | Vincent QUEMENER | Teste l'arbre de sélection des graphes
|
19 | et groupes de graphes de Vigigraph.
|
||
20 | fc33fcfb | Vincent QUEMENER | """
|
21 | |||
22 | def setUp(self): |
||
23 | """Préparation de la base de données de tests."""
|
||
24 | |||
25 | # Initialisation de la base
|
||
26 | b6d2af46 | Vincent QUEMENER | super(TestGraphTree, self).setUp() |
27 | fae18e45 | Vincent QUEMENER | |
28 | # Ajout de données de tests dans la base
|
||
29 | (host1, host2, host3) = populateDB() |
||
30 | |||
31 | # Ajout de graphes dans la base
|
||
32 | addGraphs(host1, host2, host3) |
||
33 | fc33fcfb | Vincent QUEMENER | |
34 | # Validation des ajouts dans la base
|
||
35 | DBSession.flush() |
||
36 | transaction.commit() |
||
37 | |||
38 | ##### Quatrième onglet déroulant du formulaire #####
|
||
39 | |||
40 | def test_get_graph_groups_when_allowed(self): |
||
41 | """
|
||
42 | Récupération des groupes de graphes avec les bons droits
|
||
43 | """
|
||
44 | |||
45 | # Récupération de l'hôte 'host1' dans la base de données
|
||
46 | host1 = DBSession.query(Host).filter( |
||
47 | cfed65e0 | Francois POIROTTE | Host.name == u'host1 éà').first()
|
48 | fc33fcfb | Vincent QUEMENER | |
49 | # Récupération de l'hôte 'host2' dans la base de données
|
||
50 | host2 = DBSession.query(Host).filter( |
||
51 | cfed65e0 | Francois POIROTTE | Host.name == u'host2 éà').first()
|
52 | fc33fcfb | Vincent QUEMENER | |
53 | # Récupération de l'hôte 'host3' dans la base de données
|
||
54 | host3 = DBSession.query(Host).filter( |
||
55 | cfed65e0 | Francois POIROTTE | Host.name == u'host3 éà').first()
|
56 | fc33fcfb | Vincent QUEMENER | |
57 | # Récupération du groupe de graphes
|
||
58 | # 'graphgroup1' dans la base de données
|
||
59 | graphgroup1 = DBSession.query(GraphGroup).filter( |
||
60 | GraphGroup.name == u'graphgroup1').first()
|
||
61 | |||
62 | # Récupération du groupe de graphes
|
||
63 | # 'graphgroup2' dans la base de données
|
||
64 | graphgroup2 = DBSession.query(GraphGroup).filter( |
||
65 | GraphGroup.name == u'graphgroup2').first()
|
||
66 | |||
67 | # Récupération du groupe de graphes
|
||
68 | # 'graphgroup3' dans la base de données
|
||
69 | graphgroup3 = DBSession.query(GraphGroup).filter( |
||
70 | GraphGroup.name == u'graphgroup3').first()
|
||
71 | |||
72 | # Récupération des groupes de graphes de l'hôte
|
||
73 | fae18e45 | Vincent QUEMENER | # host1 accessibles à l'utilisateur 'manager'
|
74 | response = self.app.post(
|
||
75 | b6d2af46 | Vincent QUEMENER | '/rpc/graphtree?host_id=%s' % (host1.idhost, ), {
|
76 | fae18e45 | Vincent QUEMENER | }, extra_environ={'REMOTE_USER': 'manager'}) |
77 | json = response.json |
||
78 | |||
79 | # On s'assure que la liste de groupes
|
||
80 | # de graphes retournée contient bien 'graphgroup1'
|
||
81 | 131b409a | Francois POIROTTE | self.assertEqual(
|
82 | b6d2af46 | Vincent QUEMENER | json, { |
83 | 3e3db819 | Aurelien BOMPARD | 'items': [],
|
84 | 'groups': [{'id': graphgroup1.idgroup, |
||
85 | 'name': graphgroup1.name,
|
||
86 | 'type': 'group'}] |
||
87 | b6d2af46 | Vincent QUEMENER | } |
88 | fae18e45 | Vincent QUEMENER | ) |
89 | |||
90 | # Récupération des groupes de graphes de l'hôte
|
||
91 | # host2 accessibles à l'utilisateur 'manager'
|
||
92 | response = self.app.post(
|
||
93 | b6d2af46 | Vincent QUEMENER | '/rpc/graphtree?host_id=%s' % (host2.idhost, ), {
|
94 | fae18e45 | Vincent QUEMENER | }, extra_environ={'REMOTE_USER': 'manager'}) |
95 | json = response.json |
||
96 | |||
97 | # On s'assure que la liste de groupes
|
||
98 | # de graphes retournée contient bien 'graphgroup2'
|
||
99 | 131b409a | Francois POIROTTE | self.assertEqual(
|
100 | b6d2af46 | Vincent QUEMENER | json, { |
101 | 3e3db819 | Aurelien BOMPARD | 'items': [],
|
102 | 'groups': [{'id': graphgroup2.idgroup, |
||
103 | 'name': graphgroup2.name,
|
||
104 | 'type': 'group'}] |
||
105 | b6d2af46 | Vincent QUEMENER | } |
106 | fae18e45 | Vincent QUEMENER | ) |
107 | |||
108 | # Récupération des groupes de graphes de l'hôte
|
||
109 | fc33fcfb | Vincent QUEMENER | # host1 accessibles à l'utilisateur 'poweruser'
|
110 | response = self.app.post(
|
||
111 | b6d2af46 | Vincent QUEMENER | '/rpc/graphtree?host_id=%s' % (host1.idhost, ), {
|
112 | fc33fcfb | Vincent QUEMENER | }, extra_environ={'REMOTE_USER': 'poweruser'}) |
113 | json = response.json |
||
114 | |||
115 | # On s'assure que la liste de groupes
|
||
116 | # de graphes retournée contient bien 'graphgroup1'
|
||
117 | 131b409a | Francois POIROTTE | self.assertEqual(
|
118 | b6d2af46 | Vincent QUEMENER | json, { |
119 | 3e3db819 | Aurelien BOMPARD | 'items': [],
|
120 | 'groups': [{'id': graphgroup1.idgroup, |
||
121 | 'name': graphgroup1.name,
|
||
122 | 'type': 'group'}] |
||
123 | b6d2af46 | Vincent QUEMENER | } |
124 | fc33fcfb | Vincent QUEMENER | ) |
125 | |||
126 | # Récupération des groupes de graphes de l'hôte
|
||
127 | # host2 accessibles à l'utilisateur 'poweruser'
|
||
128 | response = self.app.post(
|
||
129 | b6d2af46 | Vincent QUEMENER | '/rpc/graphtree?host_id=%s' % (host2.idhost, ), {
|
130 | fc33fcfb | Vincent QUEMENER | }, extra_environ={'REMOTE_USER': 'poweruser'}) |
131 | json = response.json |
||
132 | |||
133 | # On s'assure que la liste de groupes
|
||
134 | # de graphes retournée contient bien 'graphgroup2'
|
||
135 | 131b409a | Francois POIROTTE | self.assertEqual(
|
136 | b6d2af46 | Vincent QUEMENER | json, { |
137 | 3e3db819 | Aurelien BOMPARD | 'items': [],
|
138 | 'groups': [{'id': graphgroup2.idgroup, |
||
139 | 'name': graphgroup2.name,
|
||
140 | 'type': 'group'}] |
||
141 | b6d2af46 | Vincent QUEMENER | } |
142 | fc33fcfb | Vincent QUEMENER | ) |
143 | |||
144 | # Récupération des groupes de graphes de l'hôte
|
||
145 | # host2 accessibles à l'utilisateur 'user'
|
||
146 | response = self.app.post(
|
||
147 | b6d2af46 | Vincent QUEMENER | '/rpc/graphtree?host_id=%s' % (host2.idhost, ), {
|
148 | fc33fcfb | Vincent QUEMENER | }, extra_environ={'REMOTE_USER': 'user'}) |
149 | json = response.json |
||
150 | |||
151 | # On s'assure que la liste de groupes
|
||
152 | # de graphes retournée contient bien 'graphgroup2'
|
||
153 | 131b409a | Francois POIROTTE | self.assertEqual(
|
154 | b6d2af46 | Vincent QUEMENER | json, { |
155 | 3e3db819 | Aurelien BOMPARD | 'items': [],
|
156 | 'groups': [{'id': graphgroup2.idgroup, |
||
157 | 'name': graphgroup2.name,
|
||
158 | 'type': 'group'}] |
||
159 | b6d2af46 | Vincent QUEMENER | } |
160 | fc33fcfb | Vincent QUEMENER | ) |
161 | |||
162 | # Récupération des groupes de graphes de l'hôte
|
||
163 | # host3 accessibles à l'utilisateur 'poweruser'
|
||
164 | response = self.app.post(
|
||
165 | b6d2af46 | Vincent QUEMENER | '/rpc/graphtree?host_id=%s' % (host3.idhost, ), {
|
166 | fc33fcfb | Vincent QUEMENER | }, extra_environ={'REMOTE_USER': 'poweruser'}) |
167 | json = response.json |
||
168 | |||
169 | # On s'assure que la liste de groupes
|
||
170 | # de graphes retournée contient bien 'graphgroup3'
|
||
171 | 131b409a | Francois POIROTTE | self.assertEqual(
|
172 | b6d2af46 | Vincent QUEMENER | json, { |
173 | 3e3db819 | Aurelien BOMPARD | 'items': [],
|
174 | 'groups': [{'id': graphgroup3.idgroup, |
||
175 | 'name': graphgroup3.name,
|
||
176 | 'type': 'group'}] |
||
177 | b6d2af46 | Vincent QUEMENER | } |
178 | fc33fcfb | Vincent QUEMENER | ) |
179 | fae18e45 | Vincent QUEMENER | |
180 | fc33fcfb | Vincent QUEMENER | def test_get_graph_groups_when_not_allowed(self): |
181 | """
|
||
182 | Récupération des groupes de graphes sans les bons droits
|
||
183 | """
|
||
184 | |||
185 | # Récupération de l'hôte 'host1' dans la base de données
|
||
186 | host1 = DBSession.query(Host).filter( |
||
187 | cfed65e0 | Francois POIROTTE | Host.name == u'host1 éà').first()
|
188 | fc33fcfb | Vincent QUEMENER | |
189 | # Récupération de l'hôte 'host3' dans la base de données
|
||
190 | host3 = DBSession.query(Host).filter( |
||
191 | cfed65e0 | Francois POIROTTE | Host.name == u'host3 éà').first()
|
192 | fc33fcfb | Vincent QUEMENER | |
193 | # Récupération des groupes de graphes de l'hôte
|
||
194 | # host1 accessibles à l'utilisateur 'user'
|
||
195 | response = self.app.post(
|
||
196 | b6d2af46 | Vincent QUEMENER | '/rpc/graphtree?host_id=%s' % (host1.idhost, ), {
|
197 | fc33fcfb | Vincent QUEMENER | }, extra_environ={'REMOTE_USER': 'user'}) |
198 | json = response.json |
||
199 | |||
200 | # On s'assure que la liste de groupes
|
||
201 | # de graphes retournée est vide
|
||
202 | 131b409a | Francois POIROTTE | self.assertEqual(
|
203 | b6d2af46 | Vincent QUEMENER | json, { |
204 | 7e6517fe | Francois POIROTTE | 'graphs': [],
|
205 | b6d2af46 | Vincent QUEMENER | 'groups': []
|
206 | } |
||
207 | fc33fcfb | Vincent QUEMENER | ) |
208 | |||
209 | # Récupération des groupes de graphes de l'hôte
|
||
210 | # host3 accessibles à l'utilisateur 'user'
|
||
211 | response = self.app.post(
|
||
212 | b6d2af46 | Vincent QUEMENER | '/rpc/graphtree?host_id=%s' % (host3.idhost, ), {
|
213 | fc33fcfb | Vincent QUEMENER | }, extra_environ={'REMOTE_USER': 'user'}) |
214 | json = response.json |
||
215 | |||
216 | # On s'assure que la liste de groupes
|
||
217 | # de graphes retournée est vide
|
||
218 | 131b409a | Francois POIROTTE | self.assertEqual(
|
219 | b6d2af46 | Vincent QUEMENER | json, { |
220 | 7e6517fe | Francois POIROTTE | 'graphs': [],
|
221 | b6d2af46 | Vincent QUEMENER | 'groups': []
|
222 | } |
||
223 | fc33fcfb | Vincent QUEMENER | ) |
224 | |||
225 | # Récupération des groupes de graphes de l'hôte
|
||
226 | # host1 accessibles à l'utilisateur 'visitor'
|
||
227 | response = self.app.post(
|
||
228 | b6d2af46 | Vincent QUEMENER | '/rpc/graphtree?host_id=%s' % (host1.idhost, ), {
|
229 | fc33fcfb | Vincent QUEMENER | }, extra_environ={'REMOTE_USER': 'visitor'}) |
230 | json = response.json |
||
231 | |||
232 | # On s'assure que la liste de groupes
|
||
233 | # de graphes retournée est vide
|
||
234 | 131b409a | Francois POIROTTE | self.assertEqual(
|
235 | b6d2af46 | Vincent QUEMENER | json, { |
236 | 7e6517fe | Francois POIROTTE | 'graphs': [],
|
237 | b6d2af46 | Vincent QUEMENER | 'groups': []
|
238 | } |
||
239 | fc33fcfb | Vincent QUEMENER | ) |
240 | |||
241 | fae18e45 | Vincent QUEMENER | def test_get_graph_groups_as_anonymous(self): |
242 | """
|
||
243 | Récupération des groupes de graphes en tant qu'anonyme
|
||
244 | """
|
||
245 | |||
246 | # Récupération de l'hôte 'host1' dans la base de données
|
||
247 | host1 = DBSession.query(Host).filter( |
||
248 | cfed65e0 | Francois POIROTTE | Host.name == u'host1 éà').first()
|
249 | fae18e45 | Vincent QUEMENER | |
250 | # Récupération des groupes de graphes de l'hôte
|
||
251 | # 'host1' par un utilisateur anonyme : le contrôleur
|
||
252 | # doit retourner une erreur 401 (HTTPUnauthorized)
|
||
253 | self.app.post(
|
||
254 | b6d2af46 | Vincent QUEMENER | '/rpc/graphtree?host_id=%s' % (host1.idhost, ), {
|
255 | fae18e45 | Vincent QUEMENER | }, status=401)
|
256 | |||
257 | fc33fcfb | Vincent QUEMENER | def test_get_graph_groups_from_inexisting_host(self): |
258 | """
|
||
259 | Récupération des groupes de graphes d'un hôte inexistant
|
||
260 | """
|
||
261 | |||
262 | # Récupération des groupes d'hôtes accessibles à l'utilisateur
|
||
263 | # 'visitor' et appartenant à un groupe principal inexistant
|
||
264 | response = self.app.post(
|
||
265 | b6d2af46 | Vincent QUEMENER | '/rpc/graphtree?host_id=6666666', {
|
266 | fc33fcfb | Vincent QUEMENER | }, extra_environ={'REMOTE_USER': 'visitor'}) |
267 | json = response.json |
||
268 | |||
269 | # On s'assure que la liste de groupes
|
||
270 | # de graphes retournée est vide
|
||
271 | 131b409a | Francois POIROTTE | self.assertEqual(
|
272 | b6d2af46 | Vincent QUEMENER | json, { |
273 | 7e6517fe | Francois POIROTTE | 'graphs': [],
|
274 | b6d2af46 | Vincent QUEMENER | 'groups': []
|
275 | } |
||
276 | fc33fcfb | Vincent QUEMENER | ) |
277 | |||
278 | ##### Cinquième onglet déroulant du formulaire #####
|
||
279 | |||
280 | def test_get_graphs_when_allowed(self): |
||
281 | """
|
||
282 | Récupération des graphes avec les bons droits
|
||
283 | """
|
||
284 | |||
285 | # Récupération de l'hôte 'host1' dans la base de données
|
||
286 | host1 = DBSession.query(Host).filter( |
||
287 | cfed65e0 | Francois POIROTTE | Host.name == u'host1 éà').first()
|
288 | fc33fcfb | Vincent QUEMENER | |
289 | # Récupération de l'hôte 'host2' dans la base de données
|
||
290 | host2 = DBSession.query(Host).filter( |
||
291 | cfed65e0 | Francois POIROTTE | Host.name == u'host2 éà').first()
|
292 | fc33fcfb | Vincent QUEMENER | |
293 | # Récupération de l'hôte 'host3' dans la base de données
|
||
294 | host3 = DBSession.query(Host).filter( |
||
295 | cfed65e0 | Francois POIROTTE | Host.name == u'host3 éà').first()
|
296 | fc33fcfb | Vincent QUEMENER | |
297 | # Récupération du groupe de graphes
|
||
298 | # 'graphgroup1' dans la base de données
|
||
299 | graphgroup1 = DBSession.query(GraphGroup).filter( |
||
300 | GraphGroup.name == u'graphgroup1').first()
|
||
301 | |||
302 | # Récupération du groupe de graphes
|
||
303 | # 'graphgroup2' dans la base de données
|
||
304 | graphgroup2 = DBSession.query(GraphGroup).filter( |
||
305 | GraphGroup.name == u'graphgroup2').first()
|
||
306 | |||
307 | # Récupération du groupe de graphes
|
||
308 | # 'graphgroup3' dans la base de données
|
||
309 | graphgroup3 = DBSession.query(GraphGroup).filter( |
||
310 | GraphGroup.name == u'graphgroup3').first()
|
||
311 | |||
312 | # Récupération du graphe 'graph1'
|
||
313 | # dans la base de données
|
||
314 | graph1 = DBSession.query(Graph).filter( |
||
315 | cfed65e0 | Francois POIROTTE | Graph.name == u'graph1 éà').first()
|
316 | fc33fcfb | Vincent QUEMENER | |
317 | # Récupération du graphe 'graph2'
|
||
318 | # dans la base de données
|
||
319 | graph2 = DBSession.query(Graph).filter( |
||
320 | cfed65e0 | Francois POIROTTE | Graph.name == u'graph2 éà').first()
|
321 | fc33fcfb | Vincent QUEMENER | |
322 | # Récupération du graphe 'graph3'
|
||
323 | # dans la base de données
|
||
324 | graph3 = DBSession.query(Graph).filter( |
||
325 | cfed65e0 | Francois POIROTTE | Graph.name == u'graph3 éà').first()
|
326 | fc33fcfb | Vincent QUEMENER | |
327 | # Récupération des graphes du groupe de graphes
|
||
328 | fae18e45 | Vincent QUEMENER | # 'graphgroup1' accessibles à l'utilisateur 'manager'
|
329 | response = self.app.post(
|
||
330 | b6d2af46 | Vincent QUEMENER | '/rpc/graphtree?parent_id=%s&host_id=%s' %
|
331 | fae18e45 | Vincent QUEMENER | (graphgroup1.idgroup, host1.idhost), {}, |
332 | extra_environ={'REMOTE_USER': 'manager'}) |
||
333 | json = response.json |
||
334 | |||
335 | # On s'assure que la liste de
|
||
336 | # graphes retournée contient 'graph1'
|
||
337 | 131b409a | Francois POIROTTE | self.assertEqual(
|
338 | b6d2af46 | Vincent QUEMENER | json, { |
339 | 3e3db819 | Aurelien BOMPARD | 'items': [{'id': graph1.idgraph, |
340 | 'name': graph1.name,
|
||
341 | 'type': 'item'}], |
||
342 | b6d2af46 | Vincent QUEMENER | 'groups': []
|
343 | } |
||
344 | fae18e45 | Vincent QUEMENER | ) |
345 | |||
346 | # Récupération des graphes du groupe de graphes
|
||
347 | # 'graphgroup2' accessibles à l'utilisateur 'manager'
|
||
348 | response = self.app.post(
|
||
349 | b6d2af46 | Vincent QUEMENER | '/rpc/graphtree?parent_id=%s&host_id=%s' %
|
350 | fae18e45 | Vincent QUEMENER | (graphgroup2.idgroup, host2.idhost), {}, |
351 | extra_environ={'REMOTE_USER': 'manager'}) |
||
352 | json = response.json |
||
353 | |||
354 | # On s'assure que la liste de
|
||
355 | # graphes retournée contient 'graph2'
|
||
356 | 131b409a | Francois POIROTTE | self.assertEqual(
|
357 | b6d2af46 | Vincent QUEMENER | json, { |
358 | 3e3db819 | Aurelien BOMPARD | 'items': [{'id': graph2.idgraph, |
359 | 'name': graph2.name,
|
||
360 | 'type': 'item'}], |
||
361 | b6d2af46 | Vincent QUEMENER | 'groups': []
|
362 | } |
||
363 | fae18e45 | Vincent QUEMENER | ) |
364 | |||
365 | # Récupération des graphes du groupe de graphes
|
||
366 | fc33fcfb | Vincent QUEMENER | # 'graphgroup1' accessibles à l'utilisateur 'poweruser'
|
367 | response = self.app.post(
|
||
368 | b6d2af46 | Vincent QUEMENER | '/rpc/graphtree?parent_id=%s&host_id=%s' %
|
369 | fc33fcfb | Vincent QUEMENER | (graphgroup1.idgroup, host1.idhost), {}, |
370 | extra_environ={'REMOTE_USER': 'poweruser'}) |
||
371 | json = response.json |
||
372 | |||
373 | # On s'assure que la liste de
|
||
374 | # graphes retournée contient 'graph1'
|
||
375 | 131b409a | Francois POIROTTE | self.assertEqual(
|
376 | b6d2af46 | Vincent QUEMENER | json, { |
377 | 3e3db819 | Aurelien BOMPARD | 'items': [{'id': graph1.idgraph, |
378 | 'name': graph1.name,
|
||
379 | 'type': 'item'}], |
||
380 | b6d2af46 | Vincent QUEMENER | 'groups': []
|
381 | } |
||
382 | fc33fcfb | Vincent QUEMENER | ) |
383 | |||
384 | # Récupération des graphes du groupe de graphes
|
||
385 | # 'graphgroup2' accessibles à l'utilisateur 'poweruser'
|
||
386 | response = self.app.post(
|
||
387 | b6d2af46 | Vincent QUEMENER | '/rpc/graphtree?parent_id=%s&host_id=%s' %
|
388 | fc33fcfb | Vincent QUEMENER | (graphgroup2.idgroup, host2.idhost), {}, |
389 | extra_environ={'REMOTE_USER': 'poweruser'}) |
||
390 | json = response.json |
||
391 | |||
392 | # On s'assure que la liste de
|
||
393 | # graphes retournée contient 'graph2'
|
||
394 | 131b409a | Francois POIROTTE | self.assertEqual(
|
395 | b6d2af46 | Vincent QUEMENER | json, { |
396 | 3e3db819 | Aurelien BOMPARD | 'items': [{'id': graph2.idgraph, |
397 | 'name': graph2.name,
|
||
398 | 'type': 'item'}], |
||
399 | b6d2af46 | Vincent QUEMENER | 'groups': []
|
400 | } |
||
401 | fc33fcfb | Vincent QUEMENER | ) |
402 | |||
403 | # Récupération des graphes du groupe de graphes
|
||
404 | # 'graphgroup2' accessibles à l'utilisateur 'user'
|
||
405 | response = self.app.post(
|
||
406 | b6d2af46 | Vincent QUEMENER | '/rpc/graphtree?parent_id=%s&host_id=%s' %
|
407 | fc33fcfb | Vincent QUEMENER | (graphgroup2.idgroup, host2.idhost), {}, |
408 | extra_environ={'REMOTE_USER': 'user'}) |
||
409 | json = response.json |
||
410 | |||
411 | # On s'assure que la liste de
|
||
412 | # graphes retournée contient 'graph2'
|
||
413 | 131b409a | Francois POIROTTE | self.assertEqual(
|
414 | b6d2af46 | Vincent QUEMENER | json, { |
415 | 3e3db819 | Aurelien BOMPARD | 'items': [{'id': graph2.idgraph, |
416 | 'name': graph2.name,
|
||
417 | 'type': 'item'}], |
||
418 | b6d2af46 | Vincent QUEMENER | 'groups': []
|
419 | } |
||
420 | fc33fcfb | Vincent QUEMENER | ) |
421 | |||
422 | # Récupération des graphes du groupe de graphes
|
||
423 | # 'graphgroup3' accessibles à l'utilisateur 'poweruser'
|
||
424 | response = self.app.post(
|
||
425 | b6d2af46 | Vincent QUEMENER | '/rpc/graphtree?parent_id=%s&host_id=%s' %
|
426 | fc33fcfb | Vincent QUEMENER | (graphgroup3.idgroup, host3.idhost), {}, |
427 | extra_environ={'REMOTE_USER': 'poweruser'}) |
||
428 | json = response.json |
||
429 | |||
430 | # On s'assure que la liste de
|
||
431 | # graphes retournée contient 'graph3'
|
||
432 | 131b409a | Francois POIROTTE | self.assertEqual(
|
433 | b6d2af46 | Vincent QUEMENER | json, { |
434 | 3e3db819 | Aurelien BOMPARD | 'items': [{'id': graph3.idgraph, |
435 | 'name': graph3.name,
|
||
436 | 'type': 'item'}], |
||
437 | b6d2af46 | Vincent QUEMENER | 'groups': []
|
438 | } |
||
439 | fc33fcfb | Vincent QUEMENER | ) |
440 | |||
441 | def test_get_graphs_when_not_allowed(self): |
||
442 | """
|
||
443 | Récupération des graphes sans les bons droits
|
||
444 | """
|
||
445 | |||
446 | # Récupération de l'hôte 'host1' dans la base de données
|
||
447 | host1 = DBSession.query(Host).filter( |
||
448 | cfed65e0 | Francois POIROTTE | Host.name == u'host1 éà').first()
|
449 | fc33fcfb | Vincent QUEMENER | |
450 | # Récupération de l'hôte 'host3' dans la base de données
|
||
451 | host3 = DBSession.query(Host).filter( |
||
452 | cfed65e0 | Francois POIROTTE | Host.name == u'host3 éà').first()
|
453 | fc33fcfb | Vincent QUEMENER | |
454 | # Récupération du groupe de graphes
|
||
455 | # 'graphgroup1' dans la base de données
|
||
456 | graphgroup1 = DBSession.query(GraphGroup).filter( |
||
457 | GraphGroup.name == u'graphgroup1').first()
|
||
458 | |||
459 | # Récupération du groupe de graphes
|
||
460 | # 'graphgroup3' dans la base de données
|
||
461 | graphgroup3 = DBSession.query(GraphGroup).filter( |
||
462 | GraphGroup.name == u'graphgroup3').first()
|
||
463 | |||
464 | # Récupération des graphes du groupe de graphes
|
||
465 | # graphgroup1 accessibles à l'utilisateur 'user'
|
||
466 | response = self.app.post(
|
||
467 | b6d2af46 | Vincent QUEMENER | '/rpc/graphtree?parent_id=%s&host_id=%s' %
|
468 | fc33fcfb | Vincent QUEMENER | (graphgroup1.idgroup, host1.idhost), {}, |
469 | extra_environ={'REMOTE_USER': 'user'}) |
||
470 | json = response.json |
||
471 | |||
472 | # On s'assure que la liste de groupes
|
||
473 | # de graphes retournée est vide
|
||
474 | 131b409a | Francois POIROTTE | self.assertEqual(
|
475 | b6d2af46 | Vincent QUEMENER | json, { |
476 | 7e6517fe | Francois POIROTTE | 'graphs': [],
|
477 | b6d2af46 | Vincent QUEMENER | 'groups': []
|
478 | } |
||
479 | fc33fcfb | Vincent QUEMENER | ) |
480 | |||
481 | # Récupération des graphes du groupe de graphes
|
||
482 | # 'graphgroup1' accessibles à l'utilisateur 'visitor'
|
||
483 | response = self.app.post(
|
||
484 | b6d2af46 | Vincent QUEMENER | '/rpc/graphtree?parent_id=%s&host_id=%s' %
|
485 | fc33fcfb | Vincent QUEMENER | (graphgroup1.idgroup, host1.idhost), {}, |
486 | extra_environ={'REMOTE_USER': 'visitor'}) |
||
487 | json = response.json |
||
488 | |||
489 | # On s'assure que la liste de groupes
|
||
490 | # de graphes retournée est vide
|
||
491 | 131b409a | Francois POIROTTE | self.assertEqual(
|
492 | b6d2af46 | Vincent QUEMENER | json, { |
493 | 7e6517fe | Francois POIROTTE | 'graphs': [],
|
494 | b6d2af46 | Vincent QUEMENER | 'groups': []
|
495 | } |
||
496 | fc33fcfb | Vincent QUEMENER | ) |
497 | |||
498 | # Récupération des graphes du groupe de graphes
|
||
499 | # 'graphgroup3' accessibles à l'utilisateur 'user'
|
||
500 | response = self.app.post(
|
||
501 | b6d2af46 | Vincent QUEMENER | '/rpc/graphtree?parent_id=%s&host_id=%s' %
|
502 | fc33fcfb | Vincent QUEMENER | (graphgroup3.idgroup, host3.idhost), {}, |
503 | extra_environ={'REMOTE_USER': 'user'}) |
||
504 | json = response.json |
||
505 | |||
506 | # On s'assure que la liste de groupes
|
||
507 | # de graphes retournée est vide
|
||
508 | 131b409a | Francois POIROTTE | self.assertEqual(
|
509 | b6d2af46 | Vincent QUEMENER | json, { |
510 | 7e6517fe | Francois POIROTTE | 'graphs': [],
|
511 | b6d2af46 | Vincent QUEMENER | 'groups': []
|
512 | } |
||
513 | fc33fcfb | Vincent QUEMENER | ) |
514 | |||
515 | fae18e45 | Vincent QUEMENER | def test_get_graphs_as_anonymous(self): |
516 | """
|
||
517 | Récupération des graphes en tant qu'anonyme
|
||
518 | """
|
||
519 | |||
520 | # Récupération de l'hôte 'host1' dans la base de données
|
||
521 | host1 = DBSession.query(Host).filter( |
||
522 | cfed65e0 | Francois POIROTTE | Host.name == u'host1 éà').first()
|
523 | fae18e45 | Vincent QUEMENER | |
524 | # Récupération du groupe de graphes
|
||
525 | # 'graphgroup1' dans la base de données
|
||
526 | graphgroup1 = DBSession.query(GraphGroup).filter( |
||
527 | GraphGroup.name == u'graphgroup1').first()
|
||
528 | |||
529 | # Récupération des graphes du groupe de graphes
|
||
530 | # 'graphgroup1' par un utilisateur anonyme : le contrôleur
|
||
531 | # doit retourner une erreur 401 (HTTPUnauthorized)
|
||
532 | self.app.post(
|
||
533 | b6d2af46 | Vincent QUEMENER | '/rpc/graphtree?parent_id=%s&host_id=%s' %
|
534 | fae18e45 | Vincent QUEMENER | (graphgroup1.idgroup, host1.idhost), |
535 | {}, status=401)
|
||
536 | |||
537 | fc33fcfb | Vincent QUEMENER | def test_get_graphs_from_inexisting_graph_group(self): |
538 | """
|
||
539 | Récupération des graphes d'un groupe de graphes inexistant
|
||
540 | """
|
||
541 | |||
542 | # Récupération des graphes accessibles à l'utilisateur
|
||
543 | fae18e45 | Vincent QUEMENER | # 'manager' et appartenant à un groupe inexistant
|
544 | fc33fcfb | Vincent QUEMENER | response = self.app.post(
|
545 | b6d2af46 | Vincent QUEMENER | '/rpc/graphtree?parent_id=6666666&host_id=6666666', {
|
546 | fae18e45 | Vincent QUEMENER | }, extra_environ={'REMOTE_USER': 'manager'}) |
547 | fc33fcfb | Vincent QUEMENER | json = response.json |
548 | |||
549 | # On s'assure que la liste de
|
||
550 | # graphes retournée est vide
|
||
551 | 131b409a | Francois POIROTTE | self.assertEqual(
|
552 | b6d2af46 | Vincent QUEMENER | json, { |
553 | 7e6517fe | Francois POIROTTE | 'graphs': [],
|
554 | b6d2af46 | Vincent QUEMENER | 'groups': []
|
555 | } |
||
556 | fc33fcfb | Vincent QUEMENER | ) |