예제 #1
0
def test_create_user_command__success(mocker):
    """
    Given:
        - A ServiceNow IAM client object
        - A user-profile argument that contains an email of a non-existing user in ServiceNow
    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(client,
                        'create_user',
                        return_value=SERVICENOW_USER_OUTPUT)

    user_profile = create_user_command(client,
                                       args,
                                       'mapper_out',
                                       is_command_enabled=True,
                                       is_update_enabled=False,
                                       is_enable_enabled=False)
    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') == 'mock_user_name'
    assert outputs.get('details', {}).get('first_name') == 'mock_first_name'
    assert outputs.get('details', {}).get('last_name') == 'mock_last_name'
예제 #2
0
def test_create_user_command__user_already_exists(mocker):
    """
    Given:
        - A ServiceNow IAM client object
        - A user-profile argument that contains an email of a user
    When:
        - The user already exists in ServiceNow and disabled
        - allow-enable argument is false
        - Calling function create_user_command
    Then:
        - Ensure the command is considered successful and the user is still disabled
    """
    client = mock_client()
    args = {
        'user-profile': {
            'email': '*****@*****.**'
        },
        'allow-enable': 'false'
    }

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

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

    assert outputs.get('action') == IAMActions.UPDATE_USER
    assert outputs.get('success') is True
    assert outputs.get('active') is False
    assert outputs.get('id') == 'mock_id'
    assert outputs.get('username') == 'mock_user_name'
    assert outputs.get('details', {}).get('first_name') == 'mock_first_name'
    assert outputs.get('details', {}).get('last_name') == 'mock_last_name'