Use identity fake classes instead of old unit tests data

Use FakeProject, FakeDomain and FakeUser classes instead
of old test data in image, compute and volume. (This work
has done in network)

Change-Id: Ic37d5d9db98f0f2acc6c714a9646063dcbde4ff3
Partially-Implements: blueprint use-fake-project
This commit is contained in:
Huanxuan Ao 2016-07-15 19:02:18 +08:00
parent b838e9970d
commit 1b2ea91420
5 changed files with 136 additions and 215 deletions

View File

@ -13,7 +13,6 @@
# under the License.
#
import copy
import mock
from mock import call
@ -22,7 +21,6 @@ from osc_lib import utils
from openstackclient.compute.v2 import flavor
from openstackclient.tests.compute.v2 import fakes as compute_fakes
from openstackclient.tests import fakes
from openstackclient.tests.identity.v3 import fakes as identity_fakes
from openstackclient.tests import utils as tests_utils
@ -48,7 +46,7 @@ class TestFlavorCreate(TestFlavor):
flavor = compute_fakes.FakeFlavor.create_one_flavor(
attrs={'links': 'flavor-links'})
project = identity_fakes.FakeProject.create_one_project()
columns = (
'OS-FLV-DISABLED:disabled',
'OS-FLV-EXT-DATA:ephemeral',
@ -80,11 +78,7 @@ class TestFlavorCreate(TestFlavor):
super(TestFlavorCreate, self).setUp()
# Return a project
self.projects_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.PROJECT),
loaded=True,
)
self.projects_mock.get.return_value = self.project
self.flavors_mock.create.return_value = self.flavor
self.cmd = flavor.CreateFlavor(self.app, None)
@ -174,7 +168,7 @@ class TestFlavorCreate(TestFlavor):
'--vcpus', str(self.flavor.vcpus),
'--rxtx-factor', str(self.flavor.rxtx_factor),
'--private',
'--project', identity_fakes.project_id,
'--project', self.project.id,
'--property', 'key1=value1',
'--property', 'key2=value2',
self.flavor.name,
@ -188,7 +182,7 @@ class TestFlavorCreate(TestFlavor):
('vcpus', self.flavor.vcpus),
('rxtx_factor', self.flavor.rxtx_factor),
('public', False),
('project', identity_fakes.project_id),
('project', self.project.id),
('property', {'key1': 'value1', 'key2': 'value2'}),
('name', self.flavor.name),
]
@ -209,7 +203,7 @@ class TestFlavorCreate(TestFlavor):
self.flavors_mock.create.assert_called_once_with(*args)
self.flavor_access_mock.add_tenant_access.assert_called_with(
self.flavor.id,
identity_fakes.project_id,
self.project.id,
)
self.flavor.set_keys.assert_called_with(
{'key1': 'value1', 'key2': 'value2'})
@ -219,11 +213,11 @@ class TestFlavorCreate(TestFlavor):
def test_public_flavor_create_with_project(self):
arglist = [
'--project', identity_fakes.project_id,
'--project', self.project.id,
self.flavor.name,
]
verifylist = [
('project', identity_fakes.project_id),
('project', self.project.id),
('name', self.flavor.name),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -507,6 +501,7 @@ class TestFlavorSet(TestFlavor):
# Return value of self.flavors_mock.find().
flavor = compute_fakes.FakeFlavor.create_one_flavor(
attrs={'os-flavor-access:is_public': False})
project = identity_fakes.FakeProject.create_one_project()
def setUp(self):
super(TestFlavorSet, self).setUp()
@ -514,11 +509,7 @@ class TestFlavorSet(TestFlavor):
self.flavors_mock.find.return_value = self.flavor
self.flavors_mock.get.side_effect = exceptions.NotFound(None)
# Return a project
self.projects_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.PROJECT),
loaded=True,
)
self.projects_mock.get.return_value = self.project
self.cmd = flavor.SetFlavor(self.app, None)
def test_flavor_set_property(self):
@ -540,11 +531,11 @@ class TestFlavorSet(TestFlavor):
def test_flavor_set_project(self):
arglist = [
'--project', identity_fakes.project_id,
'--project', self.project.id,
self.flavor.id,
]
verifylist = [
('project', identity_fakes.project_id),
('project', self.project.id),
('flavor', self.flavor.id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -555,7 +546,7 @@ class TestFlavorSet(TestFlavor):
is_public=None)
self.flavor_access_mock.add_tenant_access.assert_called_with(
self.flavor.id,
identity_fakes.project_id,
self.project.id,
)
self.flavor.set_keys.assert_not_called()
self.assertIsNone(result)
@ -574,10 +565,10 @@ class TestFlavorSet(TestFlavor):
def test_flavor_set_no_flavor(self):
arglist = [
'--project', identity_fakes.project_id,
'--project', self.project.id,
]
verifylist = [
('project', identity_fakes.project_id),
('project', self.project.id),
]
self.assertRaises(tests_utils.ParserException, self.check_parser,
self.cmd, arglist, verifylist)
@ -587,11 +578,11 @@ class TestFlavorSet(TestFlavor):
self.flavors_mock.find.side_effect = exceptions.NotFound(None)
arglist = [
'--project', identity_fakes.project_id,
'--project', self.project.id,
'unexist_flavor',
]
verifylist = [
('project', identity_fakes.project_id),
('project', self.project.id),
('flavor', 'unexist_flavor'),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -729,6 +720,7 @@ class TestFlavorUnset(TestFlavor):
# Return value of self.flavors_mock.find().
flavor = compute_fakes.FakeFlavor.create_one_flavor(
attrs={'os-flavor-access:is_public': False})
project = identity_fakes.FakeProject.create_one_project()
def setUp(self):
super(TestFlavorUnset, self).setUp()
@ -736,11 +728,7 @@ class TestFlavorUnset(TestFlavor):
self.flavors_mock.find.return_value = self.flavor
self.flavors_mock.get.side_effect = exceptions.NotFound(None)
# Return a project
self.projects_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.PROJECT),
loaded=True,
)
self.projects_mock.get.return_value = self.project
self.cmd = flavor.UnsetFlavor(self.app, None)
def test_flavor_unset_property(self):
@ -763,11 +751,11 @@ class TestFlavorUnset(TestFlavor):
def test_flavor_unset_project(self):
arglist = [
'--project', identity_fakes.project_id,
'--project', self.project.id,
self.flavor.id,
]
verifylist = [
('project', identity_fakes.project_id),
('project', self.project.id),
('flavor', self.flavor.id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -779,7 +767,7 @@ class TestFlavorUnset(TestFlavor):
is_public=None)
self.flavor_access_mock.remove_tenant_access.assert_called_with(
self.flavor.id,
identity_fakes.project_id,
self.project.id,
)
self.flavor.unset_keys.assert_not_called()
self.assertIsNone(result)
@ -798,10 +786,10 @@ class TestFlavorUnset(TestFlavor):
def test_flavor_unset_no_flavor(self):
arglist = [
'--project', identity_fakes.project_id,
'--project', self.project.id,
]
verifylist = [
('project', identity_fakes.project_id),
('project', self.project.id),
]
self.assertRaises(tests_utils.ParserException, self.check_parser,
self.cmd, arglist, verifylist)
@ -811,11 +799,11 @@ class TestFlavorUnset(TestFlavor):
self.flavors_mock.find.side_effect = exceptions.NotFound(None)
arglist = [
'--project', identity_fakes.project_id,
'--project', self.project.id,
'unexist_flavor',
]
verifylist = [
('project', identity_fakes.project_id),
('project', self.project.id),
('flavor', 'unexist_flavor'),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)

View File

@ -23,7 +23,6 @@ from osc_lib import exceptions
from osc_lib import utils as common_utils
from openstackclient.image.v2 import image
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
@ -58,23 +57,18 @@ class TestImage(image_fakes.TestImagev2):
class TestImageCreate(TestImage):
project = identity_fakes.FakeProject.create_one_project()
domain = identity_fakes.FakeDomain.create_one_domain()
def setUp(self):
super(TestImageCreate, self).setUp()
self.new_image = image_fakes.FakeImage.create_one_image()
self.images_mock.create.return_value = self.new_image
self.project_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.PROJECT),
loaded=True,
)
self.project_mock.get.return_value = self.project
self.domain_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.DOMAIN),
loaded=True,
)
self.domain_mock.get.return_value = self.domain
# This is the return value for utils.find_resource()
self.images_mock.get.return_value = copy.deepcopy(
@ -145,7 +139,7 @@ class TestImageCreate(TestImage):
('--private'
if self.new_image.visibility == 'private' else '--public'),
'--project', self.new_image.owner,
'--project-domain', identity_fakes.domain_id,
'--project-domain', self.domain.id,
self.new_image.name,
]
verifylist = [
@ -158,7 +152,7 @@ class TestImageCreate(TestImage):
('public', self.new_image.visibility == 'public'),
('private', self.new_image.visibility == 'private'),
('project', self.new_image.owner),
('project_domain', identity_fakes.domain_id),
('project_domain', self.domain.id),
('name', self.new_image.name),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -175,7 +169,7 @@ class TestImageCreate(TestImage):
disk_format='fs',
min_disk=10,
min_ram=4,
owner=identity_fakes.project_id,
owner=self.project.id,
protected=self.new_image.protected,
visibility=self.new_image.visibility,
)
@ -346,10 +340,12 @@ class TestImageCreate(TestImage):
class TestAddProjectToImage(TestImage):
project = identity_fakes.FakeProject.create_one_project()
domain = identity_fakes.FakeDomain.create_one_domain()
_image = image_fakes.FakeImage.create_one_image()
new_member = image_fakes.FakeImage.create_one_image_member(
attrs={'image_id': _image.id,
'member_id': identity_fakes.project_id}
'member_id': project.id}
)
columns = (
@ -360,8 +356,8 @@ class TestAddProjectToImage(TestImage):
datalist = (
_image.id,
identity_fakes.project_id,
new_member.status
new_member.member_id,
new_member.status,
)
def setUp(self):
@ -372,27 +368,19 @@ class TestAddProjectToImage(TestImage):
# Update the image_id in the MEMBER dict
self.image_members_mock.create.return_value = self.new_member
self.project_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.PROJECT),
loaded=True,
)
self.domain_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.DOMAIN),
loaded=True,
)
self.project_mock.get.return_value = self.project
self.domain_mock.get.return_value = self.domain
# Get the command object to test
self.cmd = image.AddProjectToImage(self.app, None)
def test_add_project_to_image_no_option(self):
arglist = [
self._image.id,
identity_fakes.project_id,
self.project.id,
]
verifylist = [
('image', self._image.id),
('project', identity_fakes.project_id),
('project', self.project.id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -402,7 +390,7 @@ class TestAddProjectToImage(TestImage):
columns, data = self.cmd.take_action(parsed_args)
self.image_members_mock.create.assert_called_with(
self._image.id,
identity_fakes.project_id
self.project.id
)
self.assertEqual(self.columns, columns)
@ -411,13 +399,13 @@ class TestAddProjectToImage(TestImage):
def test_add_project_to_image_with_option(self):
arglist = [
self._image.id,
identity_fakes.project_id,
'--project-domain', identity_fakes.domain_id,
self.project.id,
'--project-domain', self.domain.id,
]
verifylist = [
('image', self._image.id),
('project', identity_fakes.project_id),
('project_domain', identity_fakes.domain_id),
('project', self.project.id),
('project_domain', self.domain.id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -427,7 +415,7 @@ class TestAddProjectToImage(TestImage):
columns, data = self.cmd.take_action(parsed_args)
self.image_members_mock.create.assert_called_with(
self._image.id,
identity_fakes.project_id
self.project.id
)
self.assertEqual(self.columns, columns)
self.assertEqual(self.datalist, data)
@ -755,6 +743,9 @@ class TestImageList(TestImage):
class TestRemoveProjectImage(TestImage):
project = identity_fakes.FakeProject.create_one_project()
domain = identity_fakes.FakeDomain.create_one_domain()
def setUp(self):
super(TestRemoveProjectImage, self).setUp()
@ -762,16 +753,8 @@ class TestRemoveProjectImage(TestImage):
# This is the return value for utils.find_resource()
self.images_mock.get.return_value = self._image
self.project_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.PROJECT),
loaded=True,
)
self.domain_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.DOMAIN),
loaded=True,
)
self.project_mock.get.return_value = self.project
self.domain_mock.get.return_value = self.domain
self.image_members_mock.delete.return_value = None
# Get the command object to test
self.cmd = image.RemoveProjectImage(self.app, None)
@ -779,11 +762,11 @@ class TestRemoveProjectImage(TestImage):
def test_remove_project_image_no_options(self):
arglist = [
self._image.id,
identity_fakes.project_id,
self.project.id,
]
verifylist = [
('image', self._image.id),
('project', identity_fakes.project_id),
('project', self.project.id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -791,20 +774,20 @@ class TestRemoveProjectImage(TestImage):
self.image_members_mock.delete.assert_called_with(
self._image.id,
identity_fakes.project_id,
self.project.id,
)
self.assertIsNone(result)
def test_remove_project_image_with_options(self):
arglist = [
self._image.id,
identity_fakes.project_id,
'--project-domain', identity_fakes.domain_id,
self.project.id,
'--project-domain', self.domain.id,
]
verifylist = [
('image', self._image.id),
('project', identity_fakes.project_id),
('project_domain', identity_fakes.domain_id),
('project', self.project.id),
('project_domain', self.domain.id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -812,13 +795,16 @@ class TestRemoveProjectImage(TestImage):
self.image_members_mock.delete.assert_called_with(
self._image.id,
identity_fakes.project_id,
self.project.id,
)
self.assertIsNone(result)
class TestImageSet(TestImage):
project = identity_fakes.FakeProject.create_one_project()
domain = identity_fakes.FakeDomain.create_one_domain()
def setUp(self):
super(TestImageSet, self).setUp()
# Set up the schema
@ -827,17 +813,9 @@ class TestImageSet(TestImage):
schemas.SchemaBasedModel,
)
self.project_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.PROJECT),
loaded=True,
)
self.project_mock.get.return_value = self.project
self.domain_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.DOMAIN),
loaded=True,
)
self.domain_mock.get.return_value = self.domain
self.images_mock.get.return_value = self.model(**image_fakes.IMAGE)
self.images_mock.update.return_value = self.model(**image_fakes.IMAGE)
@ -864,8 +842,8 @@ class TestImageSet(TestImage):
'--min-ram', '4',
'--container-format', 'ovf',
'--disk-format', 'vmdk',
'--project', identity_fakes.project_name,
'--project-domain', identity_fakes.domain_id,
'--project', self.project.name,
'--project-domain', self.domain.id,
image_fakes.image_id,
]
verifylist = [
@ -874,8 +852,8 @@ class TestImageSet(TestImage):
('min_ram', 4),
('container_format', 'ovf'),
('disk_format', 'vmdk'),
('project', identity_fakes.project_name),
('project_domain', identity_fakes.domain_id),
('project', self.project.name),
('project_domain', self.domain.id),
('image', image_fakes.image_id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -884,7 +862,7 @@ class TestImageSet(TestImage):
kwargs = {
'name': 'new-name',
'owner': identity_fakes.project_id,
'owner': self.project.id,
'min_disk': 2,
'min_ram': 4,
'container_format': 'ovf',

View File

@ -50,6 +50,9 @@ class TestVolume(volume_fakes.TestVolumev1):
class TestVolumeCreate(TestVolume):
project = identity_fakes.FakeProject.create_one_project()
user = identity_fakes.FakeUser.create_one_user()
columns = (
'attach_status',
'availability_zone',
@ -168,28 +171,20 @@ class TestVolumeCreate(TestVolume):
def test_volume_create_user_project_id(self):
# Return a project
self.projects_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.PROJECT),
loaded=True,
)
self.projects_mock.get.return_value = self.project
# Return a user
self.users_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.USER),
loaded=True,
)
self.users_mock.get.return_value = self.user
arglist = [
'--size', str(volume_fakes.volume_size),
'--project', identity_fakes.project_id,
'--user', identity_fakes.user_id,
'--project', self.project.id,
'--user', self.user.id,
volume_fakes.volume_name,
]
verifylist = [
('size', volume_fakes.volume_size),
('project', identity_fakes.project_id),
('user', identity_fakes.user_id),
('project', self.project.id),
('user', self.user.id),
('name', volume_fakes.volume_name),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -211,8 +206,8 @@ class TestVolumeCreate(TestVolume):
volume_fakes.volume_name,
None,
None,
identity_fakes.user_id,
identity_fakes.project_id,
self.user.id,
self.project.id,
None,
None,
None,
@ -223,28 +218,20 @@ class TestVolumeCreate(TestVolume):
def test_volume_create_user_project_name(self):
# Return a project
self.projects_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.PROJECT),
loaded=True,
)
self.projects_mock.get.return_value = self.project
# Return a user
self.users_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.USER),
loaded=True,
)
self.users_mock.get.return_value = self.user
arglist = [
'--size', str(volume_fakes.volume_size),
'--project', identity_fakes.project_name,
'--user', identity_fakes.user_name,
'--project', self.project.name,
'--user', self.user.name,
volume_fakes.volume_name,
]
verifylist = [
('size', volume_fakes.volume_size),
('project', identity_fakes.project_name),
('user', identity_fakes.user_name),
('project', self.project.name),
('user', self.user.name),
('name', volume_fakes.volume_name),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -266,8 +253,8 @@ class TestVolumeCreate(TestVolume):
volume_fakes.volume_name,
None,
None,
identity_fakes.user_id,
identity_fakes.project_id,
self.user.id,
self.project.id,
None,
None,
None,

View File

@ -12,13 +12,11 @@
# under the License.
#
import copy
import mock
from osc_lib import exceptions
from osc_lib import utils
from openstackclient.tests import fakes
from openstackclient.tests.identity.v3 import fakes as identity_fakes
from openstackclient.tests import utils as tests_utils
from openstackclient.tests.volume.v2 import fakes as volume_fakes
@ -219,6 +217,7 @@ class TestTypeList(TestType):
class TestTypeSet(TestType):
project = identity_fakes.FakeProject.create_one_project()
volume_type = volume_fakes.FakeType.create_one_type(
methods={'set_keys': None})
@ -228,11 +227,7 @@ class TestTypeSet(TestType):
self.types_mock.get.return_value = self.volume_type
# Return a project
self.projects_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.PROJECT),
loaded=True,
)
self.projects_mock.get.return_value = self.project
# Get the command object to test
self.cmd = volume_type.SetVolumeType(self.app, None)
@ -339,11 +334,11 @@ class TestTypeSet(TestType):
def test_type_set_project_access(self):
arglist = [
'--project', identity_fakes.project_id,
'--project', self.project.id,
self.volume_type.id,
]
verifylist = [
('project', identity_fakes.project_id),
('project', self.project.id),
('volume_type', self.volume_type.id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -353,7 +348,7 @@ class TestTypeSet(TestType):
self.types_access_mock.add_project_access.assert_called_with(
self.volume_type.id,
identity_fakes.project_id,
self.project.id,
)
@ -469,6 +464,7 @@ class TestTypeShow(TestType):
class TestTypeUnset(TestType):
project = identity_fakes.FakeProject.create_one_project()
volume_type = volume_fakes.FakeType.create_one_type(
methods={'unset_keys': None})
@ -478,11 +474,7 @@ class TestTypeUnset(TestType):
self.types_mock.get.return_value = self.volume_type
# Return a project
self.projects_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.PROJECT),
loaded=True,
)
self.projects_mock.get.return_value = self.project
# Get the command object to test
self.cmd = volume_type.UnsetVolumeType(self.app, None)
@ -507,11 +499,11 @@ class TestTypeUnset(TestType):
def test_type_unset_project_access(self):
arglist = [
'--project', identity_fakes.project_id,
'--project', self.project.id,
self.volume_type.id,
]
verifylist = [
('project', identity_fakes.project_id),
('project', self.project.id),
('volume_type', self.volume_type.id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -521,7 +513,7 @@ class TestTypeUnset(TestType):
self.types_access_mock.remove_project_access.assert_called_with(
self.volume_type.id,
identity_fakes.project_id,
self.project.id,
)
def test_type_unset_not_called_without_project_argument(self):

View File

@ -12,14 +12,12 @@
# under the License.
#
import copy
import mock
from mock import call
from osc_lib import exceptions
from osc_lib 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
@ -57,6 +55,9 @@ class TestVolume(volume_fakes.TestVolume):
class TestVolumeCreate(TestVolume):
project = identity_fakes.FakeProject.create_one_project()
user = identity_fakes.FakeUser.create_one_user()
columns = (
'attachments',
'availability_zone',
@ -168,28 +169,20 @@ class TestVolumeCreate(TestVolume):
def test_volume_create_user_project_id(self):
# Return a project
self.projects_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.PROJECT),
loaded=True,
)
self.projects_mock.get.return_value = self.project
# Return a user
self.users_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.USER),
loaded=True,
)
self.users_mock.get.return_value = self.user
arglist = [
'--size', str(self.new_volume.size),
'--project', identity_fakes.project_id,
'--user', identity_fakes.user_id,
'--project', self.project.id,
'--user', self.user.id,
self.new_volume.name,
]
verifylist = [
('size', self.new_volume.size),
('project', identity_fakes.project_id),
('user', identity_fakes.user_id),
('project', self.project.id),
('user', self.user.id),
('name', self.new_volume.name),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -205,8 +198,8 @@ class TestVolumeCreate(TestVolume):
name=self.new_volume.name,
description=None,
volume_type=None,
user_id=identity_fakes.user_id,
project_id=identity_fakes.project_id,
user_id=self.user.id,
project_id=self.project.id,
availability_zone=None,
metadata=None,
imageRef=None,
@ -218,28 +211,20 @@ class TestVolumeCreate(TestVolume):
def test_volume_create_user_project_name(self):
# Return a project
self.projects_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.PROJECT),
loaded=True,
)
self.projects_mock.get.return_value = self.project
# Return a user
self.users_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.USER),
loaded=True,
)
self.users_mock.get.return_value = self.user
arglist = [
'--size', str(self.new_volume.size),
'--project', identity_fakes.project_name,
'--user', identity_fakes.user_name,
'--project', self.project.name,
'--user', self.user.name,
self.new_volume.name,
]
verifylist = [
('size', self.new_volume.size),
('project', identity_fakes.project_name),
('user', identity_fakes.user_name),
('project', self.project.name),
('user', self.user.name),
('name', self.new_volume.name),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -255,8 +240,8 @@ class TestVolumeCreate(TestVolume):
name=self.new_volume.name,
description=None,
volume_type=None,
user_id=identity_fakes.user_id,
project_id=identity_fakes.project_id,
user_id=self.user.id,
project_id=self.project.id,
availability_zone=None,
metadata=None,
imageRef=None,
@ -492,6 +477,9 @@ class TestVolumeDelete(TestVolume):
class TestVolumeList(TestVolume):
project = identity_fakes.FakeProject.create_one_project()
user = identity_fakes.FakeUser.create_one_user()
columns = [
'ID',
'Display Name',
@ -506,21 +494,9 @@ class TestVolumeList(TestVolume):
self.mock_volume = volume_fakes.FakeVolume.create_one_volume()
self.volumes_mock.list.return_value = [self.mock_volume]
self.users_mock.get.return_value = [
fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.USER),
loaded=True,
),
]
self.users_mock.get.return_value = self.user
self.projects_mock.get.return_value = [
fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.PROJECT),
loaded=True,
),
]
self.projects_mock.get.return_value = self.project
# Get the command object to test
self.cmd = volume.ListVolume(self.app, None)
@ -553,10 +529,10 @@ class TestVolumeList(TestVolume):
def test_volume_list_project(self):
arglist = [
'--project', identity_fakes.project_name,
'--project', self.project.name,
]
verifylist = [
('project', identity_fakes.project_name),
('project', self.project.name),
('long', False),
('all_projects', False),
('status', None),
@ -581,12 +557,12 @@ class TestVolumeList(TestVolume):
def test_volume_list_project_domain(self):
arglist = [
'--project', identity_fakes.project_name,
'--project-domain', identity_fakes.domain_name,
'--project', self.project.name,
'--project-domain', self.project.domain_id,
]
verifylist = [
('project', identity_fakes.project_name),
('project_domain', identity_fakes.domain_name),
('project', self.project.name),
('project_domain', self.project.domain_id),
('long', False),
('all_projects', False),
('status', None),
@ -611,10 +587,10 @@ class TestVolumeList(TestVolume):
def test_volume_list_user(self):
arglist = [
'--user', identity_fakes.user_name,
'--user', self.user.name,
]
verifylist = [
('user', identity_fakes.user_name),
('user', self.user.name),
('long', False),
('all_projects', False),
('status', None),
@ -638,12 +614,12 @@ class TestVolumeList(TestVolume):
def test_volume_list_user_domain(self):
arglist = [
'--user', identity_fakes.user_name,
'--user-domain', identity_fakes.domain_name,
'--user', self.user.name,
'--user-domain', self.user.domain_id,
]
verifylist = [
('user', identity_fakes.user_name),
('user_domain', identity_fakes.domain_name),
('user', self.user.name),
('user_domain', self.user.domain_id),
('long', False),
('all_projects', False),
('status', None),