Passed
Push — master ( bd08d2...1ddd15 )
by Vinicius
02:53 queued 14s
created

TestControllers.test_get_circuits_archived_false()   A

Complexity

Conditions 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
"""Tests for the DB controller."""
2
from unittest import TestCase
3
from unittest.mock import MagicMock
4
5
from controllers import ELineController
6
7
8
class TestControllers(TestCase):
9
    """Test DB Controllers"""
10
11
    def setUp(self) -> None:
12
        self.eline = ELineController(MagicMock())
13
        self.evc_dict = {
14
            "id": "1234",
15
            "uni_a": {
16
                "interface_id": "00:00:00:00:00:00:00:01:1",
17
                "tag": {
18
                    "tag_type": 1,
19
                    "value": 200,
20
                }
21
            },
22
            "uni_z": {
23
                "interface_id": "00:00:00:00:00:00:00:02:2",
24
                "tag": {
25
                    "tag_type": 1,
26
                    "value": 200,
27
                }
28
            },
29
            "name": "EVC 1",
30
            "dynamic_backup_path": True,
31
            "creation_time": "2022-05-06T21:34:10",
32
            "priority": 100,
33
            "active": False,
34
            "enabled": True,
35
            "circuit_scheduler": []
36
        }
37
38
    def test_bootstrap_indexes(self):
39
        """Test bootstrap_indexes"""
40
        self.eline.bootstrap_indexes()
41
        expected_indexes = [
42
            ("evcs", [("circuit_scheduler", 1)]),
43
            ("evcs", [("archived", 1)]),
44
        ]
45
        mock = self.eline.mongo.bootstrap_index
46
        assert mock.call_count == len(expected_indexes)
47
48
    def test_get_circuits(self):
49
        """Test get_circuits"""
50
51
        assert "circuits" in self.eline.get_circuits()
52
        assert self.eline.db.evcs.aggregate.call_count == 1
53
54
    def test_get_circuits_archived_false(self):
55
        """Test get_circuits with archive being false"""
56
        self.eline.get_circuits(archived=None)
57
        args = self.eline.db.evcs.aggregate.call_args[0][0][0]
58
        assert args["$match"] == {}
59
60
    def test_get_circuits_archived_true(self):
61
        """Test get_circuits with archive being true"""
62
        self.eline.get_circuits(archived="true")
63
        args = self.eline.db.evcs.aggregate.call_args[0][0][0]
64
        assert args["$match"] == {'archived': True}
65
66
    def test_get_circuits_metadata(self):
67
        """Test get_circuits with metadata"""
68
        metadata = {"metadata.test": "123"}
69
        self.eline.get_circuits(archived=True, metadata=metadata)
70
        args = self.eline.db.evcs.aggregate.call_args[0][0][0]
71
        assert args["$match"]["metadata.test"] == 123
72
73
    def test_upsert_evc(self):
74
        """Test upsert_evc"""
75
76
        self.eline.upsert_evc(self.evc_dict)
77
        assert self.eline.db.evcs.find_one_and_update.call_count == 1
78
79
    def test_update_evcs(self):
80
        """Test update_evcs"""
81
        circuit_ids = ["123", "456", "789"]
82
        metadata = {"info": "testing"}
83
        self.eline.update_evcs(circuit_ids, metadata, "add")
84
        arg = self.eline.db.evcs.bulk_write.call_args[0][0]
85
        assert len(arg) == 3
86
        assert self.eline.db.evcs.bulk_write.call_count == 1
87