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_get_by_short_id_diff_project(self): profile_id = "same-part-unique-part" shared.create_profile(self.ctx, id=profile_id) new_ctx = utils.dummy_context(project="a-different-project") res = db_api.profile_get_by_short_id(new_ctx, profile_id) self.assertIsNone(res) res = db_api.profile_get_by_short_id(new_ctx, profile_id, project_safe=False) self.assertIsNotNone(res) self.assertEqual(profile_id, res.id)
def test_profile_get_by_short_id_diff_project(self): profile_id = 'same-part-unique-part' shared.create_profile(self.ctx, id=profile_id) new_ctx = utils.dummy_context(project='a-different-project') res = db_api.profile_get_by_short_id(new_ctx, profile_id) self.assertIsNone(res) res = db_api.profile_get_by_short_id(new_ctx, profile_id, project_safe=False) self.assertIsNotNone(res) self.assertEqual(profile_id, res.id)