Fix unit test for volume commands in volumev2

There are some issues in test_volume.py in volumev2,
I make three changes in this patch:

1.modified some codes that not used FakeVolume class.
2.added a fake image by FakeImage class for this test.
3.added a fake snapshot by FakeSnapshot class for this test.

Change-Id: I02ba73d3aaee95624b0e2307b255e0e485b0c3a3
This commit is contained in:
Huanxuan Ao 2016-05-31 16:46:16 +08:00
parent 8470618611
commit 677dfaa925

View File

@ -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)