diff --git a/O365/message.py b/O365/message.py index 03e4ff6920e0..aba51d869c2f 100644 --- a/O365/message.py +++ b/O365/message.py @@ -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. @@ -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'] diff --git a/tests/test_message.py b/tests/test_message.py index 478ac85650cd..410ae973e115 100644 --- a/tests/test_message.py +++ b/tests/test_message.py @@ -58,7 +58,7 @@ def post(url,data,headers,auth): else: return Resp(None,202) - + message.requests.post = post @@ -72,7 +72,7 @@ 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 @@ -80,7 +80,7 @@ def patch(url,data,headers,auth): 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) @@ -88,7 +88,7 @@ def setUp(self): 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): @@ -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) @@ -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')