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. # under the License.
# #
import copy
import mock import mock
from mock import call from mock import call
@ -22,7 +21,6 @@ from osc_lib import utils
from openstackclient.compute.v2 import flavor from openstackclient.compute.v2 import flavor
from openstackclient.tests.compute.v2 import fakes as compute_fakes 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.identity.v3 import fakes as identity_fakes
from openstackclient.tests import utils as tests_utils from openstackclient.tests import utils as tests_utils
@ -48,7 +46,7 @@ class TestFlavorCreate(TestFlavor):
flavor = compute_fakes.FakeFlavor.create_one_flavor( flavor = compute_fakes.FakeFlavor.create_one_flavor(
attrs={'links': 'flavor-links'}) attrs={'links': 'flavor-links'})
project = identity_fakes.FakeProject.create_one_project()
columns = ( columns = (
'OS-FLV-DISABLED:disabled', 'OS-FLV-DISABLED:disabled',
'OS-FLV-EXT-DATA:ephemeral', 'OS-FLV-EXT-DATA:ephemeral',
@ -80,11 +78,7 @@ class TestFlavorCreate(TestFlavor):
super(TestFlavorCreate, self).setUp() super(TestFlavorCreate, self).setUp()
# Return a project # Return a project
self.projects_mock.get.return_value = fakes.FakeResource( self.projects_mock.get.return_value = self.project
None,
copy.deepcopy(identity_fakes.PROJECT),
loaded=True,
)
self.flavors_mock.create.return_value = self.flavor self.flavors_mock.create.return_value = self.flavor
self.cmd = flavor.CreateFlavor(self.app, None) self.cmd = flavor.CreateFlavor(self.app, None)
@ -174,7 +168,7 @@ class TestFlavorCreate(TestFlavor):
'--vcpus', str(self.flavor.vcpus), '--vcpus', str(self.flavor.vcpus),
'--rxtx-factor', str(self.flavor.rxtx_factor), '--rxtx-factor', str(self.flavor.rxtx_factor),
'--private', '--private',
'--project', identity_fakes.project_id, '--project', self.project.id,
'--property', 'key1=value1', '--property', 'key1=value1',
'--property', 'key2=value2', '--property', 'key2=value2',
self.flavor.name, self.flavor.name,
@ -188,7 +182,7 @@ class TestFlavorCreate(TestFlavor):
('vcpus', self.flavor.vcpus), ('vcpus', self.flavor.vcpus),
('rxtx_factor', self.flavor.rxtx_factor), ('rxtx_factor', self.flavor.rxtx_factor),
('public', False), ('public', False),
('project', identity_fakes.project_id), ('project', self.project.id),
('property', {'key1': 'value1', 'key2': 'value2'}), ('property', {'key1': 'value1', 'key2': 'value2'}),
('name', self.flavor.name), ('name', self.flavor.name),
] ]
@ -209,7 +203,7 @@ class TestFlavorCreate(TestFlavor):
self.flavors_mock.create.assert_called_once_with(*args) self.flavors_mock.create.assert_called_once_with(*args)
self.flavor_access_mock.add_tenant_access.assert_called_with( self.flavor_access_mock.add_tenant_access.assert_called_with(
self.flavor.id, self.flavor.id,
identity_fakes.project_id, self.project.id,
) )
self.flavor.set_keys.assert_called_with( self.flavor.set_keys.assert_called_with(
{'key1': 'value1', 'key2': 'value2'}) {'key1': 'value1', 'key2': 'value2'})
@ -219,11 +213,11 @@ class TestFlavorCreate(TestFlavor):
def test_public_flavor_create_with_project(self): def test_public_flavor_create_with_project(self):
arglist = [ arglist = [
'--project', identity_fakes.project_id, '--project', self.project.id,
self.flavor.name, self.flavor.name,
] ]
verifylist = [ verifylist = [
('project', identity_fakes.project_id), ('project', self.project.id),
('name', self.flavor.name), ('name', self.flavor.name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -507,6 +501,7 @@ class TestFlavorSet(TestFlavor):
# Return value of self.flavors_mock.find(). # Return value of self.flavors_mock.find().
flavor = compute_fakes.FakeFlavor.create_one_flavor( flavor = compute_fakes.FakeFlavor.create_one_flavor(
attrs={'os-flavor-access:is_public': False}) attrs={'os-flavor-access:is_public': False})
project = identity_fakes.FakeProject.create_one_project()
def setUp(self): def setUp(self):
super(TestFlavorSet, self).setUp() super(TestFlavorSet, self).setUp()
@ -514,11 +509,7 @@ class TestFlavorSet(TestFlavor):
self.flavors_mock.find.return_value = self.flavor self.flavors_mock.find.return_value = self.flavor
self.flavors_mock.get.side_effect = exceptions.NotFound(None) self.flavors_mock.get.side_effect = exceptions.NotFound(None)
# Return a project # Return a project
self.projects_mock.get.return_value = fakes.FakeResource( self.projects_mock.get.return_value = self.project
None,
copy.deepcopy(identity_fakes.PROJECT),
loaded=True,
)
self.cmd = flavor.SetFlavor(self.app, None) self.cmd = flavor.SetFlavor(self.app, None)
def test_flavor_set_property(self): def test_flavor_set_property(self):
@ -540,11 +531,11 @@ class TestFlavorSet(TestFlavor):
def test_flavor_set_project(self): def test_flavor_set_project(self):
arglist = [ arglist = [
'--project', identity_fakes.project_id, '--project', self.project.id,
self.flavor.id, self.flavor.id,
] ]
verifylist = [ verifylist = [
('project', identity_fakes.project_id), ('project', self.project.id),
('flavor', self.flavor.id), ('flavor', self.flavor.id),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -555,7 +546,7 @@ class TestFlavorSet(TestFlavor):
is_public=None) is_public=None)
self.flavor_access_mock.add_tenant_access.assert_called_with( self.flavor_access_mock.add_tenant_access.assert_called_with(
self.flavor.id, self.flavor.id,
identity_fakes.project_id, self.project.id,
) )
self.flavor.set_keys.assert_not_called() self.flavor.set_keys.assert_not_called()
self.assertIsNone(result) self.assertIsNone(result)
@ -574,10 +565,10 @@ class TestFlavorSet(TestFlavor):
def test_flavor_set_no_flavor(self): def test_flavor_set_no_flavor(self):
arglist = [ arglist = [
'--project', identity_fakes.project_id, '--project', self.project.id,
] ]
verifylist = [ verifylist = [
('project', identity_fakes.project_id), ('project', self.project.id),
] ]
self.assertRaises(tests_utils.ParserException, self.check_parser, self.assertRaises(tests_utils.ParserException, self.check_parser,
self.cmd, arglist, verifylist) self.cmd, arglist, verifylist)
@ -587,11 +578,11 @@ class TestFlavorSet(TestFlavor):
self.flavors_mock.find.side_effect = exceptions.NotFound(None) self.flavors_mock.find.side_effect = exceptions.NotFound(None)
arglist = [ arglist = [
'--project', identity_fakes.project_id, '--project', self.project.id,
'unexist_flavor', 'unexist_flavor',
] ]
verifylist = [ verifylist = [
('project', identity_fakes.project_id), ('project', self.project.id),
('flavor', 'unexist_flavor'), ('flavor', 'unexist_flavor'),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -729,6 +720,7 @@ class TestFlavorUnset(TestFlavor):
# Return value of self.flavors_mock.find(). # Return value of self.flavors_mock.find().
flavor = compute_fakes.FakeFlavor.create_one_flavor( flavor = compute_fakes.FakeFlavor.create_one_flavor(
attrs={'os-flavor-access:is_public': False}) attrs={'os-flavor-access:is_public': False})
project = identity_fakes.FakeProject.create_one_project()
def setUp(self): def setUp(self):
super(TestFlavorUnset, self).setUp() super(TestFlavorUnset, self).setUp()
@ -736,11 +728,7 @@ class TestFlavorUnset(TestFlavor):
self.flavors_mock.find.return_value = self.flavor self.flavors_mock.find.return_value = self.flavor
self.flavors_mock.get.side_effect = exceptions.NotFound(None) self.flavors_mock.get.side_effect = exceptions.NotFound(None)
# Return a project # Return a project
self.projects_mock.get.return_value = fakes.FakeResource( self.projects_mock.get.return_value = self.project
None,
copy.deepcopy(identity_fakes.PROJECT),
loaded=True,
)
self.cmd = flavor.UnsetFlavor(self.app, None) self.cmd = flavor.UnsetFlavor(self.app, None)
def test_flavor_unset_property(self): def test_flavor_unset_property(self):
@ -763,11 +751,11 @@ class TestFlavorUnset(TestFlavor):
def test_flavor_unset_project(self): def test_flavor_unset_project(self):
arglist = [ arglist = [
'--project', identity_fakes.project_id, '--project', self.project.id,
self.flavor.id, self.flavor.id,
] ]
verifylist = [ verifylist = [
('project', identity_fakes.project_id), ('project', self.project.id),
('flavor', self.flavor.id), ('flavor', self.flavor.id),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -779,7 +767,7 @@ class TestFlavorUnset(TestFlavor):
is_public=None) is_public=None)
self.flavor_access_mock.remove_tenant_access.assert_called_with( self.flavor_access_mock.remove_tenant_access.assert_called_with(
self.flavor.id, self.flavor.id,
identity_fakes.project_id, self.project.id,
) )
self.flavor.unset_keys.assert_not_called() self.flavor.unset_keys.assert_not_called()
self.assertIsNone(result) self.assertIsNone(result)
@ -798,10 +786,10 @@ class TestFlavorUnset(TestFlavor):
def test_flavor_unset_no_flavor(self): def test_flavor_unset_no_flavor(self):
arglist = [ arglist = [
'--project', identity_fakes.project_id, '--project', self.project.id,
] ]
verifylist = [ verifylist = [
('project', identity_fakes.project_id), ('project', self.project.id),
] ]
self.assertRaises(tests_utils.ParserException, self.check_parser, self.assertRaises(tests_utils.ParserException, self.check_parser,
self.cmd, arglist, verifylist) self.cmd, arglist, verifylist)
@ -811,11 +799,11 @@ class TestFlavorUnset(TestFlavor):
self.flavors_mock.find.side_effect = exceptions.NotFound(None) self.flavors_mock.find.side_effect = exceptions.NotFound(None)
arglist = [ arglist = [
'--project', identity_fakes.project_id, '--project', self.project.id,
'unexist_flavor', 'unexist_flavor',
] ]
verifylist = [ verifylist = [
('project', identity_fakes.project_id), ('project', self.project.id),
('flavor', 'unexist_flavor'), ('flavor', 'unexist_flavor'),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) 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 osc_lib import utils as common_utils
from openstackclient.image.v2 import image from openstackclient.image.v2 import image
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.image.v2 import fakes as image_fakes
@ -58,23 +57,18 @@ class TestImage(image_fakes.TestImagev2):
class TestImageCreate(TestImage): class TestImageCreate(TestImage):
project = identity_fakes.FakeProject.create_one_project()
domain = identity_fakes.FakeDomain.create_one_domain()
def setUp(self): def setUp(self):
super(TestImageCreate, self).setUp() super(TestImageCreate, self).setUp()
self.new_image = image_fakes.FakeImage.create_one_image() self.new_image = image_fakes.FakeImage.create_one_image()
self.images_mock.create.return_value = self.new_image self.images_mock.create.return_value = self.new_image
self.project_mock.get.return_value = fakes.FakeResource( self.project_mock.get.return_value = self.project
None,
copy.deepcopy(identity_fakes.PROJECT),
loaded=True,
)
self.domain_mock.get.return_value = fakes.FakeResource( self.domain_mock.get.return_value = self.domain
None,
copy.deepcopy(identity_fakes.DOMAIN),
loaded=True,
)
# This is the return value for utils.find_resource() # This is the return value for utils.find_resource()
self.images_mock.get.return_value = copy.deepcopy( self.images_mock.get.return_value = copy.deepcopy(
@ -145,7 +139,7 @@ class TestImageCreate(TestImage):
('--private' ('--private'
if self.new_image.visibility == 'private' else '--public'), if self.new_image.visibility == 'private' else '--public'),
'--project', self.new_image.owner, '--project', self.new_image.owner,
'--project-domain', identity_fakes.domain_id, '--project-domain', self.domain.id,
self.new_image.name, self.new_image.name,
] ]
verifylist = [ verifylist = [
@ -158,7 +152,7 @@ class TestImageCreate(TestImage):
('public', self.new_image.visibility == 'public'), ('public', self.new_image.visibility == 'public'),
('private', self.new_image.visibility == 'private'), ('private', self.new_image.visibility == 'private'),
('project', self.new_image.owner), ('project', self.new_image.owner),
('project_domain', identity_fakes.domain_id), ('project_domain', self.domain.id),
('name', self.new_image.name), ('name', self.new_image.name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -175,7 +169,7 @@ class TestImageCreate(TestImage):
disk_format='fs', disk_format='fs',
min_disk=10, min_disk=10,
min_ram=4, min_ram=4,
owner=identity_fakes.project_id, owner=self.project.id,
protected=self.new_image.protected, protected=self.new_image.protected,
visibility=self.new_image.visibility, visibility=self.new_image.visibility,
) )
@ -346,10 +340,12 @@ class TestImageCreate(TestImage):
class TestAddProjectToImage(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() _image = image_fakes.FakeImage.create_one_image()
new_member = image_fakes.FakeImage.create_one_image_member( new_member = image_fakes.FakeImage.create_one_image_member(
attrs={'image_id': _image.id, attrs={'image_id': _image.id,
'member_id': identity_fakes.project_id} 'member_id': project.id}
) )
columns = ( columns = (
@ -360,8 +356,8 @@ class TestAddProjectToImage(TestImage):
datalist = ( datalist = (
_image.id, _image.id,
identity_fakes.project_id, new_member.member_id,
new_member.status new_member.status,
) )
def setUp(self): def setUp(self):
@ -372,27 +368,19 @@ class TestAddProjectToImage(TestImage):
# Update the image_id in the MEMBER dict # Update the image_id in the MEMBER dict
self.image_members_mock.create.return_value = self.new_member self.image_members_mock.create.return_value = self.new_member
self.project_mock.get.return_value = fakes.FakeResource( self.project_mock.get.return_value = self.project
None, self.domain_mock.get.return_value = self.domain
copy.deepcopy(identity_fakes.PROJECT),
loaded=True,
)
self.domain_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.DOMAIN),
loaded=True,
)
# Get the command object to test # Get the command object to test
self.cmd = image.AddProjectToImage(self.app, None) self.cmd = image.AddProjectToImage(self.app, None)
def test_add_project_to_image_no_option(self): def test_add_project_to_image_no_option(self):
arglist = [ arglist = [
self._image.id, self._image.id,
identity_fakes.project_id, self.project.id,
] ]
verifylist = [ verifylist = [
('image', self._image.id), ('image', self._image.id),
('project', identity_fakes.project_id), ('project', self.project.id),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -402,7 +390,7 @@ class TestAddProjectToImage(TestImage):
columns, data = self.cmd.take_action(parsed_args) columns, data = self.cmd.take_action(parsed_args)
self.image_members_mock.create.assert_called_with( self.image_members_mock.create.assert_called_with(
self._image.id, self._image.id,
identity_fakes.project_id self.project.id
) )
self.assertEqual(self.columns, columns) self.assertEqual(self.columns, columns)
@ -411,13 +399,13 @@ class TestAddProjectToImage(TestImage):
def test_add_project_to_image_with_option(self): def test_add_project_to_image_with_option(self):
arglist = [ arglist = [
self._image.id, self._image.id,
identity_fakes.project_id, self.project.id,
'--project-domain', identity_fakes.domain_id, '--project-domain', self.domain.id,
] ]
verifylist = [ verifylist = [
('image', self._image.id), ('image', self._image.id),
('project', identity_fakes.project_id), ('project', self.project.id),
('project_domain', identity_fakes.domain_id), ('project_domain', self.domain.id),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -427,7 +415,7 @@ class TestAddProjectToImage(TestImage):
columns, data = self.cmd.take_action(parsed_args) columns, data = self.cmd.take_action(parsed_args)
self.image_members_mock.create.assert_called_with( self.image_members_mock.create.assert_called_with(
self._image.id, self._image.id,
identity_fakes.project_id self.project.id
) )
self.assertEqual(self.columns, columns) self.assertEqual(self.columns, columns)
self.assertEqual(self.datalist, data) self.assertEqual(self.datalist, data)
@ -755,6 +743,9 @@ class TestImageList(TestImage):
class TestRemoveProjectImage(TestImage): class TestRemoveProjectImage(TestImage):
project = identity_fakes.FakeProject.create_one_project()
domain = identity_fakes.FakeDomain.create_one_domain()
def setUp(self): def setUp(self):
super(TestRemoveProjectImage, self).setUp() super(TestRemoveProjectImage, self).setUp()
@ -762,16 +753,8 @@ class TestRemoveProjectImage(TestImage):
# This is the return value for utils.find_resource() # This is the return value for utils.find_resource()
self.images_mock.get.return_value = self._image self.images_mock.get.return_value = self._image
self.project_mock.get.return_value = fakes.FakeResource( self.project_mock.get.return_value = self.project
None, self.domain_mock.get.return_value = self.domain
copy.deepcopy(identity_fakes.PROJECT),
loaded=True,
)
self.domain_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.DOMAIN),
loaded=True,
)
self.image_members_mock.delete.return_value = None self.image_members_mock.delete.return_value = None
# Get the command object to test # Get the command object to test
self.cmd = image.RemoveProjectImage(self.app, None) self.cmd = image.RemoveProjectImage(self.app, None)
@ -779,11 +762,11 @@ class TestRemoveProjectImage(TestImage):
def test_remove_project_image_no_options(self): def test_remove_project_image_no_options(self):
arglist = [ arglist = [
self._image.id, self._image.id,
identity_fakes.project_id, self.project.id,
] ]
verifylist = [ verifylist = [
('image', self._image.id), ('image', self._image.id),
('project', identity_fakes.project_id), ('project', self.project.id),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) 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_members_mock.delete.assert_called_with(
self._image.id, self._image.id,
identity_fakes.project_id, self.project.id,
) )
self.assertIsNone(result) self.assertIsNone(result)
def test_remove_project_image_with_options(self): def test_remove_project_image_with_options(self):
arglist = [ arglist = [
self._image.id, self._image.id,
identity_fakes.project_id, self.project.id,
'--project-domain', identity_fakes.domain_id, '--project-domain', self.domain.id,
] ]
verifylist = [ verifylist = [
('image', self._image.id), ('image', self._image.id),
('project', identity_fakes.project_id), ('project', self.project.id),
('project_domain', identity_fakes.domain_id), ('project_domain', self.domain.id),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) 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_members_mock.delete.assert_called_with(
self._image.id, self._image.id,
identity_fakes.project_id, self.project.id,
) )
self.assertIsNone(result) self.assertIsNone(result)
class TestImageSet(TestImage): class TestImageSet(TestImage):
project = identity_fakes.FakeProject.create_one_project()
domain = identity_fakes.FakeDomain.create_one_domain()
def setUp(self): def setUp(self):
super(TestImageSet, self).setUp() super(TestImageSet, self).setUp()
# Set up the schema # Set up the schema
@ -827,17 +813,9 @@ class TestImageSet(TestImage):
schemas.SchemaBasedModel, schemas.SchemaBasedModel,
) )
self.project_mock.get.return_value = fakes.FakeResource( self.project_mock.get.return_value = self.project
None,
copy.deepcopy(identity_fakes.PROJECT),
loaded=True,
)
self.domain_mock.get.return_value = fakes.FakeResource( self.domain_mock.get.return_value = self.domain
None,
copy.deepcopy(identity_fakes.DOMAIN),
loaded=True,
)
self.images_mock.get.return_value = self.model(**image_fakes.IMAGE) self.images_mock.get.return_value = self.model(**image_fakes.IMAGE)
self.images_mock.update.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', '--min-ram', '4',
'--container-format', 'ovf', '--container-format', 'ovf',
'--disk-format', 'vmdk', '--disk-format', 'vmdk',
'--project', identity_fakes.project_name, '--project', self.project.name,
'--project-domain', identity_fakes.domain_id, '--project-domain', self.domain.id,
image_fakes.image_id, image_fakes.image_id,
] ]
verifylist = [ verifylist = [
@ -874,8 +852,8 @@ class TestImageSet(TestImage):
('min_ram', 4), ('min_ram', 4),
('container_format', 'ovf'), ('container_format', 'ovf'),
('disk_format', 'vmdk'), ('disk_format', 'vmdk'),
('project', identity_fakes.project_name), ('project', self.project.name),
('project_domain', identity_fakes.domain_id), ('project_domain', self.domain.id),
('image', image_fakes.image_id), ('image', image_fakes.image_id),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -884,7 +862,7 @@ class TestImageSet(TestImage):
kwargs = { kwargs = {
'name': 'new-name', 'name': 'new-name',
'owner': identity_fakes.project_id, 'owner': self.project.id,
'min_disk': 2, 'min_disk': 2,
'min_ram': 4, 'min_ram': 4,
'container_format': 'ovf', 'container_format': 'ovf',

View File

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

View File

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

View File

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