コード例 #1
0
ファイル: test_profile_api.py プロジェクト: eayunstack/senlin
    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)
コード例 #2
0
ファイル: test_profile_api.py プロジェクト: jonnary/senlin
    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)
コード例 #3
0
    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)
コード例 #4
0
ファイル: test_profile_api.py プロジェクト: eayunstack/senlin
    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)