Passed
Pull Request — master (#166)
by Antonio
03:20
created

TestControllers.test_get_circuits()   A

Complexity

Conditions 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
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
        ]
44
        mock = self.eline.mongo.bootstrap_index
45
        assert mock.call_count == len(expected_indexes)
46
47
    def test_get_circuits(self):
48
        """Test get_circuits"""
49
50
        assert "circuits" in self.eline.get_circuits()
51
        assert self.eline.db.evcs.aggregate.call_count == 1
52
53
    def test_upsert_evc(self):
54
        """Test upsert_evc"""
55
56
        self.eline.upsert_evc(self.evc_dict)
57
        assert self.eline.db.evcs.find_one_and_update.call_count == 1
58