-
Notifications
You must be signed in to change notification settings - Fork 0
/
CalendarTestGetDetailedReminder.py
81 lines (70 loc) · 2.82 KB
/
CalendarTestGetDetailedReminder.py
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
74
75
76
77
78
79
80
81
from datetime import datetime
import unittest
from unittest.mock import Mock, patch
import Calendar
# NOTE: ALL THE TESTS HERE ARE FOR THE get_detailed_remidner METHOD IN Calendar.py
# Test Strategy : Branch Coverage
class CalendarTestGetDetailedReminders(unittest.TestCase):
def test_get_detailed_reminders_raise_value_error(self):
event = {
'irrelevant': "nonsense"
}
with self.assertRaises(ValueError):
Calendar.get_detailed_reminders(event)
def test_get_detailed_reminders_path2_two_custom_reminders(self):
#below is an example of json string returned
event = {
"summary": "test",
"start": {
"dateTime": "2020-10-03T02:00:00.000000Z"
},
"end": {
"dateTime": "2020-10-03T02:45:00.000000Z"
}, "reminders": {
'useDefault': False,
'overrides': [
{'method': 'email', 'minutes': 1},
{'method': 'popup', 'minutes': 10},
], },
}
reminders = Calendar.get_detailed_reminders(event)
self.assertIn("email 1", reminders) #Assert reminders detail is returned
self.assertIn("popup 10", reminders) #Assert reminders detail is returned
def test_get_detailed_reminders_path3_no_reminder_set(self):
event = {
"summary": "test",
"start": {
"dateTime": "2020-10-03T02:00:00.000000Z"
},
"end": {
"dateTime": "2020-10-03T02:45:00.000000Z"
}, "reminders": {
'useDefault': False,
'overrides': [
], },
}
reminders = Calendar.get_detailed_reminders(event)
self.assertEqual(reminders, "\n") # A newline is returned due to the outer for loop being executed
def test_get_detailed_reminders_path4_default_reminder(self):
# Path 5 where if statement to check date validity succeeds, outer for loop is executed, and if
# branch is executed which is default reminders
event = {
"summary": "test",
"start": {
"dateTime": "2020-10-03T02:00:00.000000Z"
},
"end": {
"dateTime": "2020-10-03T02:45:00.000000Z"
}, "reminders": {
'useDefault': True,
'overrides': [
], },
}
reminders = Calendar.get_detailed_reminders(event)
self.assertEqual(reminders, "test,Reminder through popup 10 minutes before event starts\n")
#String for default reminders
def main():
suite = unittest.TestLoader().loadTestsFromTestCase(CalendarTestGetDetailedReminders)
# This will run the test suite.
unittest.TextTestRunner(verbosity=2).run(suite)
main()