def test_ensure_role_exists_when_role_is_present_but_not_associated(): """ ensure_role_exists when role exists but not associated yet """ # Setup keystone = setup_tenant_user_role() keystone.roles.roles_for_user = mock.Mock(return_value=[]) check_mode = False # Code under test user = "******" tenant = "acme" role = "admin" (changed, id) = keystone_user.ensure_role_exists(keystone, user, tenant, role, check_mode) # Assertions assert changed assert_equal(id, "34a699ab89d04c38894bbf3d998e5229") assert not keystone.roles.create.called
def test_ensure_role_exists_when_role_is_present_but_not_associated(): """ ensure_role_exists when role exists but not associated yet """ # Setup keystone = setup_tenant_user_role() keystone.roles.roles_for_user = mock.Mock(return_value=[]) check_mode = False # Code under test user = "******" tenant = "acme" role = "admin" (changed, id) = keystone_user.ensure_role_exists(keystone, user, tenant, role, check_mode) # Assertions assert changed assert id=="34a699ab89d04c38894bbf3d998e5229" assert not keystone.roles.create.called
def test_ensure_role_exists_when_role_is_present_but_not_associated_check(): """ ensure_role_exists when role exists but not associated yet, check mode """ # Setup keystone = setup_tenant_user_role() keystone.roles.roles_for_user = mock.Mock(return_value=[]) check_mode = True # Code under test user = "******" tenant = "acme" role = "admin" (changed, id) = keystone_user.ensure_role_exists(keystone, user, tenant, role, check_mode) # Assertions assert changed assert id is None assert not keystone.roles.create.called
def test_ensure_role_exists_when_role_is_present_but_not_associated_check(): """ ensure_role_exists when role exists but not associated yet, check mode """ # Setup keystone = setup_tenant_user_role() keystone.roles.roles_for_user = mock.Mock(return_value=[]) check_mode = True # Code under test user = "******" tenant = "acme" role = "admin" (changed, id) = keystone_user.ensure_role_exists(keystone, user, tenant, role, check_mode) # Assertions assert changed assert_is_none(id) assert not keystone.roles.create.called
def test_ensure_role_exists_when_role_is_absent_check(): """ ensure_role_exists when role does not exist yet, check mode """ # Setup keystone = setup_tenant_user_role() keystone.roles.create = mock.Mock(return_value=mock.Mock( id="40b14f9c2d114b38b3f6bced49a792b8")) keystone.roles.roles_for_user = mock.Mock(return_value=[]) check_mode = True # Code under test user = "******" tenant = "acme" role = "webuser" (changed, id) = keystone_user.ensure_role_exists(keystone, user, tenant, role, check_mode) # Assertions assert changed assert id is None assert not keystone.roles.create.called
def test_ensure_role_exists_when_role_is_absent_check(): """ ensure_role_exists when role does not exist yet, check mode """ # Setup keystone = setup_tenant_user_role() keystone.roles.create = mock.Mock(return_value=mock.Mock( id="40b14f9c2d114b38b3f6bced49a792b8")) keystone.roles.roles_for_user = mock.Mock(return_value=[]) check_mode = True # Code under test user = "******" tenant = "acme" role = "webuser" (changed, id) = keystone_user.ensure_role_exists(keystone, user, tenant, role, check_mode) # Assertions assert changed assert_equal(id, None) assert not keystone.roles.create.called
def test_ensure_role_exists_when_present(): """ ensure_role_exists when role exists and is associated properly """ # Setup keystone = setup_tenant_user_role() role = mock.Mock() role.id = "34a699ab89d04c38894bbf3d998e5229" role.name = "admin" keystone.roles.roles_for_user = mock.Mock(return_value=[role]) check_mode = False # Code under test user = "******" tenant = "acme" role = "admin" (changed, id) = keystone_user.ensure_role_exists(keystone, user, tenant, role, check_mode) # Assertions assert not changed assert_equal(id, "34a699ab89d04c38894bbf3d998e5229") assert not keystone.roles.create.called
def test_ensure_role_exists_when_present_check(): """ ensure_role_exists when role exists and is associated properly, check mode """ # Setup keystone = setup_tenant_user_role() role = mock.Mock() role.id = "34a699ab89d04c38894bbf3d998e5229" role.name = "admin" keystone.roles.roles_for_user = mock.Mock(return_value=[role]) check_mode = True # Code under test user = "******" tenant = "acme" role = "admin" (changed, id) = keystone_user.ensure_role_exists(keystone, user, tenant, role, check_mode) # Assertions assert not changed assert_equal(id, "34a699ab89d04c38894bbf3d998e5229") assert not keystone.roles.create.called