alert-autoconf

Форк
0
/
test_subscription.py 
80 строк · 2.6 Кб
1
from unittest import TestCase
2

3
from alert_autoconf.moira import MoiraAlert
4

5

6
def _make_sub(**kwargs):
7
    sub = {
8
        'tags': [],
9
        'contacts': [],
10
        'escalations': [],
11
        'sched': {'startOffset': 0, 'endOffset': 1439, 'tzOffset': 0, 'days': []},
12
    }
13
    sub.update(**kwargs)
14
    return sub
15

16

17
def _make_esc(offset=10, contacts=None):
18
    return {'contacts': contacts or [], 'offset_in_minutes': offset}
19

20

21
class SubscriptionCmpTest(TestCase):
22
    def test_two_empty(self):
23
        s1 = _make_sub()
24
        s2 = _make_sub()
25
        r = MoiraAlert._subscription_not_changed(s1, s2)
26
        self.assertTrue(r)
27

28
    def test_tags_changed(self):
29
        s1 = _make_sub(tags=['t1'])
30
        s2 = _make_sub()
31
        r = MoiraAlert._subscription_not_changed(s1, s2)
32
        self.assertFalse(r)
33

34
    def test_tags_equal(self):
35
        s1 = _make_sub(tags=['t1', 't2'])
36
        s2 = _make_sub(tags=['t1', 't2'])
37
        r = MoiraAlert._subscription_not_changed(s1, s2)
38
        self.assertTrue(r)
39

40
    def test_contacts_equal(self):
41
        s1 = _make_sub(contacts=['c1', 'c2'])
42
        s2 = _make_sub(contacts=['c1', 'c2'])
43
        r = MoiraAlert._subscription_not_changed(s1, s2)
44
        self.assertTrue(r)
45

46
    def test_tags_and_contacts_equal(self):
47
        s1 = _make_sub(contacts=['c1', 'c2'], tags=['t1'])
48
        s2 = _make_sub(contacts=['c1', 'c2'], tags=['t1'])
49
        r = MoiraAlert._subscription_not_changed(s1, s2)
50
        self.assertTrue(r)
51

52
    def test_tags_and_contacts_not_equal(self):
53
        s1 = _make_sub(contacts=['z1', 'c2'], tags=['t1'])
54
        s2 = _make_sub(contacts=['c1', 'c2'], tags=['t1'])
55
        r = MoiraAlert._subscription_not_changed(s1, s2)
56
        self.assertFalse(r)
57

58
    def test_escalations_empty(self):
59
        s1 = _make_sub(escalations=[_make_esc()])
60
        s2 = _make_sub(escalations=[_make_esc()])
61
        r = MoiraAlert._subscription_not_changed(s1, s2)
62
        self.assertTrue(r)
63

64
    def test_escalations_diff_offsets(self):
65
        s1 = _make_sub(escalations=[_make_esc(20)])
66
        s2 = _make_sub(escalations=[_make_esc()])
67
        r = MoiraAlert._subscription_not_changed(s1, s2)
68
        self.assertFalse(r)
69

70
    def test_escalations_order(self):
71
        s1 = _make_sub(escalations=[_make_esc(20), _make_esc(10)])
72
        s2 = _make_sub(escalations=[_make_esc(10), _make_esc(20)])
73
        r = MoiraAlert._subscription_not_changed(s1, s2)
74
        self.assertTrue(r)
75

76
    def test_escalations_contacts_order(self):
77
        s1 = _make_sub(escalations=[_make_esc(contacts=['1', '2'])])
78
        s2 = _make_sub(escalations=[_make_esc(contacts=['2', '1'])])
79
        r = MoiraAlert._subscription_not_changed(s1, s2)
80
        self.assertTrue(r)
81

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.