-
Notifications
You must be signed in to change notification settings - Fork 0
/
CalendarTestSearchEvents.py
76 lines (59 loc) · 2.27 KB
/
CalendarTestSearchEvents.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
import unittest
from unittest.mock import Mock, patch
import Calendar
# NOTE: ALL THE TESTS HERE ARE FOR THE get_searched_events METHOD IN Calendar.py
# Test Strategy : Path Coverage
class CalenderTestSearchEvents(unittest.TestCase):
@patch("Calendar.get_calendar_api")
def test_none_event_query(self, api):
query = None
with self.assertRaises(TypeError):
Calendar.get_searched_events(api, query)
@patch("Calendar.get_calendar_api")
def test_empty_event_query(self, api):
query = ""
with self.assertRaises(ValueError):
Calendar.get_searched_events(api, query)
query = " "
with self.assertRaises(ValueError):
Calendar.get_searched_events(api, query)
def test_no_events(self):
query = "John"
api = Mock()
api.events.return_value.list.return_value.execute.return_value = {}
events = Calendar.get_searched_events(api, query)
self.assertEqual(events, "")
def test_events_found(self):
query = "testing this string"
api = Mock()
api.events.return_value.list.return_value.execute.return_value = {
"items": [
{
"summary": query,
"description": "ok",
"start": {
"dateTime": "2020-06-10T02:00:00.000000Z"
},
"end": {
"dateTime": "2020-06-10T02:45:00.000000Z"
},
},
{
"summary": "Hello World",
"description": query,
"start": {
"dateTime": "2020-06-10T02:00:00.000000Z"
},
"end": {
"dateTime": "2020-06-10T02:45:00.000000Z"
},
},
]}
searched_events = Calendar.get_searched_events(api, query)
self.assertEqual(api.events.return_value.list.return_value.execute.call_count, 1)
self.assertIn(query, searched_events)
def main():
suite = unittest.TestLoader().loadTestsFromTestCase(CalenderTestSearchEvents)
# This will run the test suite.
unittest.TextTestRunner(verbosity=2).run(suite)
main()