build.tests.unit.test_models.TestMW.setup_method()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

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