From 292608dc08b7cbc792f83ae55862e482f5324a97 Mon Sep 17 00:00:00 2001 From: Huanxuan Ao Date: Thu, 20 Oct 2016 14:11:33 +0800 Subject: [PATCH] Use FakeImage class to replace duplicated image info in volume test FakeImage class has been added in image v1 so that we can reuse it in volume v1 unit test to replace the duplicated image info in volume v1 fake. Change-Id: I0f96e568bd65e59241b57704fc2a379319a386d8 --- openstackclient/tests/unit/volume/v1/fakes.py | 13 --------- .../tests/unit/volume/v1/test_volume.py | 29 +++++++------------ 2 files changed, 11 insertions(+), 31 deletions(-) diff --git a/openstackclient/tests/unit/volume/v1/fakes.py b/openstackclient/tests/unit/volume/v1/fakes.py index a11ea49137..434e637a0a 100644 --- a/openstackclient/tests/unit/volume/v1/fakes.py +++ b/openstackclient/tests/unit/volume/v1/fakes.py @@ -69,19 +69,6 @@ EXTENSION = { 'links': extension_links, } -# NOTE(dtroyer): duplicating here the minimum image info needed to test -# volume create --image until circular references can be -# avoided by refactoring the test fakes. - -image_id = 'im1' -image_name = 'graven' - - -IMAGE = { - 'id': image_id, - 'name': image_name, -} - type_id = "5520dc9e-6f9b-4378-a719-729911c0f407" type_name = "fake-lvmdriver-1" diff --git a/openstackclient/tests/unit/volume/v1/test_volume.py b/openstackclient/tests/unit/volume/v1/test_volume.py index 73c00844e8..cd3cfd5d08 100644 --- a/openstackclient/tests/unit/volume/v1/test_volume.py +++ b/openstackclient/tests/unit/volume/v1/test_volume.py @@ -14,15 +14,14 @@ # import argparse -import copy import mock from mock import call from osc_lib import exceptions from osc_lib import utils -from openstackclient.tests.unit import fakes from openstackclient.tests.unit.identity.v2_0 import fakes as identity_fakes +from openstackclient.tests.unit.image.v1 import fakes as image_fakes from openstackclient.tests.unit import utils as tests_utils from openstackclient.tests.unit.volume.v1 import fakes as volume_fakes from openstackclient.volume.v1 import volume @@ -321,19 +320,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.display_name, ] verifylist = [ - ('image', volume_fakes.image_id), + ('image', image.id), ('size', self.new_volume.size), ('name', self.new_volume.display_name), ] @@ -360,26 +356,23 @@ class TestVolumeCreate(TestVolume): None, None, None, - volume_fakes.image_id, + image.id, ) self.assertEqual(self.columns, columns) 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.display_name, ] verifylist = [ - ('image', volume_fakes.image_name), + ('image', image.name), ('size', self.new_volume.size), ('name', self.new_volume.display_name), ] @@ -406,7 +399,7 @@ class TestVolumeCreate(TestVolume): None, None, None, - volume_fakes.image_id, + image.id, ) self.assertEqual(self.columns, columns)