Skip to content

Commit

Permalink
Merge pull request googleapis#95 from hellbe/master
Browse files Browse the repository at this point in the history
Add message methods for categories

Thank you.
  • Loading branch information
Narcolapser authored May 2, 2018
2 parents 4b707d6 + b75eab7 commit fa28547
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
17 changes: 17 additions & 0 deletions O365/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class Message(object):
fetchAttachments -- kicks off the process that downloads attachments.
sendMessage -- take local variables and form them to send the message.
markAsRead -- marks the analougs message in the cloud as read.
setCategories -- sets the list of categories in the cloud
getCategories -- gets the email's categories
getSender -- gets a dictionary with the sender's information.
getSenderEmail -- gets the email address of the sender.
getSenderName -- gets the name of the sender, if possible.
Expand Down Expand Up @@ -128,6 +130,21 @@ def markAsRead(self):
return False
return True

def setCategories(self, categories=""):
'''sets message categories in the cloud.'''
categories = json.dumps(dict(Categories=categories))
headers = {'Content-type': 'application/json', 'Accept': 'application/json'}
try:
response = requests.patch(self.update_url.format(
self.json['Id']), categories, headers=headers, auth=self.auth,verify=self.verify)
except:
return False
return True

def getCategories(self):
'''gets the message's categories'''
return self.json['Categories']

def getSender(self):
'''get all available information for the sender of the email.'''
return self.json['Sender']
Expand Down
13 changes: 8 additions & 5 deletions tests/test_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def post(url,data,headers,auth):
else:
return Resp(None,202)



message.requests.post = post

Expand All @@ -72,23 +72,23 @@ def patch(url,data,headers,auth):
if headers['Content-type'] != 'application/json':
raise
if headers['Accept'] != 'application/json':
raise
raise
return True

message.requests.patch = patch

auth = ('test@unit.com','pass')

class TestMessage (unittest.TestCase):

def setUp(self):
ur = json.loads(un_rep)['value'][0]
self.unread = message.Message(ur,auth)
re = json.loads(read_rep)['value'][0]
self.read = message.Message(re,auth)
att = json.loads(att_m_rep)['value'][0]
self.att = message.Message(att,auth)

self.newm = message.Message(auth=auth)

def test_fetchAttachments(self):
Expand Down Expand Up @@ -117,6 +117,9 @@ def test_sendMessage(self):
def test_markAsRead(self):
self.unread.markAsRead()

def test_setCategories(self):
self.unread.setCategories(["Green", "Yellow"])

def test_setRecipients(self):
self.assertTrue(len(self.read.json['ToRecipients']) == 1)
self.assertTrue(len(self.unread.json['ToRecipients']) == 1)
Expand All @@ -125,7 +128,7 @@ def test_setRecipients(self):
self.read.setRecipients('bob@unit.com')
self.assertTrue(self.read.json['ToRecipients'][0]['EmailAddress']['Address'] == 'bob@unit.com')

self.unread.setRecipients({'EmailAddress':{'Address':'bob@unit.com','Name':'What about'}})
self.unread.setRecipients({'EmailAddress':{'Address':'bob@unit.com','Name':'What about'}})
self.assertTrue(self.unread.json['ToRecipients'][0]['EmailAddress']['Address'] == 'bob@unit.com')
self.assertTrue(self.unread.json['ToRecipients'][0]['EmailAddress']['Name'] == 'What about')

Expand Down

0 comments on commit fa28547

Please sign in to comment.