def test_with_display_name(self, mocker): """ Given: - An app client object - A scim argument that contains a displayName of a group When: - The group exists in the application - Calling the main function with 'iam-get-group' command Then: - Ensure the resulted 'CommandResults' object holds the correct group details """ client = mock_client() args = {"scim": "{\"displayName\": \"The group name\"}"} mock_result = mocker.patch('AWSILM.CommandResults') with requests_mock.Mocker() as m: m.get(f'{groupUri}', json={ 'totalResults': 1, 'Resources': [APP_GROUP_OUTPUT] }) get_group_command(client, args) assert mock_result.call_args.kwargs['outputs'][ 'details'] == APP_GROUP_OUTPUT
def test_non_existing_group(self, mocker): """ Given: - An app client object - A scim argument that contains an ID and displayName of a non_existing group When: - The group not exists in the application - Calling the main function with 'iam-get-group' command Then: - Ensure the resulted 'CommandResults' object holds information about an unsuccessful result. """ client = mock_client() args = { "scim": "{\"id\": \"1234\", \"displayName\": \"The group name\"}" } mock_result = mocker.patch('AWSILM.CommandResults') with requests_mock.Mocker() as m: m.get(f'{groupUri}1234', status_code=404, text='Group Not Found') get_group_command(client, args) assert mock_result.call_args.kwargs['outputs']['errorCode'] == 404 assert mock_result.call_args.kwargs['outputs'][ 'errorMessage'] == 'Group Not Found'
def test_with_id(self, mocker): client = mock_client() args = { "scim": "{\"id\": \"1234\", \"displayName\": \"The group name\"}" } mock_result = mocker.patch('AWSILM.CommandResults') with requests_mock.Mocker() as m: # m.get(groupUri, json={'total_results': 1, 'Resources': [APP_GROUP_OUTPUT]}) m.get(f'{groupUri}1234', json=APP_GROUP_OUTPUT) get_group_command(client, args) assert mock_result.call_args.kwargs['outputs'][ 'details'] == APP_GROUP_OUTPUT
def test_id_and_display_name_empty(self): """ Given: - An app client object - A scim argument that not contains an ID and displayName of a group When: - Calling the main function with 'iam-get-group' command Then: - Ensure that an error is raised with an expected message. """ client = mock_client() args = {"scim": "{}"} with pytest.raises(Exception) as e: get_group_command(client, args) assert str( e.value ) == 'You must supply either "id" or "displayName" in the scim data'