def test_stack_get_all_by_tenant(self): values = [ { 'tenant': UUID1 }, { 'tenant': UUID1 }, { 'tenant': UUID2 }, { 'tenant': UUID2 }, { 'tenant': UUID2 }, ] [ create_stack(self.ctx, self.template, self.user_creds, **val) for val in values ] self.ctx.tenant_id = UUID1 stacks = db_api.stack_get_all_by_tenant(self.ctx) self.assertEqual(2, len(stacks)) self.ctx.tenant_id = UUID2 stacks = db_api.stack_get_all_by_tenant(self.ctx) self.assertEqual(3, len(stacks)) self.ctx.tenant_id = UUID3 self.assertEqual([], db_api.stack_get_all_by_tenant(self.ctx))
def test_stack_get_all_by_tenant(self): stacks = [self._setup_test_stack('stack', x)[1] for x in UUIDs] st_db = db_api.stack_get_all_by_tenant(self.ctx) self.assertEqual(3, len(st_db)) stacks[0].delete() st_db = db_api.stack_get_all_by_tenant(self.ctx) self.assertEqual(2, len(st_db)) stacks[1].delete() st_db = db_api.stack_get_all_by_tenant(self.ctx) self.assertEqual(1, len(st_db))
def test_stack_get_all_by_tenant(self): stacks = [self._setup_test_stack('stack', x)[1] for x in UUIDs] st_db = db_api.stack_get_all_by_tenant(self.ctx) self.assertEqual(2, len(st_db)) stacks[0].delete() st_db = db_api.stack_get_all_by_tenant(self.ctx) self.assertEqual(1, len(st_db)) stacks[1].delete() st_db = db_api.stack_get_all_by_tenant(self.ctx) self.assertEqual(0, len(st_db))
def test_stack_get_all_by_tenant_default_sort_dir(self): stacks = [self._setup_test_stack('stack', x)[1] for x in UUIDs] st_db = db_api.stack_get_all_by_tenant(self.ctx, sort_dir='asc') self.assertEqual(3, len(st_db)) self.assertEqual(stacks[0].id, st_db[0].id) self.assertEqual(stacks[1].id, st_db[1].id) self.assertEqual(stacks[2].id, st_db[2].id)
def test_stack_get_all_by_tenant_str_sort_keys(self): stacks = [self._setup_test_stack('stack', x)[1] for x in UUIDs] st_db = db_api.stack_get_all_by_tenant(self.ctx, sort_keys='created_at') self.assertEqual(3, len(st_db)) self.assertEqual(stacks[0].id, st_db[0].id) self.assertEqual(stacks[1].id, st_db[1].id) self.assertEqual(stacks[2].id, st_db[2].id)
def test_stack_get_all_by_tenant_filters_sort_keys(self, mock_paginate): sort_keys = ['name', 'status', 'created_at', 'updated_at', 'username'] st_db = db_api.stack_get_all_by_tenant(self.ctx, sort_keys=sort_keys) args, _ = mock_paginate.call_args used_sort_keys = set(args[3]) expected_keys = set(['name', 'status', 'created_at', 'updated_at', 'id']) self.assertEqual(expected_keys, used_sort_keys)
def test_stack_get_all_by_tenant_returns_all_if_no_filters(self): stack1 = self._setup_test_stack('foo', UUID1) stack2 = self._setup_test_stack('bar', UUID2) stacks = [stack1, stack2] filters = None results = db_api.stack_get_all_by_tenant(self.ctx, filters=filters) self.assertEqual(2, len(results))
def test_stack_get_all_by_tenant_filter_matches_in_list(self): stack1 = self._setup_test_stack('foo', UUID1) stack2 = self._setup_test_stack('bar', UUID2) stacks = [stack1, stack2] filters = {'name': ['bar', 'quux']} results = db_api.stack_get_all_by_tenant(self.ctx, filters=filters) self.assertEqual(1, len(results)) self.assertEqual('bar', results[0]['name'])
def test_stack_get_all_by_tenant(self): values = [ {'tenant': UUID1}, {'tenant': UUID1}, {'tenant': UUID2}, {'tenant': UUID2}, {'tenant': UUID2}, ] [create_stack(self.ctx, self.template, self.user_creds, **val) for val in values] self.ctx.tenant_id = UUID1 stacks = db_api.stack_get_all_by_tenant(self.ctx) self.assertEqual(2, len(stacks)) self.ctx.tenant_id = UUID2 stacks = db_api.stack_get_all_by_tenant(self.ctx) self.assertEqual(3, len(stacks)) self.ctx.tenant_id = UUID3 self.assertEqual([], db_api.stack_get_all_by_tenant(self.ctx))
def test_stack_get_all_by_tenant_marker(self): stacks = [self._setup_test_stack('stack', x)[1] for x in UUIDs] st_db = db_api.stack_get_all_by_tenant(self.ctx, marker=stacks[1].id) self.assertEqual(1, len(st_db)) self.assertEqual(stacks[0].id, st_db[0].id)
def test_stack_get_all_by_tenant_doesnt_mutate_sort_keys(self): stacks = [self._setup_test_stack('stack', x)[1] for x in UUIDs] sort_keys = ['id'] st_db = db_api.stack_get_all_by_tenant(self.ctx, sort_keys=sort_keys) self.assertEqual(['id'], sort_keys)
def test_stack_get_all_by_tenant_non_existing_marker(self): stacks = [self._setup_test_stack('stack', x)[1] for x in UUIDs] uuid = 'this stack doesnt exist' st_db = db_api.stack_get_all_by_tenant(self.ctx, marker=uuid) self.assertEqual(3, len(st_db))