def test_cluster_get_all_with_regular_project(self): values = [ { 'project': UUID1 }, { 'project': UUID1 }, { 'project': UUID2 }, { 'project': UUID2 }, { 'project': UUID2 }, ] [shared.create_cluster(self.ctx, self.profile, **v) for v in values] self.ctx.project_id = UUID1 clusters = db_api.cluster_get_all(self.ctx) self.assertEqual(2, len(clusters)) self.ctx.project_id = UUID2 clusters = db_api.cluster_get_all(self.ctx) self.assertEqual(3, len(clusters)) self.ctx.project_id = UUID3 self.assertEqual([], db_api.cluster_get_all(self.ctx))
def test_cluster_get_all_with_admin_context(self): values = [ { 'project': UUID1 }, { 'project': UUID1 }, { 'project': UUID2 }, { 'project': UUID2 }, { 'project': UUID2 }, ] [shared.create_cluster(self.ctx, self.profile, **v) for v in values] admin_ctx = utils.dummy_context(project='another-project', is_admin=True) clusters = db_api.cluster_get_all(admin_ctx, project_safe=True) self.assertEqual(0, len(clusters)) clusters = db_api.cluster_get_all(admin_ctx, project_safe=False) self.assertEqual(5, len(clusters))
def test_cluster_get_all_filters_sort_keys(self, mock_paginate): sort = 'name,status,created_at,updated_at' db_api.cluster_get_all(self.ctx, sort=sort) args = mock_paginate.call_args[0] 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_cluster_get_all_filters_sort_keys(self, mock_paginate): sort = 'name,status,created_at,updated_at' db_api.cluster_get_all(self.ctx, sort=sort) args = mock_paginate.call_args[0] 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_cluster_get_all_show_deleted(self): clusters = [shared.create_cluster(self.ctx, self.profile) for x in range(3)] results = db_api.cluster_get_all(self.ctx) self.assertEqual(3, len(results)) db_api.cluster_delete(self.ctx, clusters[0].id) results = db_api.cluster_get_all(self.ctx) self.assertEqual(2, len(results)) results = db_api.cluster_get_all(self.ctx, show_deleted=True) self.assertEqual(3, len(results))
def test_cluster_get_all_with_filters(self): shared.create_cluster(self.ctx, self.profile, name='foo') shared.create_cluster(self.ctx, self.profile, name='bar') filters = {'name': ['bar', 'quux']} results = db_api.cluster_get_all(self.ctx, filters=filters) self.assertEqual(1, len(results)) self.assertEqual('bar', results[0]['name']) filters = {'name': 'foo'} results = db_api.cluster_get_all(self.ctx, filters=filters) self.assertEqual(1, len(results)) self.assertEqual('foo', results[0]['name'])
def test_cluster_get_all_marker(self): clusters = [shared.create_cluster(self.ctx, self.profile, created_time=tu.utcnow()) for x in range(3)] cl_db = db_api.cluster_get_all(self.ctx, marker=clusters[1].id) self.assertEqual(1, len(cl_db)) self.assertEqual(clusters[2].id, cl_db[0].id)
def test_cluster_get_all_show_nested(self): cluster1 = shared.create_cluster(self.ctx, self.profile, name='cluster1') cluster2 = shared.create_cluster(self.ctx, self.profile, name='cluster2', parent=cluster1.id) cl_db = db_api.cluster_get_all(self.ctx) self.assertEqual(1, len(cl_db)) self.assertEqual(cluster1.id, cl_db[0].id) cl_db = db_api.cluster_get_all(self.ctx, show_nested=True) self.assertEqual(2, len(cl_db)) cl_ids = [s.id for s in cl_db] self.assertIn(cluster1.id, cl_ids) self.assertIn(cluster2.id, cl_ids)
def test_cluster_get_all_marker(self): clusters = [shared.create_cluster(self.ctx, self.profile, created_at=tu.utcnow(True)) for x in range(3)] cl_db = db_api.cluster_get_all(self.ctx, marker=clusters[1].id) self.assertEqual(1, len(cl_db)) self.assertEqual(clusters[2].id, cl_db[0].id)
def test_cluster_get_all_returns_all_if_no_filters(self): shared.create_cluster(self.ctx, self.profile) shared.create_cluster(self.ctx, self.profile) filters = None results = db_api.cluster_get_all(self.ctx, filters=filters) self.assertEqual(2, len(results))
def test_cluster_get_all_str_sort_keys(self): clusters = [shared.create_cluster(self.ctx, self.profile, created_time=tu.utcnow()) for x in range(3)] st_db = db_api.cluster_get_all(self.ctx, sort_keys='created_time') self.assertEqual(3, len(st_db)) self.assertEqual(clusters[0].id, st_db[0].id) self.assertEqual(clusters[1].id, st_db[1].id) self.assertEqual(clusters[2].id, st_db[2].id)
def test_cluster_get_all_default_sort_dir(self): clusters = [shared.create_cluster(self.ctx, self.profile, init_time=tu.utcnow()) for x in range(3)] st_db = db_api.cluster_get_all(self.ctx, sort_dir='asc') self.assertEqual(3, len(st_db)) self.assertEqual(clusters[0].id, st_db[0].id) self.assertEqual(clusters[1].id, st_db[1].id) self.assertEqual(clusters[2].id, st_db[2].id)
def test_cluster_get_all_default_sort_dir(self): clusters = [shared.create_cluster(self.ctx, self.profile, init_at=tu.utcnow(True)) for x in range(3)] st_db = db_api.cluster_get_all(self.ctx) self.assertEqual(3, len(st_db)) self.assertEqual(clusters[0].id, st_db[0].id) self.assertEqual(clusters[1].id, st_db[1].id) self.assertEqual(clusters[2].id, st_db[2].id)
def test_cluster_get_all_str_sort_keys(self): clusters = [shared.create_cluster(self.ctx, self.profile, created_at=tu.utcnow(True)) for x in range(3)] st_db = db_api.cluster_get_all(self.ctx, sort='created_at') self.assertEqual(3, len(st_db)) self.assertEqual(clusters[0].id, st_db[0].id) self.assertEqual(clusters[1].id, st_db[1].id) self.assertEqual(clusters[2].id, st_db[2].id)
def test_cluster_get_all_with_regular_project(self): values = [ {'project': UUID1}, {'project': UUID1}, {'project': UUID2}, {'project': UUID2}, {'project': UUID2}, ] [shared.create_cluster(self.ctx, self.profile, **v) for v in values] self.ctx.project = UUID1 clusters = db_api.cluster_get_all(self.ctx) self.assertEqual(2, len(clusters)) self.ctx.project = UUID2 clusters = db_api.cluster_get_all(self.ctx) self.assertEqual(3, len(clusters)) self.ctx.project = UUID3 self.assertEqual([], db_api.cluster_get_all(self.ctx))
def test_cluster_get_all_with_project_safe_false(self): values = [ {'project': UUID1}, {'project': UUID1}, {'project': UUID2}, {'project': UUID2}, {'project': UUID2}, ] [shared.create_cluster(self.ctx, self.profile, **v) for v in values] clusters = db_api.cluster_get_all(self.ctx, project_safe=False) self.assertEqual(5, len(clusters))
def test_cluster_get_all(self): values = [ {'name': 'cluster1'}, {'name': 'cluster2'}, {'name': 'cluster3'}, {'name': 'cluster4'} ] [shared.create_cluster(self.ctx, self.profile, **v) for v in values] ret_clusters = db_api.cluster_get_all(self.ctx) self.assertEqual(4, len(ret_clusters)) names = [ret_cluster.name for ret_cluster in ret_clusters] [self.assertIn(val['name'], names) for val in values]
def test_cluster_get_all_with_admin_context(self): values = [ {'project': UUID1}, {'project': UUID1}, {'project': UUID2}, {'project': UUID2}, {'project': UUID2}, ] [shared.create_cluster(self.ctx, self.profile, **v) for v in values] admin_ctx = utils.dummy_context(project='another-project', is_admin=True) clusters = db_api.cluster_get_all(admin_ctx, project_safe=True) self.assertEqual(5, len(clusters))
def test_cluster_get_all_non_existing_marker(self): [shared.create_cluster(self.ctx, self.profile) for x in range(3)] uuid = "this cluster doesn't exist" st_db = db_api.cluster_get_all(self.ctx, marker=uuid) self.assertEqual(3, len(st_db))
def test_cluster_get_all_doesnt_mutate_sort_keys(self): [shared.create_cluster(self.ctx, self.profile) for x in range(3)] sort_keys = ['id'] db_api.cluster_get_all(self.ctx, sort_keys=sort_keys) self.assertEqual(['id'], sort_keys)