summaryrefslogtreecommitdiff
path: root/troveclient
diff options
context:
space:
mode:
authorZhao Chao <zhaochao1984@gmail.com>2018-02-13 20:22:42 +0800
committerZhao Chao <zhaochao1984@gmail.com>2018-02-13 20:44:09 +0800
commit728d9378dc448885edf4437b77b146d32565a6e2 (patch)
tree4f0ec4942cf8a79f6bc588434064ad1d3ecea24d /troveclient
parent0b28b04ebbfaed981f4e00e69e4c7a8e0ed75395 (diff)
downloadpython-troveclient-728d9378dc448885edf4437b77b146d32565a6e2.tar.gz
Fix invalid mock in OSC cluster creating unittest
As '_parse_instance_options' is imported into database_clusters, mocking destination should be the database_clusters module, not the original troveclient.v1.shell. The reason this test passed before this patch is, the return value of '_parse_instance_options' is not checked, i.e. the mock object is also useless. This patch also checks how troveclient.v1.clusters.create is called to ensure '_parse_instance_options' is correctly mocked. Change-Id: I903a3b9565e4044c33401a6abcc47d50a5a2567f Signed-off-by: Zhao Chao <zhaochao1984@gmail.com>
Diffstat (limited to 'troveclient')
-rw-r--r--troveclient/tests/osc/v1/test_database_clusters.py22
1 files changed, 15 insertions, 7 deletions
diff --git a/troveclient/tests/osc/v1/test_database_clusters.py b/troveclient/tests/osc/v1/test_database_clusters.py
index 70fc9c3..939d369 100644
--- a/troveclient/tests/osc/v1/test_database_clusters.py
+++ b/troveclient/tests/osc/v1/test_database_clusters.py
@@ -18,7 +18,6 @@ from osc_lib import utils
from troveclient import common
from troveclient.osc.v1 import database_clusters
from troveclient.tests.osc.v1 import fakes
-from troveclient.v1 import shell
class TestClusters(fakes.TestDatabasev1):
@@ -134,20 +133,29 @@ class TestDatabaseClusterCreate(TestClusters):
self.data = self.fake_clusters.get_clusters_cls_1234()
self.cluster_client.create.return_value = self.data
- @mock.patch.object(shell, '_parse_instance_options')
- def test_cluster_create(self, mock_find):
- instance = 'flavor=02,volume=2'
- mock_find.return_value = instance
+ @mock.patch.object(database_clusters, '_parse_instance_options')
+ def test_cluster_create(self, mock_parse_instance_opts):
+ instances = ['flavor="02",volume=2',
+ 'flavor="03",volume=3']
+ parsed_instances = [{'flavor': '02', 'volume': 2},
+ {'flavor': '03', 'volume': 3}]
+ mock_parse_instance_opts.return_value = parsed_instances
args = ['test-name', 'vertica', '7.1',
- '--instance', instance]
+ '--instance', instances[0],
+ '--instance', instances[1]]
verifylist = [
('name', 'test-name'),
('datastore', 'vertica'),
('datastore_version', '7.1'),
- ('instances', [instance]),
+ ('instances', instances),
]
parsed_args = self.check_parser(self.cmd, args, verifylist)
columns, data = self.cmd.take_action(parsed_args)
+ self.cluster_client.create.assert_called_with(
+ parsed_args.name, parsed_args.datastore,
+ parsed_args.datastore_version,
+ instances=parsed_instances,
+ locality=parsed_args.locality)
self.assertEqual(self.columns, columns)
self.assertEqual(self.values, data)