forked from O365/python-o365
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_protocol.py
More file actions
74 lines (50 loc) · 3.15 KB
/
Copy pathtest_protocol.py
File metadata and controls
74 lines (50 loc) · 3.15 KB
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
import pytest
import json
from pytz import UnknownTimeZoneError
from tzlocal import get_localzone
from O365.connection import Connection, Protocol, MSGraphProtocol, MSOffice365Protocol, DEFAULT_SCOPES
TEST_SCOPES = ['Contacts.Read.Shared', 'Mail.Send.Shared', 'User.Read', 'Contacts.ReadWrite.Shared', 'Mail.ReadWrite.Shared', 'Mail.Read.Shared', 'Contacts.Read', 'Sites.ReadWrite.All', 'Mail.Send', 'Mail.ReadWrite', 'offline_access', 'Mail.Read', 'Contacts.ReadWrite', 'Files.ReadWrite.All', 'Calendars.ReadWrite', 'User.ReadBasic.All']
class TestProtocol:
def setup_class(self):
self.proto = Protocol(protocol_url="testing", api_version="0.0")
def teardown_class(self):
pass
def test_blank_protocol(self):
with pytest.raises(ValueError):
p = Protocol()
def test_to_api_case(self):
assert(self.proto.to_api_case("CaseTest") == "case_test")
def test_get_scopes_for(self):
with pytest.raises(ValueError):
self.proto.get_scopes_for(123) # should error sicne it's not a list or tuple.
assert(self.proto.get_scopes_for(['mailbox']) == ['mailbox'])
assert(self.proto.get_scopes_for(None) == [])
assert(self.proto.get_scopes_for('mailbox') == ['mailbox'])
self.proto._oauth_scopes = DEFAULT_SCOPES
assert(self.proto.get_scopes_for(['mailbox']) == ['Mail.Read'])
# This test verifies that the scopes in the default list don't change
#without us noticing. It makes sure that all the scopes we get back are
#in the current set of scopes we expect. And all the scopes that we are
#expecting are in the scopes we are getting back. The list contains the
#same stuff but may not be in the same order and are therefore not equal
scopes = self.proto.get_scopes_for(None)
for scope in scopes:
assert(scope in TEST_SCOPES)
for scope in TEST_SCOPES:
assert(scope in scopes)
assert(self.proto.get_scopes_for('mailbox') == ['Mail.Read'])
def test_prefix_scope(self):
assert(self.proto.prefix_scope('Mail.Read') == 'Mail.Read')
assert(self.proto.prefix_scope(('Mail.Read',)) == 'Mail.Read')
self.proto.protocol_scope_prefix = 'test_prefix_'
assert(self.proto.prefix_scope(('Mail.Read',)) == 'Mail.Read')
assert(self.proto.prefix_scope('test_prefix_Mail.Read') == 'test_prefix_Mail.Read')
assert(self.proto.prefix_scope('Mail.Read') == 'test_prefix_Mail.Read')
def test_decendant_MSOffice365Protocol(self):
# Basically we just test that it can create the class w/o erroring.
msp = MSOffice365Protocol()
# Make sure these don't change without going noticed.
assert(msp.keyword_data_store['message_type'] == 'Microsoft.OutlookServices.Message')
assert(msp.keyword_data_store['file_attachment_type'] == '#Microsoft.OutlookServices.FileAttachment')
assert(msp.keyword_data_store['item_attachment_type'] == '#Microsoft.OutlookServices.ItemAttachment')
assert(msp.max_top_value == 999)