diff --git a/openstackclient/tests/volume/v2/test_volume.py b/openstackclient/tests/volume/v2/test_volume.py index 85ff61422b..fb48d8acf5 100644 --- a/openstackclient/tests/volume/v2/test_volume.py +++ b/openstackclient/tests/volume/v2/test_volume.py @@ -14,12 +14,12 @@ import copy -import mock from mock import call from openstackclient.common import utils from openstackclient.tests import fakes from openstackclient.tests.identity.v3 import fakes as identity_fakes +from openstackclient.tests.image.v2 import fakes as image_fakes from openstackclient.tests.volume.v2 import fakes as volume_fakes from openstackclient.volume.v2 import volume @@ -301,19 +301,16 @@ class TestVolumeCreate(TestVolume): self.assertEqual(self.datalist, data) def test_volume_create_image_id(self): - self.images_mock.get.return_value = fakes.FakeResource( - None, - copy.deepcopy(volume_fakes.IMAGE), - loaded=True, - ) + image = image_fakes.FakeImage.create_one_image() + self.images_mock.get.return_value = image arglist = [ - '--image', volume_fakes.image_id, + '--image', image.id, '--size', str(self.new_volume.size), self.new_volume.name, ] verifylist = [ - ('image', volume_fakes.image_id), + ('image', image.id), ('size', self.new_volume.size), ('name', self.new_volume.name), ] @@ -334,7 +331,7 @@ class TestVolumeCreate(TestVolume): project_id=None, availability_zone=None, metadata=None, - imageRef=volume_fakes.image_id, + imageRef=image.id, source_volid=None, ) @@ -342,19 +339,16 @@ class TestVolumeCreate(TestVolume): self.assertEqual(self.datalist, data) def test_volume_create_image_name(self): - self.images_mock.get.return_value = fakes.FakeResource( - None, - copy.deepcopy(volume_fakes.IMAGE), - loaded=True, - ) + image = image_fakes.FakeImage.create_one_image() + self.images_mock.get.return_value = image arglist = [ - '--image', volume_fakes.image_name, + '--image', image.name, '--size', str(self.new_volume.size), self.new_volume.name, ] verifylist = [ - ('image', volume_fakes.image_name), + ('image', image.name), ('size', self.new_volume.size), ('name', self.new_volume.name), ] @@ -375,7 +369,7 @@ class TestVolumeCreate(TestVolume): project_id=None, availability_zone=None, metadata=None, - imageRef=volume_fakes.image_id, + imageRef=image.id, source_volid=None ) @@ -383,21 +377,21 @@ class TestVolumeCreate(TestVolume): self.assertEqual(self.datalist, data) def test_volume_create_with_snapshot(self): + snapshot = volume_fakes.FakeSnapshot.create_one_snapshot() + self.new_volume.snapshot_id = snapshot.id arglist = [ '--size', str(self.new_volume.size), - '--snapshot', volume_fakes.snapshot_id, + '--snapshot', self.new_volume.snapshot_id, self.new_volume.name, ] verifylist = [ ('size', self.new_volume.size), - ('snapshot', volume_fakes.snapshot_id), + ('snapshot', self.new_volume.snapshot_id), ('name', self.new_volume.name), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - fake_snapshot = mock.Mock() - fake_snapshot.id = volume_fakes.snapshot_id - self.snapshots_mock.get.return_value = fake_snapshot + self.snapshots_mock.get.return_value = snapshot # In base command class ShowOne in cliff, abstract method take_action() # returns a two-part tuple with a tuple of column names and a tuple of @@ -406,7 +400,7 @@ class TestVolumeCreate(TestVolume): self.volumes_mock.create.assert_called_once_with( size=self.new_volume.size, - snapshot_id=fake_snapshot.id, + snapshot_id=snapshot.id, name=self.new_volume.name, description=None, volume_type=None, @@ -642,12 +636,12 @@ class TestVolumeList(TestVolume): def test_volume_list_name(self): arglist = [ - '--name', volume_fakes.volume_name, + '--name', self.mock_volume.name, ] verifylist = [ ('long', False), ('all_projects', False), - ('name', volume_fakes.volume_name), + ('name', self.mock_volume.name), ('status', None), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -670,13 +664,13 @@ class TestVolumeList(TestVolume): def test_volume_list_status(self): arglist = [ - '--status', volume_fakes.volume_status, + '--status', self.mock_volume.status, ] verifylist = [ ('long', False), ('all_projects', False), ('name', None), - ('status', volume_fakes.volume_status), + ('status', self.mock_volume.status), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist)