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(self): |
55
|
|
|
"""Test get_circuits archived filter""" |
56
|
|
|
|
57
|
|
|
self.eline.get_circuits(archived=None) |
58
|
|
|
arg1 = self.eline.db.evcs.aggregate.call_args[0] |
59
|
|
|
assert "$match" not in arg1[0][0] |
60
|
|
|
|
61
|
|
|
self.eline.get_circuits(archived=True) |
62
|
|
|
arg1 = self.eline.db.evcs.aggregate.call_args[0] |
63
|
|
|
assert arg1[0][0]["$match"] == {'archived': True} |
64
|
|
|
|
65
|
|
|
def test_upsert_evc(self): |
66
|
|
|
"""Test upsert_evc""" |
67
|
|
|
|
68
|
|
|
self.eline.upsert_evc(self.evc_dict) |
69
|
|
|
assert self.eline.db.evcs.find_one_and_update.call_count == 1 |
70
|
|
|
|
71
|
|
|
def test_update_bulk_evc(self): |
72
|
|
|
"""Test update_bulk_evc""" |
73
|
|
|
circuit_ids = ["123", "456", "789"] |
74
|
|
|
metadata = {"$set": {"metadata.info": "testing"}} |
75
|
|
|
self.eline.update_bulk_evc(circuit_ids, metadata) |
76
|
|
|
arg = self.eline.db.evcs.bulk_write.call_args[0][0] |
77
|
|
|
assert len(arg) == 3 |
78
|
|
|
assert self.eline.db.evcs.bulk_write.call_count == 1 |
79
|
|
|
|