Example #1
0
    def test_webhook_get_by_short_id(self):
        webhook_id1 = 'same-part-unique-part'
        webhook_id2 = 'same-part-part-unique'
        shared.create_webhook(self.ctx,
                              self.obj_id,
                              self.obj_type,
                              self.action,
                              id=webhook_id1,
                              name='webhook-1')
        shared.create_webhook(self.ctx,
                              self.obj_id,
                              self.obj_type,
                              self.action,
                              id=webhook_id2,
                              name='webhook-2')

        for x in range(len('same-part-')):
            self.assertRaises(exception.MultipleChoices,
                              db_api.webhook_get_by_short_id, self.ctx,
                              webhook_id1[:x])

        res = db_api.webhook_get_by_short_id(self.ctx, webhook_id1[:11])
        self.assertEqual(webhook_id1, res.id)
        res = db_api.webhook_get_by_short_id(self.ctx, webhook_id2[:11])
        self.assertEqual(webhook_id2, res.id)
        res = db_api.webhook_get_by_short_id(self.ctx, 'non-existent')
        self.assertIsNone(res)
Example #2
0
    def test_webhook_get_by_short_id_show_deleted(self):
        webhook_id = 'this-is-a-unique-id'
        shared.create_webhook(self.ctx,
                              self.obj_id,
                              self.obj_type,
                              self.action,
                              id=webhook_id)

        res = db_api.webhook_get_by_short_id(self.ctx, webhook_id[:5])
        self.assertEqual(webhook_id, res.id)
        res = db_api.webhook_get_by_short_id(self.ctx, webhook_id[:7])
        self.assertEqual(webhook_id, res.id)

        db_api.webhook_delete(self.ctx, webhook_id)

        res = db_api.webhook_get_by_short_id(self.ctx, webhook_id[:5])
        self.assertIsNone(res)
        res = db_api.webhook_get_by_short_id(self.ctx,
                                             webhook_id[:5],
                                             show_deleted=False)
        self.assertIsNone(res)
        res = db_api.webhook_get_by_short_id(self.ctx,
                                             webhook_id[:5],
                                             show_deleted=True)
        self.assertEqual(webhook_id, res.id)
Example #3
0
    def test_webhook_get_by_short_id_diff_project(self):
        webhook_id = 'same-part-unique-part'
        shared.create_webhook(self.ctx, self.obj_id, self.obj_type,
                              self.action, id=webhook_id, name='webhook-1')

        new_ctx = utils.dummy_context(project='a-different-project')
        res = db_api.webhook_get_by_short_id(new_ctx, webhook_id[:11])
        self.assertIsNone(res)
        res = db_api.webhook_get_by_short_id(new_ctx, webhook_id[:11],
                                             project_safe=False)
        self.assertIsNotNone(res)
        self.assertEqual(webhook_id, res.id)
Example #4
0
    def test_webhook_get_by_short_id(self):
        webhook_id1 = 'same-part-unique-part'
        webhook_id2 = 'same-part-part-unique'
        shared.create_webhook(self.ctx, self.obj_id, self.obj_type,
                              self.action, id=webhook_id1, name='webhook-1')
        shared.create_webhook(self.ctx, self.obj_id, self.obj_type,
                              self.action, id=webhook_id2, name='webhook-2')

        for x in range(len('same-part-')):
            self.assertRaises(exception.MultipleChoices,
                              db_api.webhook_get_by_short_id,
                              self.ctx, webhook_id1[:x])

        res = db_api.webhook_get_by_short_id(self.ctx, webhook_id1[:11])
        self.assertEqual(webhook_id1, res.id)
        res = db_api.webhook_get_by_short_id(self.ctx, webhook_id2[:11])
        self.assertEqual(webhook_id2, res.id)
        res = db_api.webhook_get_by_short_id(self.ctx, 'non-existent')
        self.assertIsNone(res)
Example #5
0
    def test_webhook_get_by_short_id_show_deleted(self):
        webhook_id = 'this-is-a-unique-id'
        shared.create_webhook(self.ctx, self.obj_id, self.obj_type,
                              self.action, id=webhook_id)

        res = db_api.webhook_get_by_short_id(self.ctx, webhook_id[:5])
        self.assertEqual(webhook_id, res.id)
        res = db_api.webhook_get_by_short_id(self.ctx, webhook_id[:7])
        self.assertEqual(webhook_id, res.id)

        db_api.webhook_delete(self.ctx, webhook_id)

        res = db_api.webhook_get_by_short_id(self.ctx, webhook_id[:5])
        self.assertIsNone(res)
        res = db_api.webhook_get_by_short_id(self.ctx, webhook_id[:5],
                                             show_deleted=False)
        self.assertIsNone(res)
        res = db_api.webhook_get_by_short_id(self.ctx, webhook_id[:5],
                                             show_deleted=True)
        self.assertEqual(webhook_id, res.id)