vigigraph / vigigraph / tests / functional / test_opensearch.py @ 71709694
History | View | Annotate | Download (2.94 KB)
1 | 8bdfad89 | Francois POIROTTE | # -*- coding: utf-8 -*-
|
---|---|---|---|
2 | 71709694 | Francois POIROTTE | # Copyright (C) 2006-2020 CS GROUP – France
|
3 | 90a1f4ab | Aurelien BOMPARD | # License: GNU GPL v2 <http://www.gnu.org/licenses/gpl-2.0.html>
|
4 | |||
5 | 8bdfad89 | Francois POIROTTE | """
|
6 | Teste l'utilisation du module de recherche
|
||
7 | OpenSearch intégré au navigateur.
|
||
8 | """
|
||
9 | 77b7746d | Francois POIROTTE | import transaction |
10 | import urllib |
||
11 | 8bdfad89 | Francois POIROTTE | |
12 | from vigigraph.tests import TestController |
||
13 | from vigilo.models.session import DBSession |
||
14 | 8d86738e | Aurelien BOMPARD | from vigigraph.tests.functional.helpers import populateDB, addGraphs |
15 | 8bdfad89 | Francois POIROTTE | |
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 | cfed65e0 | Francois POIROTTE | u'/rpc/fullHostPage?host=%s' %
|
47 | 77b7746d | Francois POIROTTE | urllib.quote_plus(host.encode('utf-8'))
|
48 | cfed65e0 | Francois POIROTTE | in response.unicode_body
|
49 | 8bdfad89 | Francois POIROTTE | ) |
50 | else:
|
||
51 | self.assertTrue(
|
||
52 | cfed65e0 | Francois POIROTTE | u'/rpc/fullHostPage?host=%s' %
|
53 | 77b7746d | Francois POIROTTE | urllib.quote_plus(host.encode('utf-8'))
|
54 | cfed65e0 | Francois POIROTTE | not in response.unicode_body |
55 | 8bdfad89 | Francois POIROTTE | ) |
56 | |||
57 | def test_direct_permission(self): |
||
58 | """OpenSearch avec permission sur le groupe"""
|
||
59 | hosts = { |
||
60 | cfed65e0 | Francois POIROTTE | u'host1 éà': False, |
61 | u'host2 éà': True, |
||
62 | u'host3 éà': False, |
||
63 | 8bdfad89 | Francois POIROTTE | } |
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 | cfed65e0 | Francois POIROTTE | u'host1 éà': True, |
70 | u'host2 éà': True, |
||
71 | u'host3 éà': True, |
||
72 | 8bdfad89 | Francois POIROTTE | } |
73 | self._check_results('poweruser', hosts) |
||
74 | |||
75 | def test_no_permission(self): |
||
76 | """OpenSearch sans permissions"""
|
||
77 | hosts = { |
||
78 | cfed65e0 | Francois POIROTTE | u'host1 éà': False, |
79 | u'host2 éà': False, |
||
80 | u'host3 éà': False, |
||
81 | 8bdfad89 | Francois POIROTTE | } |
82 | self._check_results('visitor', hosts) |
||
83 | |||
84 | def test_anonymous(self): |
||
85 | """OpenSearch en anonyme"""
|
||
86 | cfed65e0 | Francois POIROTTE | for host in (u'host1 éà', u'host2 éà', u'host3 éà'): |
87 | 8d86738e | Aurelien BOMPARD | self.app.get(
|
88 | cfed65e0 | Francois POIROTTE | '/rpc/fullHostPage?host=%s' %
|
89 | 77b7746d | Francois POIROTTE | urllib.quote_plus(host.encode('utf-8'), ''), |
90 | 8bdfad89 | Francois POIROTTE | status=401
|
91 | ) |
||
92 | |||
93 | def test_managers(self): |
||
94 | """OpenSearch avec le compte manager"""
|
||
95 | hosts = { |
||
96 | cfed65e0 | Francois POIROTTE | u'host1 éà': True, |
97 | u'host2 éà': True, |
||
98 | u'host3 éà': True, |
||
99 | 8bdfad89 | Francois POIROTTE | } |
100 | self._check_results('manager', hosts) |