-
Notifications
You must be signed in to change notification settings - Fork 0
/
CalendarTestSearchReminders.py
85 lines (64 loc) · 2.65 KB
/
CalendarTestSearchReminders.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
82
83
84
85
import unittest
from unittest.mock import Mock, patch
import Calendar
# NOTE: ALL THE TESTS HERE ARE FOR THE get_searched_reminders METHOD IN Calendar.py
# Test Strategy : Path Coverage
class CalenderTestSearchReminders(unittest.TestCase):
@patch("Calendar.get_calendar_api")
def test_none_reminder_query(self, api):
query = None
with self.assertRaises(TypeError):
Calendar.get_searched_reminders(api, query)
@patch("Calendar.get_calendar_api")
def test_empty_reminder_query(self, api):
query = ""
with self.assertRaises(ValueError):
Calendar.get_searched_reminders(api, query)
query = " "
with self.assertRaises(ValueError):
Calendar.get_searched_reminders(api, query)
def test_no_reminders(self):
api = Mock()
api.events.return_value.list.return_value.execute.return_value = {}
query = "John"
reminders = Calendar.get_searched_reminders(api, query)
self.assertEqual(reminders, "")
def test_reminders_found(self):
query = "testing this string"
api = Mock()
api.events.return_value.list.return_value.execute.return_value = {
"items": [
{
"summary": query,
"reminders": {
'useDefault': False,
'overrides': [
{'method': 'email', 'minutes': 1},
{'method': 'popup', 'minutes': 10},
], },
},
]}
reminders = Calendar.get_searched_reminders(api, query)
self.assertEqual(api.events.return_value.list.return_value.execute.call_count, 1)
self.assertIn("email 1", reminders)
self.assertIn("popup 10", reminders)
def test_reminders_found_default(self):
query = "testing this string"
api = Mock()
api.events.return_value.list.return_value.execute.return_value = {
"items": [
{
"summary": query,
"reminders": {
'useDefault': True,
'overrides': [], },
},
]}
reminders = Calendar.get_searched_reminders(api, query)
self.assertEqual(api.events.return_value.list.return_value.execute.call_count, 1)
self.assertEqual(reminders, query + ",Reminder through popup 10 minutes before event starts\n")
def main():
suite = unittest.TestLoader().loadTestsFromTestCase(CalenderTestSearchReminders)
# This will run the test suite.
unittest.TextTestRunner(verbosity=2).run(suite)
main()