def test_get_user_profile(self, authenticate_mock, get_mock): """ Test Get User Profile""" print("Test Get User Profile\n") 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) content = {"displayName": "Tester"} # Test get_mock.return_value = generate_response(content, 200) response = MS_graph_helper.get_user_profile("*****@*****.**") assert response.status_code == 200 assert response.content["displayName"] == "Tester" get_mock.return_value = generate_response(content, 404) response = MS_graph_helper.get_user_profile("*****@*****.**") assert response.status_code == 404 assert response.content["displayName"] == "Tester" get_mock.return_value = generate_response(content, 300) response = MS_graph_helper.get_user_profile("*****@*****.**") except IntegrationError as err: assert True
def _exchange_online_get_email_user_profile_function( self, event, *args, **kwargs): """Function: This function will get Exchange Online user profile for a given email address.""" try: # Initialize the results payload rp = ResultPayload(CONFIG_DATA_SECTION, **kwargs) # Validate fields validate_fields(['exo_email_address'], kwargs) # Get the function parameters email_address = kwargs.get('exo_email_address') # text LOG.info(u"exo_email_address: %s", email_address) yield StatusMessage( u"Starting user profile query for email address: {}".format( email_address)) # Get the MS Graph helper class # 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"), RequestsCommon(self.opts, self.options).get_proxies()) # Call MS Graph API to get the user profile response = MS_graph_helper.get_user_profile(email_address) response_json = response.json() results = rp.done(True, response_json) # Add pretty printed string for easier to read output text in note. pretty_string = json.dumps(response_json, ensure_ascii=False, sort_keys=True, indent=4, separators=(',', ': ')) results['pretty_string'] = pretty_string yield StatusMessage( u"Returning user profile 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)