1
|
|
|
"""Tests for the models module.""" |
2
|
|
|
|
3
|
1 |
|
from unittest import TestCase |
4
|
|
|
|
5
|
1 |
|
from datetime import datetime, timedelta |
6
|
1 |
|
import pytz |
7
|
1 |
|
from kytos.lib.helpers import get_controller_mock |
8
|
1 |
|
from napps.kytos.maintenance.models import MaintenanceWindow as MW, Status |
9
|
|
|
|
10
|
1 |
|
TIME_FMT = "%Y-%m-%dT%H:%M:%S%z" |
11
|
|
|
|
12
|
|
|
|
13
|
1 |
|
class TestMW(TestCase): |
14
|
|
|
"""Test of the MaintenanceWindow class.""" |
15
|
|
|
|
16
|
|
|
# pylint: disable=protected-access |
17
|
|
|
|
18
|
1 |
|
def setUp(self): |
19
|
|
|
"""Initialize before tests are executed.""" |
20
|
1 |
|
self.controller = get_controller_mock() |
21
|
1 |
|
self.start = datetime.now(pytz.utc) |
22
|
1 |
|
self.start += timedelta(days=1) |
23
|
1 |
|
self.end = self.start + timedelta(hours=6) |
24
|
1 |
|
self.switches = [ |
25
|
|
|
"01:23:45:67:89:ab:cd:ef" |
26
|
|
|
] |
27
|
1 |
|
self.maintenance = MW( |
28
|
|
|
start=self.start, |
29
|
|
|
end=self.end, |
30
|
|
|
switches=self.switches |
31
|
|
|
) |
32
|
|
|
|
33
|
1 |
|
def test_as_dict(self): |
34
|
|
|
"""Test as_dict method.""" |
35
|
1 |
|
mw_dict = self.maintenance.dict() |
36
|
1 |
|
expected_dict = { |
37
|
|
|
'description': '', |
38
|
|
|
'start': self.start, |
39
|
|
|
'end': self.end, |
40
|
|
|
'id': self.maintenance.id, |
41
|
|
|
'switches': self.switches, |
42
|
|
|
'interfaces': [], |
43
|
|
|
'links': [], |
44
|
|
|
'status': Status.PENDING, |
45
|
|
|
'inserted_at': None, |
46
|
|
|
'updated_at': None, |
47
|
|
|
} |
48
|
1 |
|
self.assertEqual(mw_dict, expected_dict) |
49
|
|
|
|
50
|
1 |
|
def test_start_in_past(self): |
51
|
1 |
|
start = datetime.now(pytz.utc) - timedelta(days=1) |
52
|
|
|
|
53
|
1 |
|
self.assertRaises(ValueError, MW, |
54
|
|
|
start=start, |
55
|
|
|
end=self.end, |
56
|
|
|
switches=self.switches, |
57
|
|
|
) |
58
|
|
|
|
59
|
1 |
|
def test_end_before_start(self): |
60
|
1 |
|
end = datetime.now(pytz.utc) - timedelta(days=1) |
61
|
|
|
|
62
|
1 |
|
self.assertRaises(ValueError, MW, |
63
|
|
|
start=self.start, |
64
|
|
|
end=end, |
65
|
|
|
switches=self.switches, |
66
|
|
|
) |
67
|
|
|
|
68
|
1 |
|
def test_items_empty(self): |
69
|
|
|
|
70
|
1 |
|
self.assertRaises(ValueError, MW, |
71
|
|
|
start=self.start, |
72
|
|
|
end=self.end, |
73
|
|
|
) |
74
|
|
|
|