Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

vigiboard / vigiboard / tests / models / test_vigiboard.py @ 35cea70e

History | View | Annotate | Download (5.29 KB)

1
# -*- coding: utf-8 -*-
2
# vim:set expandtab tabstop=4 shiftwidth=4:
3
"""Test des modèle de Vigiboard"""
4

    
5
from nose.tools import assert_true
6
import re
7
from vigiboard.model import DBSession, Host, Service, Events, Graph, \
8
    GraphGroups, Groups, ServiceHautNiveau, EventHistory, GraphToGroups, \
9
    GroupPermissions, HostGroups, PerfDataSource, ServiceGroups, ServiceTopo
10
from vigiboard.tests.models import ModelTest
11

    
12

    
13
class TestEventHistory(ModelTest):
14
    """Test de la table EventHistory"""
15

    
16
    klass = EventHistory
17
    attrs = dict(type_action = 'Nagios update state', value = '',
18
            text = '', username = 'manager')
19

    
20
    def do_get_dependencies(self):
21
        """Generate some data for the test"""
22

    
23
        DBSession.add(Host(name = "monhost"))
24
        DBSession.add(Service(name = "monservice"))
25
        DBSession.flush()
26
        DBSession.add(Events(hostname = "monhost", servicename = "monservice"))
27
        DBSession.flush()
28
        return dict(idevent = DBSession.query(Events.idevent)[0].idevent)
29

    
30
class TestEvent(ModelTest):
31
    """Test de la table Events"""
32

    
33
    klass = Events
34
    attrs = {}
35

    
36
    def do_get_dependencies(self):
37
        """Generate some data for the test"""
38

    
39
        DBSession.add(Host(name = "monhost"))
40
        DBSession.add(Service(name = "monservice"))
41
        DBSession.flush()
42
        return dict(hostname = "monhost", servicename = "monservice")
43

    
44
    def test_get_date(self):
45
        """La fonction GetDate doit renvoyer un objet formaté"""
46
        form1 = re.compile("^\w* \w* \d*:\d*:\d*$")
47
        form2 = re.compile("^\w* \d*:\d*:\d*$")
48
        assert_true(form1.match(self.obj.get_date("timestamp_active")) \
49
                or form2.match(self.obj.get_date("timestamp_active")))
50

    
51
    def test_get_since_date(self):
52
        """La fonction GetSinceDate doit renvoyer un objet formaté"""
53
        assert_true(re.compile("^\d*d \d*h \d'$").match(
54
            self.obj.get_since_date("timestamp_active")))
55
        
56
class TestGraph(ModelTest):
57
    """Test de la table GraphGroups"""
58

    
59
    klass = GraphGroups
60
    attrs = dict(name = "mongraph")
61

    
62
class TestGraphToGroups(ModelTest):
63
    """Test de la table GraphToGroups"""
64

    
65
    klass = GraphToGroups
66
    attrs = {}
67

    
68
    def do_get_dependencies(self):
69
        """Generate some data for the test"""
70

    
71
        DBSession.add(Graph(name = "mongraph"))
72
        DBSession.add(GraphGroups(name = "mongraphgroup"))
73
        DBSession.flush()
74
        return dict(graphname = "mongraph", groupname = "mongraphgroup")
75

    
76
class TestGraphGroups(ModelTest):
77
    """Test de la table GraphGroups"""
78

    
79
    klass = GraphGroups
80
    attrs = dict(name = "mongraphgroup")
81

    
82
class TestGroupPermissions(ModelTest):
83
    """Test de la table GroupPermissions"""
84

    
85
    klass = GroupPermissions
86
    attrs = {}
87

    
88
    def do_get_dependencies(self):
89
        """Generate some data for the test"""
90

    
91
        DBSession.add(Groups(name = "mongroup"))
92
        DBSession.flush()
93
        return dict(groupname = "mongroup")
94

    
95
class TestGroups(ModelTest):
96
    """Test de la table Groups"""
97

    
98
    klass = Groups
99
    attrs = dict(name = "mongroup")
100

    
101
class TestHost(ModelTest):
102
    """Test de la table host"""
103

    
104
    klass = Host
105
    attrs = dict(name = "monhost")
106

    
107
class TestHostGroups(ModelTest):
108
    """Test de la table hostgroup"""
109

    
110
    klass = HostGroups
111
    attrs = {}
112

    
113
    def do_get_dependencies(self):
114
        """Generate some data for the test"""
115

    
116
        DBSession.add(Host(name = "monhost"))
117
        DBSession.add(Groups(name = "mongroup"))
118
        DBSession.flush()
119
        return dict(hostname = "monhost", groupname = "mongroup")
120

    
121
class TestPerfDataSource(ModelTest):
122
    """Test de la table perfdatasource"""
123

    
124
    klass = PerfDataSource
125
    attrs = {}
126

    
127
    def do_get_dependencies(self):
128
        """Generate some data for the test"""
129

    
130
        DBSession.add(Host(name = "monhost"))
131
        DBSession.add(Service(name = "monservice"))
132
        DBSession.add(Graph(name = "mongraph"))
133
        DBSession.flush()
134
        return dict(hostname = "monhost", servicename = "monservice",
135
                graphname = "mongraph")
136

    
137
class TestServiceGroups(ModelTest):
138
    """Test de la table servicegroups"""
139

    
140
    klass = ServiceGroups
141
    attrs = {}
142

    
143
    def do_get_dependencies(self):
144
        """Generate some data for the test"""
145

    
146
        DBSession.add(Service(name = "monservice"))
147
        DBSession.add(Groups(name = "mongroupe"))
148
        DBSession.flush()
149
        return dict(servicename = "monservice", groupname = "mongroupe")
150

    
151
class TestServiceHautNiveau(ModelTest):
152
    """Test de la table servicehautniveau"""
153

    
154
    klass = ServiceHautNiveau
155
    attrs = {}
156

    
157
    def do_get_dependencies(self):
158
        """Generate some data for the test"""
159
        
160
        DBSession.add(Service(name = "monservice"))
161
        DBSession.flush()
162
        return dict(servicename = "monservice", servicename_dep = "monservice")
163

    
164
class TestService(ModelTest):
165
    """Test de la table service"""
166

    
167
    klass = Service
168
    attrs = dict(name = "monservice")
169

    
170
class TestServiceTopo(ModelTest):
171
    """Test de la table servicetopo"""
172

    
173
    klass = ServiceTopo
174
    attrs = {}
175

    
176
    def do_get_dependencies(self):
177
        """Generate some data for the test"""
178

    
179
        DBSession.add(Service(name = "monservice"))
180
        DBSession.add(ServiceHautNiveau(servicename = "monservice",
181
            servicename_dep = "monservice"))
182
        DBSession.flush()
183
        return dict(servicename = "monservice")