Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
language: python
python:
- "3.5"
- "3.6"

install: pip install -r requirements-dev.txt

- '3.5'
- '3.6'
install:
- pip install -r requirements-dev.txt
- python setup.py install
script: pytest

deploy:
provider: pypi
user: O365
password:
secure: Lbz3GiQvV5Kzzn79wI/sEMR1bysZNPONekp3TrlJ6PLNKGYaAz3HurBqvDQ0IlAKsnRVch4kjB1FXgEx20dhuGznBooSfe9JoXGEWox7zprsZOHYq9iD4Q1Ay8Q24IEtK7Ey+g+zb2Mj6DsMhafaPMuHS6uWQNdvRSPCNvONOjUtv4w54Jk8UViZvffLaZocn17/+qOjS+Z0ZDyj7NiMh4gDJmKHayE3WgF88wv7TTtikTCQ4+yBHkYhYmqp4lzMcJfM++XscGHhv/dKiUnDvd8ig+KqqSEevIOBylQy3M5ApT3u4khS9tv57yq+nowJ8ddtz0+TAr5Sjm4TBMYjOMl6X7hEvoXY40s3RL7IongyF/zTZgUk2VuAVPE9OUXwDeOWFqu1CP/RYEQxgxEMyCakhsEGcIS8eT/1DROxgvAvNX8kq2f/WPWmKgNoanbNO+0TAvzqdPhzNjL0NcpwUz+0FE24m00iroRJkU0IlFJosx4TvXh+Jb6ihUA+yCdjOzLu0GAPXP8oKkJ4rj7/2qwh4w/5AvtmYMc0XA0w2VSNQxJpBkpieZ2z13oUbrrjLtEhmyuJFKAhsU0va+l853xInbL4pQzCzodb36R+FCihEOonaFORkEATtltYG98T3DmhzFu40dvd2+1lIHPkLhvBBuR5iFR+tqjkVFTcS8o=
on:
tags: true
24 changes: 24 additions & 0 deletions release.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,30 @@ def check():

subprocess.check_call(['twine', 'check', 'dist/*'])

@cli.command()
@click.option('--annotate/--no-annotate',default=False)
@click.option('--coverage/--no-coverage',default=False)
@click.option('-v/-nv',default=False)
@click.option('-vv/-nvv',default=False)
def test(annotate,coverage,v,vv):
""" runs tests and optionally creates annotated files of coverage. """
args = ["python3","-m","pytest","tests/"]
if coverage:
args.append("--cov=O365")
if annotate:
args.append("--cov-report")
args.append("annotate")
if v:#Verbose
args.append("-v")
if vv and not v:#Very verbose
args.append("-vv")

env = os.environ.copy()

p = subprocess.Popen(args,env=env)

p.wait()


if __name__ == "__main__":
cli()
16 changes: 16 additions & 0 deletions tests/test_account.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from O365 import Account
from O365 import Message


class TestAccount:

def setup_class(self):
credentials = ("client id","client secret")
self.account = Account(credentials)

def teardown_class(self):
pass

def test_get_message(self):
message = self.account.new_message()
assert isinstance(message,Message)
18 changes: 18 additions & 0 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import pytest
import json

from O365.connection import Connection, Protocol, MSGraphProtocol, MSOffice365Protocol, DEFAULT_SCOPES


class TestConnection:

def setup_class(self):
pass

def teardown_class(self):
pass

def test_blank_connection(self):
with pytest.raises(TypeError):
c1 = Connection()

25 changes: 23 additions & 2 deletions tests/test_mailbox.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
#from O365 import Account
from O365 import Account
import json

class MockConnection:

ret_value = None

def get(self, url, params=None, **kwargs):
self.url = url
self.kwargs = kwargs

class TestMailBox:

def setup_class(self):
pass
credentials = ("client id","client secret")
self.account = Account(credentials)
self.mailbox = self.account.mailbox()
self.mailbox.con = MockConnection()

def teardown_class(self):
pass

def test_mailbox(self):
assert self.mailbox.root

# def test_get_mailbox_folders(self):
# self.mailbox.con.ret_value = ['Inbox','Drafts']
#
# folders = self.mailbox.get_folders(limit=5)
#
# assert len(folders) > 0
2 changes: 1 addition & 1 deletion tests/test_message.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pathlib import Path
#from O365 import Account
from O365 import Account

class TestMessage:

Expand Down
74 changes: 74 additions & 0 deletions tests/test_protocol.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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)