Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
    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)
Ejemplo n.º 6
0
    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)
Ejemplo n.º 7
0
    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)
Ejemplo n.º 8
0
    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)
Ejemplo n.º 9
0
    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)
Ejemplo n.º 10
0
 def test_profile_get_not_found(self):
     profile = db_api.profile_get(self.ctx, 'BogusProfileID')
     self.assertIsNone(profile)
Ejemplo n.º 11
0
 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)
Ejemplo n.º 12
0
 def test_profile_get_not_found(self):
     profile = db_api.profile_get(self.ctx, 'BogusProfileID')
     self.assertIsNone(profile)
Ejemplo n.º 13
0
 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)
Ejemplo n.º 14
0
 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)