From 9bf849d95563aefda38eb8de13527578c3528598 Mon Sep 17 00:00:00 2001 From: Feng Shengqin Date: Thu, 20 Oct 2016 01:26:48 +0800 Subject: [PATCH] add some tests for db Change-Id: If54be4b9d1e6f2463c13e4b79b0d28de330432f8 --- magnum/tests/unit/db/test_cluster.py | 20 ++++++++++++++++++- magnum/tests/unit/db/test_cluster_template.py | 6 ++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/magnum/tests/unit/db/test_cluster.py b/magnum/tests/unit/db/test_cluster.py index 0111455834..31c7cc2486 100644 --- a/magnum/tests/unit/db/test_cluster.py +++ b/magnum/tests/unit/db/test_cluster.py @@ -63,6 +63,20 @@ class DbClusterTestCase(base.DbTestCase): self.dbapi.get_cluster_by_uuid, self.context, '12345678-9999-0000-aaaa-123456789012') + self.assertRaises(exception.ClusterNotFound, + self.dbapi.get_cluster_by_name, + self.context, 'not_found') + + def test_get_cluster_by_name_multiple_cluster(self): + utils.create_test_cluster( + id=1, name='clusterone', + uuid=uuidutils.generate_uuid()) + utils.create_test_cluster( + id=2, name='clusterone', + uuid=uuidutils.generate_uuid()) + self.assertRaises(exception.Conflict, + self.dbapi.get_cluster_by_name, + self.context, 'clusterone') def test_get_cluster_list(self): uuids = [] @@ -189,11 +203,15 @@ class DbClusterTestCase(base.DbTestCase): self.dbapi.get_cluster_by_uuid, self.context, cluster.uuid) - def test_destroy_cluster_that_does_not_exist(self): + def test_destroy_cluster_by_id_that_does_not_exist(self): self.assertRaises(exception.ClusterNotFound, self.dbapi.destroy_cluster, '12345678-9999-0000-aaaa-123456789012') + def test_destroy_cluster_by_uuid_that_does_not_exist(self): + self.assertRaises(exception.ClusterNotFound, + self.dbapi.destroy_cluster, '999') + def test_update_cluster(self): cluster = utils.create_test_cluster() old_nc = cluster.node_count diff --git a/magnum/tests/unit/db/test_cluster_template.py b/magnum/tests/unit/db/test_cluster_template.py index 54b0a6a0fa..cb88c5520f 100644 --- a/magnum/tests/unit/db/test_cluster_template.py +++ b/magnum/tests/unit/db/test_cluster_template.py @@ -140,6 +140,12 @@ class DbClusterTemplateTestCase(base.DbTestCase): self.dbapi.get_cluster_template_by_name, self.context, 'not_found') + def test_get_cluster_template_by_uuid_that_does_not_exist(self): + self.assertRaises(exception.ClusterTemplateNotFound, + self.dbapi.get_cluster_template_by_uuid, + self.context, + '12345678-9999-0000-aaaa-123456789012') + def test_update_cluster_template(self): ct = utils.create_test_cluster_template() res = self.dbapi.update_cluster_template(ct['id'],