File size: 2,552 Bytes
550665c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
72
73
from gcsa.calendar import Calendar, AccessRoles
from tests.google_calendar_tests.test_case_with_mocked_service import TestCaseWithMockedService


class TestCalendarsService(TestCaseWithMockedService):
    def test_get_calendar(self):
        calendar = self.gc.get_calendar()
        self.assertEqual(calendar.id, 'primary')
        self.assertIsInstance(calendar, Calendar)

        calendar = self.gc.get_calendar('1')
        self.assertEqual(calendar.id, '1')

    def test_add_calendar(self):
        calendar = Calendar(
            summary='secondary',
            description='Description secondary',
            location='Location secondary',
            timezone='Timezone secondary',
            allowed_conference_solution_types=[
                AccessRoles.FREE_BUSY_READER,
                AccessRoles.READER
            ]
        )
        new_calendar = self.gc.add_calendar(calendar)

        self.assertIsNotNone(new_calendar.id)
        self.assertEqual(calendar.summary, new_calendar.summary)

    def test_update_calendar(self):
        calendar = Calendar(
            summary='secondary',
            description='Description secondary',
            location='Location secondary',
            timezone='Timezone secondary',
            allowed_conference_solution_types=[
                AccessRoles.FREE_BUSY_READER,
                AccessRoles.READER
            ]
        )
        new_calendar = self.gc.add_calendar(calendar)

        self.assertEqual(calendar.summary, new_calendar.summary)

        new_calendar.summary = 'Updated summary'
        updated_calendar = self.gc.update_calendar(new_calendar)

        self.assertEqual(new_calendar.summary, updated_calendar.summary)

        retrieved_updated_calendar = self.gc.get_calendar(new_calendar.id)
        self.assertEqual(retrieved_updated_calendar.summary, updated_calendar.summary)

    def test_delete_calendar(self):
        calendar = Calendar(
            summary='secondary'
        )

        with self.assertRaises(ValueError):
            # no calendar_id
            self.gc.delete_calendar(calendar)

        new_calendar = self.gc.add_calendar(calendar)
        self.gc.delete_calendar(new_calendar)
        self.gc.delete_calendar('2')

        with self.assertRaises(TypeError):
            # should be a Calendar or calendar id as a string
            self.gc.delete_calendar(None)

    def test_clear_calendar(self):
        self.gc.clear_calendar()
        self.gc.clear()