def test_get_user_command_404_response(mocker): """ Given: - The get_user_command When: - The returned response is a 404 - not found error. Then: - Validate that the error is handled and that the human readable indicates an error. """ from MicrosoftGraphUser import MsGraphClient, get_user_command from MicrosoftApiModule import MicrosoftClient, BaseClient from requests.models import Response client = MsGraphClient('tenant_id', 'auth_id', 'enc_key', 'app_name', 'base_url', 'verify', 'proxy', 'self_deployed', 'redirect_uri', 'auth_code', True) error_404 = Response() error_404._content = b'{"error": {"code": "Request_ResourceNotFound", "message": "Resource ' \ b'"NotExistingUser does not exist."}}' error_404.status_code = 404 mocker.patch.object(BaseClient, '_http_request', return_value=error_404) mocker.patch.object(MicrosoftClient, 'get_access_token') hr, _, _ = get_user_command( client, {'user': '******'}) # client.get_user('user', 'properties') assert 'User NotExistingUser was not found' in hr
def test_get_user_command_url_saved_chars(mocker): """ Given: - The get_user_command When: - The returned response is a 404 - not found error. Then: - Validate that the error is handled and that the human readable indicates an error. """ from MicrosoftGraphUser import MsGraphClient, get_user_command from MicrosoftApiModule import MicrosoftClient, BaseClient user_name = "dbot^" client = MsGraphClient('tenant_id', 'auth_id', 'enc_key', 'app_name', 'http://base_url', 'verify', 'proxy', 'self_deployed', 'redirect_uri', 'auth_code', False) http_mock = mocker.patch.object(BaseClient, '_http_request') mocker.patch.object(MicrosoftClient, 'get_access_token') hr, _, _ = get_user_command(client, {'user': user_name}) assert 'users/dbot%5E' == http_mock.call_args[1]["url_suffix"]