Esempio n. 1
0
    def test_webhook_get_all_with_filters(self):
        shared.create_webhook(self.ctx, self.obj_id,
                              self.obj_type, self.action, name='webhook1')
        shared.create_webhook(self.ctx, self.obj_id,
                              self.obj_type, self.action, name='webhook2')

        filters = {'name': ['webhook1', 'webhookx']}
        results = db_api.webhook_get_all(self.ctx, filters=filters)
        self.assertEqual(1, len(results))
        self.assertEqual('webhook1', results[0]['name'])

        filters = {'name': 'webhook1'}
        results = db_api.webhook_get_all(self.ctx, filters=filters)
        self.assertEqual(1, len(results))
        self.assertEqual('webhook1', results[0]['name'])
Esempio n. 2
0
    def test_webhook_get_all_show_deleted(self):
        values = [{'id': 'webhook1'}, {'id': 'webhook2'}, {'id': 'webhook3'}]
        for v in values:
            shared.create_webhook(self.ctx, self.obj_id, self.obj_type,
                                  self.action, **v)

        db_api.webhook_delete(self.ctx, 'webhook2')

        webhooks = db_api.webhook_get_all(self.ctx)
        self.assertEqual(2, len(webhooks))

        webhooks = db_api.webhook_get_all(self.ctx, show_deleted=False)
        self.assertEqual(2, len(webhooks))

        webhooks = db_api.webhook_get_all(self.ctx, show_deleted=True)
        self.assertEqual(3, len(webhooks))
Esempio n. 3
0
    def test_webhook_get_all_show_deleted(self):
        values = [{'id': 'webhook1'}, {'id': 'webhook2'}, {'id': 'webhook3'}]
        for v in values:
            shared.create_webhook(self.ctx, self.obj_id, self.obj_type,
                                  self.action, **v)

        db_api.webhook_delete(self.ctx, 'webhook2')

        webhooks = db_api.webhook_get_all(self.ctx)
        self.assertEqual(2, len(webhooks))

        webhooks = db_api.webhook_get_all(self.ctx, show_deleted=False)
        self.assertEqual(2, len(webhooks))

        webhooks = db_api.webhook_get_all(self.ctx, show_deleted=True)
        self.assertEqual(3, len(webhooks))
Esempio n. 4
0
    def test_webhook_get_all_used_sort_keys(self):
        webhook_ids = ['webhook1', 'webhook2', 'webhook3']
        for v in webhook_ids:
            shared.create_webhook(self.ctx, self.obj_id, self.obj_type,
                                  self.action, id=v)

        mock_paginate = self.patchobject(db_api.utils, 'paginate_query')
        sort_keys = ['name', 'created_time', 'deleted_time',
                     'obj_id', 'obj_type']

        db_api.webhook_get_all(self.ctx, sort_keys=sort_keys)
        args = mock_paginate.call_args[0]
        used_sort_keys = set(args[3])
        expected_keys = set(['name', 'created_time', 'deleted_time',
                             'obj_id', 'obj_type', 'id'])
        self.assertEqual(expected_keys, used_sort_keys)
Esempio n. 5
0
    def test_webhook_get_all_with_project_safe(self):
        shared.create_webhook(self.ctx, self.obj_id,
                              self.obj_type, self.action, name='webhook1')
        shared.create_webhook(self.ctx, self.obj_id,
                              self.obj_type, self.action, name='webhook2')

        self.ctx.project = 'a-different-project'
        results = db_api.webhook_get_all(self.ctx, project_safe=False)
        self.assertEqual(2, len(results))

        self.ctx.project = 'a-different-project'
        results = db_api.webhook_get_all(self.ctx)
        self.assertEqual(0, len(results))

        results = db_api.webhook_get_all(self.ctx, project_safe=True)
        self.assertEqual(0, len(results))
Esempio n. 6
0
    def test_webhook_get_all_with_limit_marker(self):
        webhook_ids = ['webhook1', 'webhook2', 'webhook3']
        for v in webhook_ids:
            shared.create_webhook(self.ctx,
                                  self.obj_id,
                                  self.obj_type,
                                  self.action,
                                  id=v,
                                  created_time=tu.utcnow())

        webhooks = db_api.webhook_get_all(self.ctx, limit=1)
        self.assertEqual(1, len(webhooks))

        webhooks = db_api.webhook_get_all(self.ctx, limit=2)
        self.assertEqual(2, len(webhooks))

        webhooks = db_api.webhook_get_all(self.ctx, limit=5)
        self.assertEqual(3, len(webhooks))

        webhooks = db_api.webhook_get_all(self.ctx, marker='webhook1')
        self.assertEqual(2, len(webhooks))

        webhooks = db_api.webhook_get_all(self.ctx, marker='webhook2')
        self.assertEqual(1, len(webhooks))

        webhooks = db_api.webhook_get_all(self.ctx, marker='webhook3')
        self.assertEqual(0, len(webhooks))

        webhooks = db_api.webhook_get_all(self.ctx, limit=1, marker='webhook1')
        self.assertEqual(1, len(webhooks))
Esempio n. 7
0
    def test_webhook_get_all_with_limit_marker(self):
        webhook_ids = ['webhook1', 'webhook2', 'webhook3']
        for v in webhook_ids:
            shared.create_webhook(self.ctx, self.obj_id, self.obj_type,
                                  self.action, id=v,
                                  created_time=tu.utcnow())

        webhooks = db_api.webhook_get_all(self.ctx, limit=1)
        self.assertEqual(1, len(webhooks))

        webhooks = db_api.webhook_get_all(self.ctx, limit=2)
        self.assertEqual(2, len(webhooks))

        webhooks = db_api.webhook_get_all(self.ctx, limit=5)
        self.assertEqual(3, len(webhooks))

        webhooks = db_api.webhook_get_all(self.ctx, marker='webhook1')
        self.assertEqual(2, len(webhooks))

        webhooks = db_api.webhook_get_all(self.ctx, marker='webhook2')
        self.assertEqual(1, len(webhooks))

        webhooks = db_api.webhook_get_all(self.ctx, marker='webhook3')
        self.assertEqual(0, len(webhooks))

        webhooks = db_api.webhook_get_all(self.ctx, limit=1, marker='webhook1')
        self.assertEqual(1, len(webhooks))
Esempio n. 8
0
    def test_webhook_get_all_with_empty_filters(self):
        shared.create_webhook(self.ctx, self.obj_id,
                              self.obj_type, self.action, name='webhook1')
        shared.create_webhook(self.ctx, self.obj_id,
                              self.obj_type, self.action, name='webhook2')

        filters = None
        results = db_api.webhook_get_all(self.ctx, filters=filters)
        self.assertEqual(2, len(results))
Esempio n. 9
0
    def test_webhook_get_all_sort_keys_and_dir(self):
        values = [{
            'id': '001',
            'name': 'webhook1'
        }, {
            'id': '002',
            'name': 'webhook3'
        }, {
            'id': '003',
            'name': 'webhook2'
        }]
        obj_ids = {'webhook1': 'id3', 'webhook2': 'id2', 'webhook3': 'id1'}
        for v in values:
            shared.create_webhook(self.ctx, obj_ids[v['name']], self.obj_type,
                                  self.action, **v)

        webhooks = db_api.webhook_get_all(self.ctx,
                                          sort_keys=['name', 'obj_id'],
                                          sort_dir='asc')
        self.assertEqual(3, len(webhooks))
        # Sorted by name (ascending)
        self.assertEqual('001', webhooks[0].id)
        self.assertEqual('003', webhooks[1].id)
        self.assertEqual('002', webhooks[2].id)

        webhooks = db_api.webhook_get_all(self.ctx,
                                          sort_keys=['obj_id', 'name'],
                                          sort_dir='asc')
        self.assertEqual(3, len(webhooks))
        # Sorted by obj_id (ascending)
        self.assertEqual('002', webhooks[0].id)
        self.assertEqual('003', webhooks[1].id)
        self.assertEqual('001', webhooks[2].id)

        webhooks = db_api.webhook_get_all(self.ctx,
                                          sort_keys=['obj_id', 'name'],
                                          sort_dir='desc')
        self.assertEqual(3, len(webhooks))
        # Sorted by obj_id (descending)
        self.assertEqual('001', webhooks[0].id)
        self.assertEqual('003', webhooks[1].id)
        self.assertEqual('002', webhooks[2].id)
Esempio n. 10
0
    def test_webhook_get_all_with_filters(self):
        shared.create_webhook(self.ctx,
                              self.obj_id,
                              self.obj_type,
                              self.action,
                              name='webhook1')
        shared.create_webhook(self.ctx,
                              self.obj_id,
                              self.obj_type,
                              self.action,
                              name='webhook2')

        filters = {'name': ['webhook1', 'webhookx']}
        results = db_api.webhook_get_all(self.ctx, filters=filters)
        self.assertEqual(1, len(results))
        self.assertEqual('webhook1', results[0]['name'])

        filters = {'name': 'webhook1'}
        results = db_api.webhook_get_all(self.ctx, filters=filters)
        self.assertEqual(1, len(results))
        self.assertEqual('webhook1', results[0]['name'])
Esempio n. 11
0
    def test_webhook_get_all_used_sort_keys(self):
        webhook_ids = ['webhook1', 'webhook2', 'webhook3']
        for v in webhook_ids:
            shared.create_webhook(self.ctx,
                                  self.obj_id,
                                  self.obj_type,
                                  self.action,
                                  id=v)

        mock_paginate = self.patchobject(db_api.utils, 'paginate_query')
        sort_keys = [
            'name', 'created_time', 'deleted_time', 'obj_id', 'obj_type'
        ]

        db_api.webhook_get_all(self.ctx, sort_keys=sort_keys)
        args = mock_paginate.call_args[0]
        used_sort_keys = set(args[3])
        expected_keys = set([
            'name', 'created_time', 'deleted_time', 'obj_id', 'obj_type', 'id'
        ])
        self.assertEqual(expected_keys, used_sort_keys)
Esempio n. 12
0
    def test_webhook_get_all_with_project_safe(self):
        shared.create_webhook(self.ctx,
                              self.obj_id,
                              self.obj_type,
                              self.action,
                              name='webhook1')
        shared.create_webhook(self.ctx,
                              self.obj_id,
                              self.obj_type,
                              self.action,
                              name='webhook2')

        self.ctx.project = 'a-different-project'
        results = db_api.webhook_get_all(self.ctx, project_safe=False)
        self.assertEqual(2, len(results))

        self.ctx.project = 'a-different-project'
        results = db_api.webhook_get_all(self.ctx)
        self.assertEqual(0, len(results))

        results = db_api.webhook_get_all(self.ctx, project_safe=True)
        self.assertEqual(0, len(results))
Esempio n. 13
0
    def test_webhook_get_all(self):
        values = [{'name': 'webhook1'},
                  {'name': 'webhook2'},
                  {'name': 'webhook3'}]
        [shared.create_webhook(
            self.ctx, self.obj_id, self.obj_type,
            self.action, **v) for v in values]

        webhooks = db_api.webhook_get_all(self.ctx)
        self.assertEqual(3, len(webhooks))

        names = [webhook.name for webhook in webhooks]
        [self.assertIn(val['name'], names) for val in values]
Esempio n. 14
0
    def test_webhook_get_all_sort_keys_and_dir(self):
        values = [{'id': '001', 'name': 'webhook1'},
                  {'id': '002', 'name': 'webhook3'},
                  {'id': '003', 'name': 'webhook2'}]
        obj_ids = {'webhook1': 'id3',
                   'webhook2': 'id2',
                   'webhook3': 'id1'}
        for v in values:
            shared.create_webhook(self.ctx, obj_ids[v['name']],
                                  self.obj_type,
                                  self.action, **v)

        webhooks = db_api.webhook_get_all(self.ctx,
                                          sort_keys=['name', 'obj_id'],
                                          sort_dir='asc')
        self.assertEqual(3, len(webhooks))
        # Sorted by name (ascending)
        self.assertEqual('001', webhooks[0].id)
        self.assertEqual('003', webhooks[1].id)
        self.assertEqual('002', webhooks[2].id)

        webhooks = db_api.webhook_get_all(self.ctx,
                                          sort_keys=['obj_id', 'name'],
                                          sort_dir='asc')
        self.assertEqual(3, len(webhooks))
        # Sorted by obj_id (ascending)
        self.assertEqual('002', webhooks[0].id)
        self.assertEqual('003', webhooks[1].id)
        self.assertEqual('001', webhooks[2].id)

        webhooks = db_api.webhook_get_all(self.ctx,
                                          sort_keys=['obj_id', 'name'],
                                          sort_dir='desc')
        self.assertEqual(3, len(webhooks))
        # Sorted by obj_id (descending)
        self.assertEqual('001', webhooks[0].id)
        self.assertEqual('003', webhooks[1].id)
        self.assertEqual('002', webhooks[2].id)
Esempio n. 15
0
    def test_webhook_get_all_with_empty_filters(self):
        shared.create_webhook(self.ctx,
                              self.obj_id,
                              self.obj_type,
                              self.action,
                              name='webhook1')
        shared.create_webhook(self.ctx,
                              self.obj_id,
                              self.obj_type,
                              self.action,
                              name='webhook2')

        filters = None
        results = db_api.webhook_get_all(self.ctx, filters=filters)
        self.assertEqual(2, len(results))
Esempio n. 16
0
    def test_webhook_get_all_default_sort_dir(self):
        values = [{'id': '001', 'name': 'webhook1'},
                  {'id': '002', 'name': 'webhook2'},
                  {'id': '003', 'name': 'webhook3'}]
        obj_ids = {'webhook1': 'id3',
                   'webhook2': 'id2',
                   'webhook3': 'id1'}
        for v in values:
            shared.create_webhook(self.ctx, obj_ids[v['name']],
                                  self.obj_type,
                                  self.action, **v)

        webhooks = db_api.webhook_get_all(self.ctx, sort_dir='asc')
        self.assertEqual(3, len(webhooks))
        self.assertEqual(values[2]['id'], webhooks[0].id)
        self.assertEqual(values[1]['id'], webhooks[1].id)
        self.assertEqual(values[0]['id'], webhooks[2].id)
Esempio n. 17
0
    def test_webhook_get_all(self):
        values = [{
            'name': 'webhook1'
        }, {
            'name': 'webhook2'
        }, {
            'name': 'webhook3'
        }]
        [
            shared.create_webhook(self.ctx, self.obj_id, self.obj_type,
                                  self.action, **v) for v in values
        ]

        webhooks = db_api.webhook_get_all(self.ctx)
        self.assertEqual(3, len(webhooks))

        names = [webhook.name for webhook in webhooks]
        [self.assertIn(val['name'], names) for val in values]
Esempio n. 18
0
    def test_webhook_get_all_default_sort_dir(self):
        values = [{
            'id': '001',
            'name': 'webhook1'
        }, {
            'id': '002',
            'name': 'webhook2'
        }, {
            'id': '003',
            'name': 'webhook3'
        }]
        obj_ids = {'webhook1': 'id3', 'webhook2': 'id2', 'webhook3': 'id1'}
        for v in values:
            shared.create_webhook(self.ctx, obj_ids[v['name']], self.obj_type,
                                  self.action, **v)

        webhooks = db_api.webhook_get_all(self.ctx, sort_dir='asc')
        self.assertEqual(3, len(webhooks))
        self.assertEqual(values[2]['id'], webhooks[0].id)
        self.assertEqual(values[1]['id'], webhooks[1].id)
        self.assertEqual(values[0]['id'], webhooks[2].id)
Esempio n. 19
0
 def test_webhook_get_all_sort_keys_wont_change(self):
     sort_keys = ['id']
     db_api.webhook_get_all(self.ctx, sort_keys=sort_keys)
     self.assertEqual(['id'], sort_keys)
Esempio n. 20
0
 def test_webhook_get_all_sort_keys_wont_change(self):
     sort_keys = ['id']
     db_api.webhook_get_all(self.ctx, sort_keys=sort_keys)
     self.assertEqual(['id'], sort_keys)