def test_update_group_users_no_purge(mocker, identity_client):
    additional_properties = dict({'purge_user_memberships': True})
    user_ids = dict({'ocid1.testuser1': 'test_user1'})
    mock_get_user_ids_from_user_names = mocker.patch.object(
        oci_group, 'get_user_ids_from_user_names')
    mock_get_user_ids_from_user_names.return_value = user_ids
    existing_group_members = ['ocid1.testuser1']
    changed = oci_group.update_group_users(identity_client, None,
                                           'test_compartment',
                                           existing_group_members,
                                           create_group_object(),
                                           get_module(additional_properties))

    assert changed is False
def test_update_group_users_no_purge(mocker, identity_client):
    additional_properties = dict({"purge_user_memberships": True})
    user_ids = dict({"ocid1.testuser1": "test_user1"})
    mock_get_user_ids_from_user_names = mocker.patch.object(
        oci_group, "get_user_ids_from_user_names")
    mock_get_user_ids_from_user_names.return_value = user_ids
    existing_group_members = ["ocid1.testuser1"]
    changed = oci_group.update_group_users(
        identity_client,
        None,
        "test_compartment",
        existing_group_members,
        create_group_object(),
        get_module(additional_properties),
    )

    assert changed is False
def test_update_group_users_purge_members(mocker, identity_client):
    additional_properties = dict({'purge_user_memberships': True})
    user_ids = dict({'ocid1.testuser1': 'test_user1'})
    mock_get_user_ids_from_user_names = mocker.patch.object(
        oci_group, 'get_user_ids_from_user_names')
    mock_get_user_ids_from_user_names.return_value = user_ids
    mock_delete_all_users_from_the_group = mocker.patch.object(
        oci_group, 'delete_all_users_from_group')
    mock_add_users_to_group = mocker.patch.object(oci_group,
                                                  'add_users_to_group')
    existing_group_members = ['ocid1.testuser1', 'ocid1.testuser2']
    changed = oci_group.update_group_users(identity_client, 'test_compartment',
                                           None, existing_group_members,
                                           create_group_object(),
                                           get_module(additional_properties))

    assert changed is True
예제 #4
0
def test_update_group_users_new_user_success(mocker, identity_client):
    dditional_properties = dict({"purge_user_memberships": False})
    user_ids = dict({"ocid1.testuser1": "test_user1", "ocid1.testuser2": "test_user2"})
    mock_get_user_ids_from_user_names = mocker.patch.object(
        oci_group, "get_user_ids_from_user_names"
    )
    mock_get_user_ids_from_user_names.return_value = user_ids
    mock_add_users_to_group = mocker.patch.object(oci_group, "add_users_to_group")
    existing_group_members = ["ocid1.testuser1"]
    changed = oci_group.update_group_users(
        identity_client,
        "test_compartment",
        None,
        existing_group_members,
        create_group_object(),
        get_module(dditional_properties),
    )

    assert mock_add_users_to_group.called
    assert changed is True