summaryrefslogtreecommitdiff
path: root/test.py
blob: 5ca77ea3bf93c84530ccee0e7457119fd01b91e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python3
"""Test for the signal event notifier"""

import datetime
import os
import unittest

import signal_event_notifier as sen

DUMMY_CYCLIC_RESPONSIBILITIES = "alice:+1234\nbob:+5678,charlie:+5679"
DUMMY_CYCLIC_RESPONSIBILITIES_3 = "alice:+1234\nbob:+5678\ncharlie:+5679"

TEST_CAL = "test/cal.ics"


# pragma pylint: disable=missing-function-docstring,missing-class-docstring,invalid-name
class TestCyclicRespLoading(unittest.TestCase):

    def setUp(self):
        os.environ[
            sen.RESPONSIBILITIES_ENV_VAR_NAME] = DUMMY_CYCLIC_RESPONSIBILITIES

    def test_cyclic_resp_first_week(self):
        first = datetime.date(year=2013, month=1, day=1)
        resp = sen.load_responsibilities(first)
        self.assertEqual(resp, ['alice:+1234'])

    def test_cyclic_resp_second_week(self):
        second = datetime.date(year=2013, month=1, day=8)
        resp = sen.load_responsibilities(second)
        self.assertEqual(resp, ['bob:+5678', 'charlie:+5679'])

    def test_cyclic_resp_all_weeks(self):
        expected = [['alice:+1234'], ['bob:+5678', 'charlie:+5679']]
        day = datetime.date(year=2013, month=1, day=1)
        delta = datetime.timedelta(days=7)
        for week in range(52 * 2):
            resp = sen.load_responsibilities(day)
            self.assertEqual(resp, expected[(week % 2)])
            day += delta


# pragma pylint: disable=missing-function-docstring,missing-class-docstring,invalid-name
class TestCyclicUnevenRespLoading(unittest.TestCase):

    def setUp(self):
        os.environ[
            sen.
            RESPONSIBILITIES_ENV_VAR_NAME] = DUMMY_CYCLIC_RESPONSIBILITIES_3

    def test_cyclic_resp_all_weeks(self):
        expected = [['alice:+1234'], ['bob:+5678'], ['charlie:+5679']]
        day = datetime.date(year=2013, month=1, day=1)
        delta = datetime.timedelta(days=7)
        for week in range(52):
            resp = sen.load_responsibilities(day)
            self.assertEqual(resp, expected[(week % 3)])
            day += delta

        # Second year
        expected = [['bob:+5678'], ['charlie:+5679'], ['alice:+1234']]
        offset = 1

        for week in range(52):
            resp = sen.load_responsibilities(day, offset=offset)
            self.assertEqual(resp, expected[(week % 3)])
            day += delta


if __name__ == '__main__':
    unittest.main()