def test_profile_get_admin_context(self): profile = shared.create_profile(self.ctx) admin_ctx = utils.dummy_context(project='a-different-project', is_admin=True) res = db_api.profile_get(admin_ctx, profile.id, project_safe=True) self.assertIsNone(res) res = db_api.profile_get(admin_ctx, profile.id, project_safe=False) self.assertIsNotNone(res)
def test_profile_get_diff_project(self): profile = shared.create_profile(self.ctx) new_ctx = utils.dummy_context(project='a-different-project') res = db_api.profile_get(new_ctx, profile.id) self.assertIsNone(res) res = db_api.profile_get(new_ctx, profile.id, project_safe=False) self.assertIsNotNone(res) self.assertEqual(profile.id, res.id)
def test_profile_get_by_short_id(self): profile_ids = ['same-part-unique-part', 'same-part-part-unique'] for pid in profile_ids: shared.create_profile(self.ctx, id=pid) # verify creation with set ID profile = db_api.profile_get(self.ctx, pid) self.assertIsNotNone(profile) self.assertEqual(pid, profile.id) # too short -> multiple choices for x in range(len('same-part-')): self.assertRaises(exception.MultipleChoices, db_api.profile_get_by_short_id, self.ctx, profile_ids[0][:x]) # ids are unique profile = db_api.profile_get_by_short_id(self.ctx, profile_ids[0][:11]) self.assertEqual(profile_ids[0], profile.id) profile = db_api.profile_get_by_short_id(self.ctx, profile_ids[1][:11]) self.assertEqual(profile_ids[1], profile.id) # bad ids res = db_api.profile_get_by_short_id(self.ctx, 'non-existent') self.assertIsNone(res)
def test_profile_delete(self): profile = shared.create_profile(self.ctx) self.assertIsNotNone(profile) profile_id = profile.id db_api.profile_delete(self.ctx, profile_id) profile = db_api.profile_get(self.ctx, profile_id) self.assertIsNone(profile) # not found in delete is okay res = db_api.profile_delete(self.ctx, profile_id) self.assertIsNone(res)
def test_profile_get_show_deleted(self): profile_id = shared.create_profile(self.ctx).id # check created profile = db_api.profile_get(self.ctx, profile_id) self.assertIsNotNone(profile) # Now, delete it db_api.profile_delete(self.ctx, profile_id) # default equivalent to false profile = db_api.profile_get(self.ctx, profile_id) self.assertIsNone(profile) # explicit false profile = db_api.profile_get(self.ctx, profile_id, show_deleted=False) self.assertIsNone(profile) # explicit true profile = db_api.profile_get(self.ctx, profile_id, show_deleted=True) self.assertIsNotNone(profile) self.assertEqual(profile_id, profile.id)
def test_profile_get_not_found(self): profile = db_api.profile_get(self.ctx, 'BogusProfileID') self.assertIsNone(profile)
def test_profile_get(self): profile = shared.create_profile(self.ctx) retobj = db_api.profile_get(self.ctx, profile.id) self.assertEqual(profile.id, retobj.id) self.assertEqual(profile.spec, retobj.spec)
def test_profile_get_admin_context(self): profile = shared.create_profile(self.ctx) admin_ctx = utils.dummy_context(project='a-different-project', is_admin=True) res = db_api.profile_get(admin_ctx, profile.id, project_safe=True) self.assertIsNotNone(res)