Passed
Push — master ( 46397d...edc14b )
by
unknown
05:36 queued 14s
created

TestDBModels.test_evcupdatedoc()   A

Complexity

Conditions 1

Size

Total Lines 10
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 9
nop 1
dl 0
loc 10
ccs 9
cts 9
cp 1
crap 1
rs 9.95
c 0
b 0
f 0
1
"""Tests for DB models."""
2 1
import pytest
3 1
from pydantic import ValidationError
4
5 1
from db.models import EVCBaseDoc, DocumentBaseModel, TAGDoc, EVCUpdateDoc
6
7
8 1
class TestDBModels():
9
    """Test the DB models"""
10
11 1
    def setup_method(self):
12
        """Setup method."""
13 1
        self.evc_dict = {
14
            "uni_a": {
15
                "interface_id": "00:00:00:00:00:00:00:04:1",
16
                "tag": {
17
                    "tag_type": 1,
18
                    "value": 100,
19
                },
20
            },
21
            "uni_z": {
22
                "interface_id": "00:00:00:00:00:00:00:02:3",
23
                "tag": {
24
                    "tag_type": 1,
25
                    "value": 100,
26
                }
27
            },
28
            "name": "EVC 2",
29
            "dynamic_backup_path": True,
30
            "creation_time": "2022-04-06T21:34:10",
31
            "sb_priority": 81,
32
            "active": False,
33
            "enabled": False,
34
            "circuit_scheduler": [],
35
            "queue_id": None
36
        }
37 1
        self.evc_update = {
38
            "uni_a": {
39
                "interface_id": "00:00:00:00:00:00:00:04:1",
40
                "tag": {
41
                    "tag_type": 1,
42
                    "value": 100,
43
                },
44
            },
45
            "uni_z": {
46
                "interface_id": "00:00:00:00:00:00:00:02:3",
47
                "tag": {
48
                    "tag_type": 1,
49
                    "value": 100,
50
                }
51
            },
52
            "name": "EVC 2",
53
            "dynamic_backup_path": True,
54
            "sb_priority": 81,
55
            "enabled": False,
56
            "circuit_scheduler": [],
57
            "queue_id": None
58
        }
59
60 1
    def test_evcbasedoc(self):
61
        """Test EVCBaseDoc model"""
62
63 1
        evc = EVCBaseDoc(**self.evc_dict)
64 1
        assert evc.name == "EVC 2"
65 1
        assert evc.uni_a.interface_id == "00:00:00:00:00:00:00:04:1"
66 1
        assert evc.uni_z.interface_id == "00:00:00:00:00:00:00:02:3"
67 1
        assert evc.dynamic_backup_path
68 1
        assert evc.sb_priority == 81
69 1
        assert evc.service_level == 0
70 1
        assert not evc.active
71 1
        assert not evc.enabled
72 1
        assert not evc.circuit_scheduler
73
74 1
    def test_evcupdatedoc(self):
75
        """Test EVCUpdateDoc model"""
76 1
        evc = EVCUpdateDoc(**self.evc_update)
77 1
        assert evc.name == "EVC 2"
78 1
        assert evc.uni_a.interface_id == "00:00:00:00:00:00:00:04:1"
79 1
        assert evc.uni_z.interface_id == "00:00:00:00:00:00:00:02:3"
80 1
        assert evc.dynamic_backup_path
81 1
        assert evc.sb_priority == 81
82 1
        assert not evc.enabled
83 1
        assert not evc.circuit_scheduler
84
85 1
    def test_evcbasedoc_error(self):
86
        """Test failure EVCBaseDoc model creation"""
87
88 1
        self.evc_dict["queue_id"] = "error"
89
90 1
        with pytest.raises(ValidationError):
91 1
            EVCBaseDoc(**self.evc_dict)
92
93 1
    def test_document_base_model_dict(self):
94
        """test_document_base_model_dict."""
95 1
        self.evc_dict["_id"] = "some_id"
96 1
        model = DocumentBaseModel(**self.evc_dict)
97 1
        assert "_id" not in model.dict(exclude={"_id"})
98
99 1
    def test_tagdoc_value(self):
100
        """Test TAGDoc value restrictions"""
101 1
        tag_mask = {"tag_type": 1, "value": "untagged"}
102 1
        tag = TAGDoc(**tag_mask)
103 1
        assert tag.tag_type == 1
104 1
        assert tag.value == "untagged"
105
106 1
        tag_mask = {"tag_type": 1, "value": "any"}
107 1
        tag = TAGDoc(**tag_mask)
108 1
        assert tag.tag_type == 1
109 1
        assert tag.value == "any"
110
111 1
    def test_tagdoc_fail(self):
112
        """Test TAGDoc value fail case"""
113 1
        tag_fail = {"tag_type": 1, "value": "test_fail"}
114 1
        with pytest.raises(ValueError):
115
            TAGDoc(**tag_fail)
116