def test_delete_message(self, authenticate_mock, delete_mock): """ Test """ print("Test Delete Message\n") content = {"displayName": "Tester"} try: authenticate_mock.return_value = True MS_graph_helper = MSGraphHelper( MOCKED_OPTS.get("microsoft_graph_token_url"), MOCKED_OPTS.get("microsoft_graph_url"), MOCKED_OPTS.get("tenant_id"), MOCKED_OPTS.get("client_id"), MOCKED_OPTS.get("client_secret"), MOCKED_OPTS.get("max_messages"), MOCKED_OPTS.get("max_users"), MOCKED_OPTS.get("max_retries_total"), MOCKED_OPTS.get("max_retries_backoff_factor"), MOCKED_OPTS.get("max_batched_requests"), None) delete_mock.return_value = generate_response(content, 204) response = MS_graph_helper.delete_message("*****@*****.**", None, "AAAA") assert response.status_code == 204 delete_mock.return_value = generate_response(content, 300) response = MS_graph_helper.delete_message("*****@*****.**", None, "AAAA") except IntegrationError as err: assert True
def _exchange_online_delete_email_function(self, event, *args, **kwargs): """Function: Delete a message in the specified user's mailbox.""" try: # Initialize the results payload rp = ResultPayload(CONFIG_DATA_SECTION, **kwargs) # Validate fields validate_fields(['exo_email_address', 'exo_messages_id'], kwargs) # Get the function parameters email_address = kwargs.get('exo_email_address') # text mailfolders_id = kwargs.get('exo_mailfolders_id') # text messages_id = kwargs.get('exo_messages_id') # text LOG.info(u"exo_email_address: %s", email_address) LOG.info(u"exo_mailfolders_id: %s", mailfolders_id) LOG.info(u"exo_messages_id: %s", messages_id) yield StatusMessage( u"Starting delete message for email address: {}".format( email_address)) # Get the MS Graph helper class MS_graph_helper = MSGraphHelper( self.options.get("microsoft_graph_token_url"), self.options.get("microsoft_graph_url"), self.options.get("tenant_id"), self.options.get("client_id"), self.options.get("client_secret"), self.options.get("max_messages"), self.options.get("max_users"), self.options.get("max_retries_total", MAX_RETRIES_TOTAL), self.options.get("max_retries_backoff_factor", MAX_RETRIES_BACKOFF_FACTOR), self.options.get("max_batched_requests", MAX_BATCHED_REQUESTS), RequestsCommon(self.opts, self.options).get_proxies()) # Call MS Graph API to get the user profile response = MS_graph_helper.delete_message(email_address, mailfolders_id, messages_id) # If message was deleted a 204 code is returned. if response.status_code == 204: success = True response_json = {'value': success} else: success = False response_json = response.json() results = rp.done(success, response_json) yield StatusMessage( u"Returning delete results for email address: {}".format( email_address)) # Produce a FunctionResult with the results yield FunctionResult(results) except Exception as err: LOG.error(err) yield FunctionError(err)