vigiboard / vigiboard / tests / functional / test_sorting.py @ c94dc931
History | View | Annotate | Download (4.97 KB)
1 | 5a845c93 | Vincent QUEMENER | # -*- coding: utf-8 -*-
|
---|---|---|---|
2 | # vim:set expandtab tabstop=4 shiftwidth=4:
|
||
3 | c94dc931 | Francois POIROTTE | # Copyright (C) 2006-2020 CS-SI
|
4 | 5a845c93 | Vincent QUEMENER | # License: GNU GPL v2 <http://www.gnu.org/licenses/gpl-2.0.html>
|
5 | |||
6 | """
|
||
7 | Test du tri de Vigiboard
|
||
8 | """
|
||
9 | |||
10 | from __future__ import absolute_import |
||
11 | |||
12 | from nose.tools import assert_true, assert_equal |
||
13 | |||
14 | import transaction |
||
15 | from vigilo.models.demo import functions |
||
16 | from vigilo.models.session import DBSession |
||
17 | from vigilo.models import tables |
||
18 | |||
19 | from vigiboard.tests import TestController |
||
20 | from tg import config |
||
21 | |||
22 | def populate_DB(): |
||
23 | """ Peuple la base de données en vue des tests. """
|
||
24 | |||
25 | # On crée deux hôtes de test.
|
||
26 | host1 = functions.add_host(u'host1')
|
||
27 | host2 = functions.add_host(u'host2')
|
||
28 | DBSession.flush() |
||
29 | |||
30 | # On ajoute un service sur chaque hôte.
|
||
31 | service1 = functions.add_lowlevelservice( |
||
32 | host2, u'service1')
|
||
33 | service2 = functions.add_lowlevelservice( |
||
34 | host1, u'service2')
|
||
35 | DBSession.flush() |
||
36 | |||
37 | # On ajoute un événement brut sur chaque service.
|
||
38 | event1 = functions.add_event(service1, u'WARNING', u'foo') |
||
39 | event2 = functions.add_event(service2, u'CRITICAL', u'foo') |
||
40 | DBSession.flush() |
||
41 | |||
42 | # On ajoute un événement corrélé pour chaque événement brut.
|
||
43 | functions.add_correvent([event1]) |
||
44 | functions.add_correvent([event2]) |
||
45 | DBSession.flush() |
||
46 | transaction.commit() |
||
47 | |||
48 | class TestSorting(TestController): |
||
49 | """
|
||
50 | Test du tri de Vigiboard
|
||
51 | """
|
||
52 | def setUp(self): |
||
53 | super(TestSorting, self).setUp() |
||
54 | populate_DB() |
||
55 | |||
56 | def test_ascending_order(self): |
||
57 | """ Tri dans l'ordre croissant """
|
||
58 | |||
59 | # On affiche la page principale de VigiBoard
|
||
60 | # triée sur le nom d'hôte par ordre croissant
|
||
61 | environ = {'REMOTE_USER': 'manager'} |
||
62 | response = self.app.get(
|
||
63 | '/?sort=hostname&order=asc', extra_environ=environ)
|
||
64 | |||
65 | # Il doit y avoir 2 lignes de résultats :
|
||
66 | # - la 1ère concerne 'service2' sur 'host1' ;
|
||
67 | # - la 2nde concerne 'service1' sur 'host2'.
|
||
68 | # Il doit y avoir plusieurs colonnes dans la ligne de résultats.
|
||
69 | hostnames = response.lxml.xpath( |
||
70 | 7bde24ad | Francois POIROTTE | '//table[contains(concat(" ", @class, " "), " vigitable ")]'
|
71 | '/tbody/tr/td[@class="plugin_hostname"]/text()')
|
||
72 | 5a845c93 | Vincent QUEMENER | assert_equal(hostnames, ['host1', 'host2']) |
73 | servicenames = response.lxml.xpath( |
||
74 | 7bde24ad | Francois POIROTTE | '//table[contains(concat(" ", @class, " "), " vigitable ")]'
|
75 | '/tbody/tr/td[@class="plugin_servicename"]/text()')
|
||
76 | 5a845c93 | Vincent QUEMENER | assert_equal(servicenames, ['service2', 'service1']) |
77 | |||
78 | def test_descending_order(self): |
||
79 | """ Tri dans l'ordre décroissant """
|
||
80 | |||
81 | # On affiche la page principale de VigiBoard
|
||
82 | # triée sur le nom de service par ordre décroissant
|
||
83 | environ = {'REMOTE_USER': 'manager'} |
||
84 | response = self.app.get(
|
||
85 | '/?sort=servicename&order=desc', extra_environ=environ)
|
||
86 | |||
87 | # Il doit y avoir 2 lignes de résultats :
|
||
88 | # - la 1ère concerne 'service2' sur 'host1' ;
|
||
89 | # - la 2nde concerne 'service1' sur 'host2'.
|
||
90 | # Il doit y avoir plusieurs colonnes dans la ligne de résultats.
|
||
91 | hostnames = response.lxml.xpath( |
||
92 | 7bde24ad | Francois POIROTTE | '//table[contains(concat(" ", @class, " "), " vigitable ")]'
|
93 | '/tbody/tr/td[@class="plugin_hostname"]/text()')
|
||
94 | 5a845c93 | Vincent QUEMENER | assert_equal(hostnames, ['host1', 'host2']) |
95 | servicenames = response.lxml.xpath( |
||
96 | 7bde24ad | Francois POIROTTE | '//table[contains(concat(" ", @class, " "), " vigitable ")]'
|
97 | '/tbody/tr/td[@class="plugin_servicename"]/text()')
|
||
98 | 5a845c93 | Vincent QUEMENER | assert_equal(servicenames, ['service2', 'service1']) |
99 | |||
100 | def test_pagination(self): |
||
101 | """ Pagination du tri """
|
||
102 | |||
103 | # On crée autant d'événements qu'on peut en afficher par page + 1,
|
||
104 | # afin d'avoir 2 pages dans le bac à événements.
|
||
105 | host3 = functions.add_host(u'host3')
|
||
106 | service3 = functions.add_lowlevelservice( |
||
107 | host3, u'service3')
|
||
108 | DBSession.flush() |
||
109 | items_per_page = int(config['vigiboard_items_per_page']) |
||
110 | for i in xrange(items_per_page - 1): |
||
111 | event = functions.add_event(service3, u'WARNING', u'foo') |
||
112 | functions.add_correvent([event]) |
||
113 | DBSession.flush() |
||
114 | transaction.commit() |
||
115 | |||
116 | # On affiche la seconde page de VigiBoard avec
|
||
117 | # un tri par ordre décroissant sur le nom d'hôte
|
||
118 | environ = {'REMOTE_USER': 'manager'} |
||
119 | response = self.app.get(
|
||
120 | '/?page=2&sort=hostname&order=desc', extra_environ=environ)
|
||
121 | |||
122 | # Il ne doit y avoir qu'une seule ligne de
|
||
123 | # résultats concernant "service2" sur "host1"
|
||
124 | hostnames = response.lxml.xpath( |
||
125 | 7bde24ad | Francois POIROTTE | '//table[contains(concat(" ", @class, " "), " vigitable ")]'
|
126 | '/tbody/tr/td[@class="plugin_hostname"]/text()')
|
||
127 | 5a845c93 | Vincent QUEMENER | assert_equal(hostnames, ['host1'])
|
128 | servicenames = response.lxml.xpath( |
||
129 | 7bde24ad | Francois POIROTTE | '//table[contains(concat(" ", @class, " "), " vigitable ")]'
|
130 | '/tbody/tr/td[@class="plugin_servicename"]/text()')
|
||
131 | 5a845c93 | Vincent QUEMENER | assert_equal(servicenames, ['service2'])
|
132 |