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:
parent
8470618611
commit
677dfaa925
@ -14,12 +14,12 @@
|
|||||||
|
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
import mock
|
|
||||||
from mock import call
|
from mock import call
|
||||||
|
|
||||||
from openstackclient.common import utils
|
from openstackclient.common import utils
|
||||||
from openstackclient.tests import fakes
|
from openstackclient.tests import fakes
|
||||||
from openstackclient.tests.identity.v3 import fakes as identity_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.tests.volume.v2 import fakes as volume_fakes
|
||||||
from openstackclient.volume.v2 import volume
|
from openstackclient.volume.v2 import volume
|
||||||
|
|
||||||
@ -301,19 +301,16 @@ class TestVolumeCreate(TestVolume):
|
|||||||
self.assertEqual(self.datalist, data)
|
self.assertEqual(self.datalist, data)
|
||||||
|
|
||||||
def test_volume_create_image_id(self):
|
def test_volume_create_image_id(self):
|
||||||
self.images_mock.get.return_value = fakes.FakeResource(
|
image = image_fakes.FakeImage.create_one_image()
|
||||||
None,
|
self.images_mock.get.return_value = image
|
||||||
copy.deepcopy(volume_fakes.IMAGE),
|
|
||||||
loaded=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
arglist = [
|
arglist = [
|
||||||
'--image', volume_fakes.image_id,
|
'--image', image.id,
|
||||||
'--size', str(self.new_volume.size),
|
'--size', str(self.new_volume.size),
|
||||||
self.new_volume.name,
|
self.new_volume.name,
|
||||||
]
|
]
|
||||||
verifylist = [
|
verifylist = [
|
||||||
('image', volume_fakes.image_id),
|
('image', image.id),
|
||||||
('size', self.new_volume.size),
|
('size', self.new_volume.size),
|
||||||
('name', self.new_volume.name),
|
('name', self.new_volume.name),
|
||||||
]
|
]
|
||||||
@ -334,7 +331,7 @@ class TestVolumeCreate(TestVolume):
|
|||||||
project_id=None,
|
project_id=None,
|
||||||
availability_zone=None,
|
availability_zone=None,
|
||||||
metadata=None,
|
metadata=None,
|
||||||
imageRef=volume_fakes.image_id,
|
imageRef=image.id,
|
||||||
source_volid=None,
|
source_volid=None,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -342,19 +339,16 @@ class TestVolumeCreate(TestVolume):
|
|||||||
self.assertEqual(self.datalist, data)
|
self.assertEqual(self.datalist, data)
|
||||||
|
|
||||||
def test_volume_create_image_name(self):
|
def test_volume_create_image_name(self):
|
||||||
self.images_mock.get.return_value = fakes.FakeResource(
|
image = image_fakes.FakeImage.create_one_image()
|
||||||
None,
|
self.images_mock.get.return_value = image
|
||||||
copy.deepcopy(volume_fakes.IMAGE),
|
|
||||||
loaded=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
arglist = [
|
arglist = [
|
||||||
'--image', volume_fakes.image_name,
|
'--image', image.name,
|
||||||
'--size', str(self.new_volume.size),
|
'--size', str(self.new_volume.size),
|
||||||
self.new_volume.name,
|
self.new_volume.name,
|
||||||
]
|
]
|
||||||
verifylist = [
|
verifylist = [
|
||||||
('image', volume_fakes.image_name),
|
('image', image.name),
|
||||||
('size', self.new_volume.size),
|
('size', self.new_volume.size),
|
||||||
('name', self.new_volume.name),
|
('name', self.new_volume.name),
|
||||||
]
|
]
|
||||||
@ -375,7 +369,7 @@ class TestVolumeCreate(TestVolume):
|
|||||||
project_id=None,
|
project_id=None,
|
||||||
availability_zone=None,
|
availability_zone=None,
|
||||||
metadata=None,
|
metadata=None,
|
||||||
imageRef=volume_fakes.image_id,
|
imageRef=image.id,
|
||||||
source_volid=None
|
source_volid=None
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -383,21 +377,21 @@ class TestVolumeCreate(TestVolume):
|
|||||||
self.assertEqual(self.datalist, data)
|
self.assertEqual(self.datalist, data)
|
||||||
|
|
||||||
def test_volume_create_with_snapshot(self):
|
def test_volume_create_with_snapshot(self):
|
||||||
|
snapshot = volume_fakes.FakeSnapshot.create_one_snapshot()
|
||||||
|
self.new_volume.snapshot_id = snapshot.id
|
||||||
arglist = [
|
arglist = [
|
||||||
'--size', str(self.new_volume.size),
|
'--size', str(self.new_volume.size),
|
||||||
'--snapshot', volume_fakes.snapshot_id,
|
'--snapshot', self.new_volume.snapshot_id,
|
||||||
self.new_volume.name,
|
self.new_volume.name,
|
||||||
]
|
]
|
||||||
verifylist = [
|
verifylist = [
|
||||||
('size', self.new_volume.size),
|
('size', self.new_volume.size),
|
||||||
('snapshot', volume_fakes.snapshot_id),
|
('snapshot', self.new_volume.snapshot_id),
|
||||||
('name', self.new_volume.name),
|
('name', self.new_volume.name),
|
||||||
]
|
]
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
fake_snapshot = mock.Mock()
|
self.snapshots_mock.get.return_value = snapshot
|
||||||
fake_snapshot.id = volume_fakes.snapshot_id
|
|
||||||
self.snapshots_mock.get.return_value = fake_snapshot
|
|
||||||
|
|
||||||
# In base command class ShowOne in cliff, abstract method take_action()
|
# 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
|
# 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(
|
self.volumes_mock.create.assert_called_once_with(
|
||||||
size=self.new_volume.size,
|
size=self.new_volume.size,
|
||||||
snapshot_id=fake_snapshot.id,
|
snapshot_id=snapshot.id,
|
||||||
name=self.new_volume.name,
|
name=self.new_volume.name,
|
||||||
description=None,
|
description=None,
|
||||||
volume_type=None,
|
volume_type=None,
|
||||||
@ -642,12 +636,12 @@ class TestVolumeList(TestVolume):
|
|||||||
|
|
||||||
def test_volume_list_name(self):
|
def test_volume_list_name(self):
|
||||||
arglist = [
|
arglist = [
|
||||||
'--name', volume_fakes.volume_name,
|
'--name', self.mock_volume.name,
|
||||||
]
|
]
|
||||||
verifylist = [
|
verifylist = [
|
||||||
('long', False),
|
('long', False),
|
||||||
('all_projects', False),
|
('all_projects', False),
|
||||||
('name', volume_fakes.volume_name),
|
('name', self.mock_volume.name),
|
||||||
('status', None),
|
('status', None),
|
||||||
]
|
]
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
@ -670,13 +664,13 @@ class TestVolumeList(TestVolume):
|
|||||||
|
|
||||||
def test_volume_list_status(self):
|
def test_volume_list_status(self):
|
||||||
arglist = [
|
arglist = [
|
||||||
'--status', volume_fakes.volume_status,
|
'--status', self.mock_volume.status,
|
||||||
]
|
]
|
||||||
verifylist = [
|
verifylist = [
|
||||||
('long', False),
|
('long', False),
|
||||||
('all_projects', False),
|
('all_projects', False),
|
||||||
('name', None),
|
('name', None),
|
||||||
('status', volume_fakes.volume_status),
|
('status', self.mock_volume.status),
|
||||||
]
|
]
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user