forked from O365/python-o365
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_event.py
111 lines (86 loc) · 2.97 KB
/
test_event.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
from O365 import event
import unittest
import json
import time
class Calendar:
'''mock up calendar class'''
def __init__(self,json,auth):
self.json = json
self.auth = auth
self.calendarId = json['Id']
class Resp:
def __init__(self,json_string):
self.jsons = json_string
def json(self):
return json.loads(self.jsons)
event_rep = open('events.json','r').read()
events_json = json.loads(event_rep)
lough = events_json['value'][0]
oughter = events_json['value'][1]
t_string = '%Y-%m-%dT%H:%M:%SZ'
urls = ['https://outlook.office365.com/api/v1.0/me/events/bigolguid=',
'https://outlook.office365.com/api/v1.0/me/events/otherguid']
def delete(url,headers,auth):
if url not in urls:
raise BaseException('Url wrong')
if auth[0] != '[email protected]':
raise BaseException('wrong email')
if auth[1] != 'pass':
raise BaseException('wrong password')
if headers['Content-type'] != 'application/json':
raise BaseException('header wrong value for content-type.')
if headers['Accept'] != 'text/plain':
raise BaseException('header accept wrong.')
return True
event.requests.delete = delete
def post(url,data,headers,auth):
if url != 'https://outlook.office365.com/api/v1.0/me/calendars/0/events':
raise BaseException('Url wrong')
if auth[0] != '[email protected]':
raise BaseException('wrong email')
if auth[1] != 'pass':
raise BaseException('wrong password')
if headers['Content-type'] != 'application/json':
raise BaseException('header wrong value for content-type.')
if headers['Accept'] != 'application/json':
raise BaseException('header accept wrong.')
if json.loads(data) != lough and json.loads(data) != oughter:
raise BaseException('data is wrong.')
return Resp(data)
event.requests.post = post
def patch(url,data,headers,auth):
if url not in urls:
raise BaseException('Url wrong')
if auth[0] != '[email protected]':
raise BaseException('wrong email')
if auth[1] != 'pass':
raise BaseException('wrong password')
if headers['Content-type'] != 'application/json':
raise BaseException('header wrong value for content-type.')
if headers['Accept'] != 'application/json':
raise BaseException('header accept wrong.')
return Resp(data)
event.requests.patch = patch
auth = ('[email protected]','pass')
cal_json = {'Id':0}
cal = Calendar(cal_json,auth)
class TestInbox (unittest.TestCase):
def setUp(self):
self.lough = event.Event(lough,auth,cal)
self.oughter = event.Event(oughter,auth,cal)
def test_create(self):
self.assertTrue(self.lough.create())
self.assertTrue(self.oughter.create())
def test_update(self):
self.assertTrue(self.lough.update())
self.assertTrue(self.oughter.update())
def test_delete(self):
self.assertTrue(self.lough.delete())
self.assertTrue(self.oughter.delete())
def test_auth(self):
self.assertEqual('[email protected]',self.lough.auth[0])
self.assertEqual('pass',self.lough.auth[1])
self.assertEqual('[email protected]',self.oughter.auth[0])
self.assertEqual('pass',self.oughter.auth[1])
if __name__ == '__main__':
unittest.main()