vigigraph / vigigraph / tests / functional / test_opensearch.py @ 77b7746d
History | View | Annotate | Download (2.93 KB)
1 |
# -*- coding: utf-8 -*-
|
---|---|
2 |
# Copyright (C) 2006-2016 CS-SI
|
3 |
# License: GNU GPL v2 <http://www.gnu.org/licenses/gpl-2.0.html>
|
4 |
|
5 |
"""
|
6 |
Teste l'utilisation du module de recherche
|
7 |
OpenSearch intégré au navigateur.
|
8 |
"""
|
9 |
import transaction |
10 |
import urllib |
11 |
|
12 |
from vigigraph.tests import TestController |
13 |
from vigilo.models.session import DBSession |
14 |
from vigigraph.tests.functional.helpers import populateDB, addGraphs |
15 |
|
16 |
|
17 |
class TestOpenSearch(TestController): |
18 |
"""
|
19 |
Teste la page d'affichage de tous les graphs d'un hôte.
|
20 |
"""
|
21 |
|
22 |
def setUp(self): |
23 |
"""Préparation de la base de données de tests."""
|
24 |
|
25 |
# Initialisation de la base
|
26 |
super(TestOpenSearch, self).setUp() |
27 |
|
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 |
|
34 |
# Validation des ajouts dans la base
|
35 |
DBSession.flush() |
36 |
transaction.commit() |
37 |
|
38 |
def _check_results(self, user, hosts): |
39 |
response = self.app.get(
|
40 |
'/rpc/searchHost?query=host*',
|
41 |
extra_environ={"REMOTE_USER": user}
|
42 |
) |
43 |
for host in hosts: |
44 |
if hosts[host]:
|
45 |
self.assertTrue(
|
46 |
u'/rpc/fullHostPage?host=%s' %
|
47 |
urllib.quote_plus(host.encode('utf-8'))
|
48 |
in response.unicode_body
|
49 |
) |
50 |
else:
|
51 |
self.assertTrue(
|
52 |
u'/rpc/fullHostPage?host=%s' %
|
53 |
urllib.quote_plus(host.encode('utf-8'))
|
54 |
not in response.unicode_body |
55 |
) |
56 |
|
57 |
def test_direct_permission(self): |
58 |
"""OpenSearch avec permission sur le groupe"""
|
59 |
hosts = { |
60 |
u'host1 éà': False, |
61 |
u'host2 éà': True, |
62 |
u'host3 éà': False, |
63 |
} |
64 |
self._check_results('user', hosts) |
65 |
|
66 |
def test_permission_on_parent(self): |
67 |
"""OpenSearch avec permission sur le parent du groupe"""
|
68 |
hosts = { |
69 |
u'host1 éà': True, |
70 |
u'host2 éà': True, |
71 |
u'host3 éà': True, |
72 |
} |
73 |
self._check_results('poweruser', hosts) |
74 |
|
75 |
def test_no_permission(self): |
76 |
"""OpenSearch sans permissions"""
|
77 |
hosts = { |
78 |
u'host1 éà': False, |
79 |
u'host2 éà': False, |
80 |
u'host3 éà': False, |
81 |
} |
82 |
self._check_results('visitor', hosts) |
83 |
|
84 |
def test_anonymous(self): |
85 |
"""OpenSearch en anonyme"""
|
86 |
for host in (u'host1 éà', u'host2 éà', u'host3 éà'): |
87 |
self.app.get(
|
88 |
'/rpc/fullHostPage?host=%s' %
|
89 |
urllib.quote_plus(host.encode('utf-8'), ''), |
90 |
status=401
|
91 |
) |
92 |
|
93 |
def test_managers(self): |
94 |
"""OpenSearch avec le compte manager"""
|
95 |
hosts = { |
96 |
u'host1 éà': True, |
97 |
u'host2 éà': True, |
98 |
u'host3 éà': True, |
99 |
} |
100 |
self._check_results('manager', hosts) |