Beispiel #1
0
def test_create_user_command__success(mocker):
    """
    Given:
        - An Okta IAM client object
        - A user-profile argument that contains an email of a non-existing user in Okta
    When:
        - Calling function create_user_command
    Then:
        - Ensure a User Profile object with the user data is returned
    """
    client = mock_client()
    args = {'user-profile': {'email': '*****@*****.**'}}

    mocker.patch.object(client, 'get_user', return_value=None)
    mocker.patch.object(IAMUserProfile, 'map_object', return_value={})
    mocker.patch.object(client, 'create_user', return_value=OKTA_USER_OUTPUT)

    user_profile = create_user_command(client,
                                       args,
                                       'mapper_out',
                                       is_command_enabled=True,
                                       is_update_user_enabled=True)
    outputs = get_outputs_from_user_profile(user_profile)

    assert outputs.get('action') == IAMActions.CREATE_USER
    assert outputs.get('success') is True
    assert outputs.get('active') is True
    assert outputs.get('id') == 'mock_id'
    assert outputs.get('username') == '*****@*****.**'
    assert outputs.get('details',
                       {}).get('profile',
                               {}).get('firstName') == 'mock_first_name'
    assert outputs.get('details',
                       {}).get('profile',
                               {}).get('lastName') == 'mock_last_name'
Beispiel #2
0
def test_create_user_command__user_already_exists(mocker):
    """
    Given:
        - An Okta IAM client object
        - A user-profile argument that contains an email of a user
    When:
        - The user already exists in Okta
        - Calling function create_user_command
    Then:
        - Ensure the command is considered successful and skipped
    """
    client = mock_client()
    args = {'user-profile': {'email': '*****@*****.**'}}

    mocker.patch.object(client, 'get_user', return_value=OKTA_USER_OUTPUT)

    user_profile = create_user_command(client,
                                       args,
                                       'mapper_out',
                                       is_command_enabled=True)
    outputs = get_outputs_from_user_profile(user_profile)

    assert outputs.get('action') == IAMActions.CREATE_USER
    assert outputs.get('success') is True
    assert outputs.get('skipped') is True
    assert outputs.get('reason') == IAMErrors.USER_ALREADY_EXISTS[1]