Passed
Push — master ( 0d5b5f...2f9122 )
by
unknown
01:39 queued 12s
created

build.tests.unit.test_models.TestDeployer.test_end_mw_case_3()   A

Complexity

Conditions 1

Size

Total Lines 18
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 14
nop 1
dl 0
loc 18
ccs 9
cts 9
cp 1
crap 1
rs 9.7
c 0
b 0
f 0
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