alert-autoconf
80 строк · 2.6 Кб
1from unittest import TestCase
2
3from alert_autoconf.moira import MoiraAlert
4
5
6def _make_sub(**kwargs):
7sub = {
8'tags': [],
9'contacts': [],
10'escalations': [],
11'sched': {'startOffset': 0, 'endOffset': 1439, 'tzOffset': 0, 'days': []},
12}
13sub.update(**kwargs)
14return sub
15
16
17def _make_esc(offset=10, contacts=None):
18return {'contacts': contacts or [], 'offset_in_minutes': offset}
19
20
21class SubscriptionCmpTest(TestCase):
22def test_two_empty(self):
23s1 = _make_sub()
24s2 = _make_sub()
25r = MoiraAlert._subscription_not_changed(s1, s2)
26self.assertTrue(r)
27
28def test_tags_changed(self):
29s1 = _make_sub(tags=['t1'])
30s2 = _make_sub()
31r = MoiraAlert._subscription_not_changed(s1, s2)
32self.assertFalse(r)
33
34def test_tags_equal(self):
35s1 = _make_sub(tags=['t1', 't2'])
36s2 = _make_sub(tags=['t1', 't2'])
37r = MoiraAlert._subscription_not_changed(s1, s2)
38self.assertTrue(r)
39
40def test_contacts_equal(self):
41s1 = _make_sub(contacts=['c1', 'c2'])
42s2 = _make_sub(contacts=['c1', 'c2'])
43r = MoiraAlert._subscription_not_changed(s1, s2)
44self.assertTrue(r)
45
46def test_tags_and_contacts_equal(self):
47s1 = _make_sub(contacts=['c1', 'c2'], tags=['t1'])
48s2 = _make_sub(contacts=['c1', 'c2'], tags=['t1'])
49r = MoiraAlert._subscription_not_changed(s1, s2)
50self.assertTrue(r)
51
52def test_tags_and_contacts_not_equal(self):
53s1 = _make_sub(contacts=['z1', 'c2'], tags=['t1'])
54s2 = _make_sub(contacts=['c1', 'c2'], tags=['t1'])
55r = MoiraAlert._subscription_not_changed(s1, s2)
56self.assertFalse(r)
57
58def test_escalations_empty(self):
59s1 = _make_sub(escalations=[_make_esc()])
60s2 = _make_sub(escalations=[_make_esc()])
61r = MoiraAlert._subscription_not_changed(s1, s2)
62self.assertTrue(r)
63
64def test_escalations_diff_offsets(self):
65s1 = _make_sub(escalations=[_make_esc(20)])
66s2 = _make_sub(escalations=[_make_esc()])
67r = MoiraAlert._subscription_not_changed(s1, s2)
68self.assertFalse(r)
69
70def test_escalations_order(self):
71s1 = _make_sub(escalations=[_make_esc(20), _make_esc(10)])
72s2 = _make_sub(escalations=[_make_esc(10), _make_esc(20)])
73r = MoiraAlert._subscription_not_changed(s1, s2)
74self.assertTrue(r)
75
76def test_escalations_contacts_order(self):
77s1 = _make_sub(escalations=[_make_esc(contacts=['1', '2'])])
78s2 = _make_sub(escalations=[_make_esc(contacts=['2', '1'])])
79r = MoiraAlert._subscription_not_changed(s1, s2)
80self.assertTrue(r)
81