Prepare for Identity v3 tests

* Split identity/fakes.py for v2_0 and v3
* Split identity/test_identity.py for v2_0 and v3
* Fix issues in commands with enable/disable
* Clean up v2 commands

Change-Id: I6e536b6a130fc556dbd7dcf9f2e76d939ca1bc1c
This commit is contained in:
Dean Troyer 2013-09-09 14:52:45 -05:00
parent 16edd97007
commit 7a0a7d67ed
12 changed files with 222 additions and 141 deletions

View File

@ -33,7 +33,7 @@ class CreateProject(show.ShowOne):
def get_parser(self, prog_name): def get_parser(self, prog_name):
parser = super(CreateProject, self).get_parser(prog_name) parser = super(CreateProject, self).get_parser(prog_name)
parser.add_argument( parser.add_argument(
'project_name', 'name',
metavar='<project-name>', metavar='<project-name>',
help='New project name', help='New project name',
) )
@ -57,13 +57,14 @@ class CreateProject(show.ShowOne):
def take_action(self, parsed_args): def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args) self.log.debug('take_action(%s)' % parsed_args)
identity_client = self.app.client_manager.identity identity_client = self.app.client_manager.identity
enabled = True enabled = True
if parsed_args.disable: if parsed_args.disable:
enabled = False enabled = False
project = identity_client.tenants.create( project = identity_client.tenants.create(
parsed_args.project_name, parsed_args.name,
description=parsed_args.description, description=parsed_args.description,
enabled=enabled, enabled=enabled,
) )
@ -90,10 +91,12 @@ class DeleteProject(command.Command):
def take_action(self, parsed_args): def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args) self.log.debug('take_action(%s)' % parsed_args)
identity_client = self.app.client_manager.identity identity_client = self.app.client_manager.identity
project = utils.find_resource( project = utils.find_resource(
identity_client.tenants, identity_client.tenants,
parsed_args.project, parsed_args.project,
) )
identity_client.tenants.delete(project.id) identity_client.tenants.delete(project.id)
return return
@ -164,8 +167,14 @@ class SetProject(command.Command):
def take_action(self, parsed_args): def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args) self.log.debug('take_action(%s)' % parsed_args)
identity_client = self.app.client_manager.identity identity_client = self.app.client_manager.identity
if (not parsed_args.name
and not parsed_args.description
and not parsed_args.enable
and not parsed_args.disable):
return
project = utils.find_resource( project = utils.find_resource(
identity_client.tenants, identity_client.tenants,
parsed_args.project, parsed_args.project,
@ -180,7 +189,6 @@ class SetProject(command.Command):
kwargs['enabled'] = True kwargs['enabled'] = True
if parsed_args.disable: if parsed_args.disable:
kwargs['enabled'] = False kwargs['enabled'] = False
if 'id' in kwargs: if 'id' in kwargs:
del kwargs['id'] del kwargs['id']
if 'name' in kwargs: if 'name' in kwargs:
@ -188,8 +196,8 @@ class SetProject(command.Command):
kwargs['tenant_name'] = kwargs['name'] kwargs['tenant_name'] = kwargs['name']
del kwargs['name'] del kwargs['name']
if len(kwargs): identity_client.tenants.update(project.id, **kwargs)
identity_client.tenants.update(project.id, **kwargs) return
class ShowProject(show.ShowOne): class ShowProject(show.ShowOne):

View File

@ -28,7 +28,7 @@ from openstackclient.common import utils
class CreateService(show.ShowOne): class CreateService(show.ShowOne):
"""Create service command""" """Create new service"""
log = logging.getLogger(__name__ + '.CreateService') log = logging.getLogger(__name__ + '.CreateService')
@ -37,21 +37,25 @@ class CreateService(show.ShowOne):
parser.add_argument( parser.add_argument(
'name', 'name',
metavar='<service-name>', metavar='<service-name>',
help='New service name') help='New service name',
)
parser.add_argument( parser.add_argument(
'--type', '--type',
metavar='<service-type>', metavar='<service-type>',
required=True, required=True,
help='New service type') help='New service type (compute, image, identity, volume, etc)',
)
parser.add_argument( parser.add_argument(
'--description', '--description',
metavar='<service-description>', metavar='<service-description>',
help='New service description') help='New service description',
)
return parser return parser
def take_action(self, parsed_args): def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args) self.log.debug('take_action(%s)' % parsed_args)
identity_client = self.app.client_manager.identity identity_client = self.app.client_manager.identity
service = identity_client.services.create( service = identity_client.services.create(
parsed_args.name, parsed_args.name,
parsed_args.type, parsed_args.type,
@ -63,7 +67,7 @@ class CreateService(show.ShowOne):
class DeleteService(command.Command): class DeleteService(command.Command):
"""Delete service command""" """Delete service"""
log = logging.getLogger(__name__ + '.DeleteService') log = logging.getLogger(__name__ + '.DeleteService')
@ -71,19 +75,26 @@ class DeleteService(command.Command):
parser = super(DeleteService, self).get_parser(prog_name) parser = super(DeleteService, self).get_parser(prog_name)
parser.add_argument( parser.add_argument(
'service', 'service',
metavar='<service-id>', metavar='<service>',
help='ID of service to delete') help='Service to delete (name or ID)',
)
return parser return parser
def take_action(self, parsed_args): def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args) self.log.debug('take_action(%s)' % parsed_args)
identity_client = self.app.client_manager.identity identity_client = self.app.client_manager.identity
identity_client.services.delete(parsed_args.service)
service = utils.find_resource(
identity_client.services,
parsed_args.service,
)
identity_client.services.delete(service.id)
return return
class ListService(lister.Lister): class ListService(lister.Lister):
"""List service command""" """List services"""
log = logging.getLogger(__name__ + '.ListService') log = logging.getLogger(__name__ + '.ListService')
@ -98,6 +109,7 @@ class ListService(lister.Lister):
def take_action(self, parsed_args): def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args) self.log.debug('take_action(%s)' % parsed_args)
if parsed_args.long: if parsed_args.long:
columns = ('ID', 'Name', 'Type', 'Description') columns = ('ID', 'Name', 'Type', 'Description')
else: else:
@ -111,7 +123,7 @@ class ListService(lister.Lister):
class ShowService(show.ShowOne): class ShowService(show.ShowOne):
"""Show cloud service information""" """Show service details"""
log = logging.getLogger(__name__ + '.ShowService') log = logging.getLogger(__name__ + '.ShowService')
@ -120,7 +132,7 @@ class ShowService(show.ShowOne):
parser.add_argument( parser.add_argument(
'service', 'service',
metavar='<service>', metavar='<service>',
help='Type, name or ID of service to display', help='Service to display (type, name or ID)',
) )
parser.add_argument( parser.add_argument(
'--catalog', '--catalog',

View File

@ -26,7 +26,7 @@ from openstackclient.common import utils
class CreateUser(show.ShowOne): class CreateUser(show.ShowOne):
"""Create user command""" """Create new user"""
log = logging.getLogger(__name__ + '.CreateUser') log = logging.getLogger(__name__ + '.CreateUser')
@ -35,15 +35,18 @@ class CreateUser(show.ShowOne):
parser.add_argument( parser.add_argument(
'name', 'name',
metavar='<user-name>', metavar='<user-name>',
help='New user name') help='New user name',
)
parser.add_argument( parser.add_argument(
'--password', '--password',
metavar='<user-password>', metavar='<user-password>',
help='New user password') help='New user password',
)
parser.add_argument( parser.add_argument(
'--email', '--email',
metavar='<user-email>', metavar='<user-email>',
help='New user email address') help='New user email address',
)
parser.add_argument( parser.add_argument(
'--project', '--project',
metavar='<project>', metavar='<project>',
@ -65,6 +68,7 @@ class CreateUser(show.ShowOne):
def take_action(self, parsed_args): def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args) self.log.debug('take_action(%s)' % parsed_args)
identity_client = self.app.client_manager.identity identity_client = self.app.client_manager.identity
if parsed_args.project: if parsed_args.project:
project_id = utils.find_resource( project_id = utils.find_resource(
identity_client.tenants, identity_client.tenants,
@ -72,9 +76,11 @@ class CreateUser(show.ShowOne):
).id ).id
else: else:
project_id = None project_id = None
enabled = True enabled = True
if parsed_args.disable: if parsed_args.disable:
enabled = False enabled = False
user = identity_client.users.create( user = identity_client.users.create(
parsed_args.name, parsed_args.name,
parsed_args.password, parsed_args.password,
@ -95,7 +101,7 @@ class CreateUser(show.ShowOne):
class DeleteUser(command.Command): class DeleteUser(command.Command):
"""Delete user command""" """Delete user"""
log = logging.getLogger(__name__ + '.DeleteUser') log = logging.getLogger(__name__ + '.DeleteUser')
@ -104,19 +110,25 @@ class DeleteUser(command.Command):
parser.add_argument( parser.add_argument(
'user', 'user',
metavar='<user>', metavar='<user>',
help='Name or ID of user to delete') help='User to delete (name or ID)',
)
return parser return parser
def take_action(self, parsed_args): def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args) self.log.debug('take_action(%s)' % parsed_args)
identity_client = self.app.client_manager.identity identity_client = self.app.client_manager.identity
user = utils.find_resource(identity_client.users, parsed_args.user)
user = utils.find_resource(
identity_client.users,
parsed_args.user,
)
identity_client.users.delete(user.id) identity_client.users.delete(user.id)
return return
class ListUser(lister.Lister): class ListUser(lister.Lister):
"""List user command""" """List users"""
log = logging.getLogger(__name__ + '.ListUser') log = logging.getLogger(__name__ + '.ListUser')
@ -191,7 +203,7 @@ class ListUser(lister.Lister):
class SetUser(command.Command): class SetUser(command.Command):
"""Set user command""" """Set user properties"""
log = logging.getLogger(__name__ + '.SetUser') log = logging.getLogger(__name__ + '.SetUser')
@ -200,19 +212,23 @@ class SetUser(command.Command):
parser.add_argument( parser.add_argument(
'user', 'user',
metavar='<user>', metavar='<user>',
help='Name or ID of user to change') help='User to change (name or ID)',
)
parser.add_argument( parser.add_argument(
'--name', '--name',
metavar='<new-user-name>', metavar='<new-user-name>',
help='New user name') help='New user name',
)
parser.add_argument( parser.add_argument(
'--password', '--password',
metavar='<user-password>', metavar='<user-password>',
help='New user password') help='New user password',
)
parser.add_argument( parser.add_argument(
'--email', '--email',
metavar='<user-email>', metavar='<user-email>',
help='New user email address') help='New user email address',
)
parser.add_argument( parser.add_argument(
'--project', '--project',
metavar='<project>', metavar='<project>',
@ -233,9 +249,21 @@ class SetUser(command.Command):
def take_action(self, parsed_args): def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args) self.log.debug('take_action(%s)' % parsed_args)
identity_client = self.app.client_manager.identity identity_client = self.app.client_manager.identity
user = utils.find_resource(identity_client.users, parsed_args.user)
if (not parsed_args.name
and not parsed_args.name
and not parsed_args.password
and not parsed_args.email
and not parsed_args.project
and not parsed_args.enable
and not parsed_args.disable):
return
user = utils.find_resource(
identity_client.users,
parsed_args.user,
)
if parsed_args.password: if parsed_args.password:
identity_client.users.update_password( identity_client.users.update_password(
@ -258,17 +286,18 @@ class SetUser(command.Command):
kwargs['name'] = parsed_args.name kwargs['name'] = parsed_args.name
if parsed_args.email: if parsed_args.email:
kwargs['email'] = parsed_args.email kwargs['email'] = parsed_args.email
kwargs['enabled'] = user.enabled
if parsed_args.enable: if parsed_args.enable:
kwargs['enabled'] = True kwargs['enabled'] = True
if parsed_args.disable: if parsed_args.disable:
kwargs['enabled'] = False kwargs['enabled'] = False
if len(kwargs): identity_client.users.update(user.id, **kwargs)
identity_client.users.update(user.id, **kwargs) return
class ShowUser(show.ShowOne): class ShowUser(show.ShowOne):
"""Show user command""" """Show user details"""
log = logging.getLogger(__name__ + '.ShowUser') log = logging.getLogger(__name__ + '.ShowUser')
@ -277,13 +306,19 @@ class ShowUser(show.ShowOne):
parser.add_argument( parser.add_argument(
'user', 'user',
metavar='<user>', metavar='<user>',
help='Name or ID of user to display') help='User to display (name or ID)',
)
return parser return parser
def take_action(self, parsed_args): def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args) self.log.debug('take_action(%s)' % parsed_args)
identity_client = self.app.client_manager.identity identity_client = self.app.client_manager.identity
user = utils.find_resource(identity_client.users, parsed_args.user)
user = utils.find_resource(
identity_client.users,
parsed_args.user,
)
if 'tenantId' in user._info: if 'tenantId' in user._info:
user._info.update( user._info.update(
{'project_id': user._info.pop('tenantId')} {'project_id': user._info.pop('tenantId')}

View File

@ -42,7 +42,11 @@ class FakeApp(object):
class FakeClientManager(object): class FakeClientManager(object):
def __init__(self): def __init__(self):
pass self.compute = None
self.identity = None
self.image = None
self.volume = None
self.auth_ref = None
class FakeResource(object): class FakeResource(object):

View File

@ -1,50 +0,0 @@
# Copyright 2013 OpenStack, LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
from openstackclient.common import clientmanager
from openstackclient.identity import client as identity_client
from openstackclient.tests import utils
AUTH_TOKEN = "foobar"
AUTH_URL = "http://0.0.0.0"
class TestIdentity(utils.TestCommand):
def setUp(self):
super(TestIdentity, self).setUp()
api_version = {"identity": "2.0"}
identity_client.API_VERSIONS = {
"2.0": "openstackclient.tests.identity.fakes.FakeIdentityv2Client"
}
self.app.client_manager = clientmanager.ClientManager(
token=AUTH_TOKEN,
url=AUTH_URL,
auth_url=AUTH_URL,
api_version=api_version,
)
def test_make_client(self):
self.assertEqual(
self.app.client_manager.identity.auth_token,
AUTH_TOKEN,
)
self.assertEqual(
self.app.client_manager.identity.management_url,
AUTH_URL,
)

View File

@ -83,13 +83,3 @@ class FakeIdentityv2Client(object):
self.ec2.resource_class = fakes.FakeResource(None, {}) self.ec2.resource_class = fakes.FakeResource(None, {})
self.auth_token = kwargs['token'] self.auth_token = kwargs['token']
self.management_url = kwargs['endpoint'] self.management_url = kwargs['endpoint']
class FakeIdentityv3Client(object):
def __init__(self, **kwargs):
self.domains = mock.Mock()
self.domains.resource_class = fakes.FakeResource(None, {})
self.projects = mock.Mock()
self.projects.resource_class = fakes.FakeResource(None, {})
self.users = mock.Mock()
self.users.resource_class = fakes.FakeResource(None, {})

View File

@ -0,0 +1,31 @@
# Copyright 2013 Nebula Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
from openstackclient.tests.identity.v2_0 import fakes
from openstackclient.tests import utils
AUTH_TOKEN = "foobar"
AUTH_URL = "http://0.0.0.0"
class TestIdentityv2(utils.TestCommand):
def setUp(self):
super(TestIdentityv2, self).setUp()
self.app.client_manager.identity = fakes.FakeIdentityv2Client(
endpoint=AUTH_URL,
token=AUTH_TOKEN,
)

View File

@ -17,11 +17,11 @@ import copy
from openstackclient.identity.v2_0 import project from openstackclient.identity.v2_0 import project
from openstackclient.tests import fakes from openstackclient.tests import fakes
from openstackclient.tests.identity import fakes as identity_fakes from openstackclient.tests.identity.v2_0 import fakes as identity_fakes
from openstackclient.tests.identity import test_identity from openstackclient.tests.identity.v2_0 import test_identity
class TestProject(test_identity.TestIdentity): class TestProject(test_identity.TestIdentityv2):
def setUp(self): def setUp(self):
super(TestProject, self).setUp() super(TestProject, self).setUp()
@ -50,9 +50,9 @@ class TestProjectCreate(TestProject):
identity_fakes.project_name, identity_fakes.project_name,
] ]
verifylist = [ verifylist = [
('project_name', identity_fakes.project_name),
('enable', False), ('enable', False),
('disable', False), ('disable', False),
('name', identity_fakes.project_name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -85,8 +85,8 @@ class TestProjectCreate(TestProject):
identity_fakes.project_name, identity_fakes.project_name,
] ]
verifylist = [ verifylist = [
('project_name', identity_fakes.project_name),
('description', 'new desc'), ('description', 'new desc'),
('name', identity_fakes.project_name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -119,9 +119,9 @@ class TestProjectCreate(TestProject):
identity_fakes.project_name, identity_fakes.project_name,
] ]
verifylist = [ verifylist = [
('project_name', identity_fakes.project_name),
('enable', True), ('enable', True),
('disable', False), ('disable', False),
('name', identity_fakes.project_name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -154,9 +154,9 @@ class TestProjectCreate(TestProject):
identity_fakes.project_name, identity_fakes.project_name,
] ]
verifylist = [ verifylist = [
('project_name', identity_fakes.project_name),
('enable', False), ('enable', False),
('disable', True), ('disable', True),
('name', identity_fakes.project_name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -284,6 +284,11 @@ class TestProjectSet(TestProject):
copy.deepcopy(identity_fakes.PROJECT), copy.deepcopy(identity_fakes.PROJECT),
loaded=True, loaded=True,
) )
self.projects_mock.update.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.PROJECT),
loaded=True,
)
# Get the command object to test # Get the command object to test
self.cmd = project.SetProject(self.app, None) self.cmd = project.SetProject(self.app, None)
@ -302,17 +307,6 @@ class TestProjectSet(TestProject):
result = self.cmd.run(parsed_args) result = self.cmd.run(parsed_args)
self.assertEqual(result, 0) self.assertEqual(result, 0)
# Set expected values
kwargs = {
'description': identity_fakes.project_description,
'enabled': True,
'tenant_name': identity_fakes.project_name,
}
self.projects_mock.update.assert_called_with(
identity_fakes.project_id,
**kwargs
)
def test_project_set_name(self): def test_project_set_name(self):
arglist = [ arglist = [
'--name', 'qwerty', '--name', 'qwerty',
@ -320,6 +314,9 @@ class TestProjectSet(TestProject):
] ]
verifylist = [ verifylist = [
('name', 'qwerty'), ('name', 'qwerty'),
('enable', False),
('disable', False),
('project', identity_fakes.project_name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -344,6 +341,9 @@ class TestProjectSet(TestProject):
] ]
verifylist = [ verifylist = [
('description', 'new desc'), ('description', 'new desc'),
('enable', False),
('disable', False),
('project', identity_fakes.project_name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -369,6 +369,7 @@ class TestProjectSet(TestProject):
verifylist = [ verifylist = [
('enable', True), ('enable', True),
('disable', False), ('disable', False),
('project', identity_fakes.project_name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -394,6 +395,7 @@ class TestProjectSet(TestProject):
verifylist = [ verifylist = [
('enable', False), ('enable', False),
('disable', True), ('disable', True),
('project', identity_fakes.project_name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)

View File

@ -19,11 +19,11 @@ import mock
from openstackclient.common import exceptions from openstackclient.common import exceptions
from openstackclient.identity.v2_0 import role from openstackclient.identity.v2_0 import role
from openstackclient.tests import fakes from openstackclient.tests import fakes
from openstackclient.tests.identity import fakes as identity_fakes from openstackclient.tests.identity.v2_0 import fakes as identity_fakes
from openstackclient.tests.identity import test_identity from openstackclient.tests.identity.v2_0 import test_identity
class TestRole(test_identity.TestIdentity): class TestRole(test_identity.TestIdentityv2):
def setUp(self): def setUp(self):
super(TestRole, self).setUp() super(TestRole, self).setUp()

View File

@ -17,11 +17,11 @@ import copy
from openstackclient.identity.v2_0 import service from openstackclient.identity.v2_0 import service
from openstackclient.tests import fakes from openstackclient.tests import fakes
from openstackclient.tests.identity import fakes as identity_fakes from openstackclient.tests.identity.v2_0 import fakes as identity_fakes
from openstackclient.tests.identity import test_identity from openstackclient.tests.identity.v2_0 import test_identity
class TestService(test_identity.TestIdentity): class TestService(test_identity.TestIdentityv2):
def setUp(self): def setUp(self):
super(TestService, self).setUp() super(TestService, self).setUp()
@ -45,13 +45,14 @@ class TestServiceCreate(TestService):
# Get the command object to test # Get the command object to test
self.cmd = service.CreateService(self.app, None) self.cmd = service.CreateService(self.app, None)
def test_service_create_minimum_options(self): def test_service_create_name_type(self):
arglist = [ arglist = [
'--type', identity_fakes.service_type, '--type', identity_fakes.service_type,
identity_fakes.service_name, identity_fakes.service_name,
] ]
verifylist = [ verifylist = [
('type', identity_fakes.service_type), ('type', identity_fakes.service_type),
('description', None),
('name', identity_fakes.service_name), ('name', identity_fakes.service_name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -138,7 +139,7 @@ class TestServiceDelete(TestService):
self.cmd.take_action(parsed_args) self.cmd.take_action(parsed_args)
self.services_mock.delete.assert_called_with( self.services_mock.delete.assert_called_with(
identity_fakes.service_name, identity_fakes.service_id,
) )

View File

@ -17,11 +17,11 @@ import copy
from openstackclient.identity.v2_0 import user from openstackclient.identity.v2_0 import user
from openstackclient.tests import fakes from openstackclient.tests import fakes
from openstackclient.tests.identity import fakes as identity_fakes from openstackclient.tests.identity.v2_0 import fakes as identity_fakes
from openstackclient.tests.identity import test_identity from openstackclient.tests.identity.v2_0 import test_identity
class TestUser(test_identity.TestIdentity): class TestUser(test_identity.TestIdentityv2):
def setUp(self): def setUp(self):
super(TestUser, self).setUp() super(TestUser, self).setUp()
@ -29,6 +29,7 @@ class TestUser(test_identity.TestIdentity):
# Get a shortcut to the TenantManager Mock # Get a shortcut to the TenantManager Mock
self.projects_mock = self.app.client_manager.identity.tenants self.projects_mock = self.app.client_manager.identity.tenants
self.projects_mock.reset_mock() self.projects_mock.reset_mock()
# Get a shortcut to the UserManager Mock # Get a shortcut to the UserManager Mock
self.users_mock = self.app.client_manager.identity.users self.users_mock = self.app.client_manager.identity.users
self.users_mock.reset_mock() self.users_mock.reset_mock()
@ -44,6 +45,7 @@ class TestUserCreate(TestUser):
copy.deepcopy(identity_fakes.PROJECT), copy.deepcopy(identity_fakes.PROJECT),
loaded=True, loaded=True,
) )
self.users_mock.create.return_value = fakes.FakeResource( self.users_mock.create.return_value = fakes.FakeResource(
None, None,
copy.deepcopy(identity_fakes.USER), copy.deepcopy(identity_fakes.USER),
@ -58,6 +60,8 @@ class TestUserCreate(TestUser):
identity_fakes.user_name, identity_fakes.user_name,
] ]
verifylist = [ verifylist = [
('enable', False),
('disable', False),
('name', identity_fakes.user_name), ('name', identity_fakes.user_name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -70,7 +74,7 @@ class TestUserCreate(TestUser):
'enabled': True, 'enabled': True,
'tenant_id': None, 'tenant_id': None,
} }
# users.create(name, password, email, tenant_id=None, enabled=True) # UserManager.create(name, password, email, tenant_id=, enabled=)
self.users_mock.create.assert_called_with( self.users_mock.create.assert_called_with(
identity_fakes.user_name, identity_fakes.user_name,
None, None,
@ -108,7 +112,7 @@ class TestUserCreate(TestUser):
'enabled': True, 'enabled': True,
'tenant_id': None, 'tenant_id': None,
} }
# users.create(name, password, email, tenant_id=None, enabled=True) # UserManager.create(name, password, email, tenant_id=, enabled=)
self.users_mock.create.assert_called_with( self.users_mock.create.assert_called_with(
identity_fakes.user_name, identity_fakes.user_name,
'secret', 'secret',
@ -146,7 +150,7 @@ class TestUserCreate(TestUser):
'enabled': True, 'enabled': True,
'tenant_id': None, 'tenant_id': None,
} }
# users.create(name, password, email, tenant_id=None, enabled=True) # UserManager.create(name, password, email, tenant_id=, enabled=)
self.users_mock.create.assert_called_with( self.users_mock.create.assert_called_with(
identity_fakes.user_name, identity_fakes.user_name,
None, None,
@ -199,7 +203,7 @@ class TestUserCreate(TestUser):
'enabled': True, 'enabled': True,
'tenant_id': identity_fakes.PROJECT_2['id'], 'tenant_id': identity_fakes.PROJECT_2['id'],
} }
# users.create(name, password, email, tenant_id=None, enabled=True) # UserManager.create(name, password, email, tenant_id=, enabled=)
self.users_mock.create.assert_called_with( self.users_mock.create.assert_called_with(
identity_fakes.user_name, identity_fakes.user_name,
None, None,
@ -238,7 +242,7 @@ class TestUserCreate(TestUser):
'enabled': True, 'enabled': True,
'tenant_id': None, 'tenant_id': None,
} }
# users.create(name, password, email, tenant_id=None, enabled=True) # UserManager.create(name, password, email, tenant_id=, enabled=)
self.users_mock.create.assert_called_with( self.users_mock.create.assert_called_with(
identity_fakes.user_name, identity_fakes.user_name,
None, None,
@ -277,7 +281,7 @@ class TestUserCreate(TestUser):
'enabled': False, 'enabled': False,
'tenant_id': None, 'tenant_id': None,
} }
# users.create(name, password, email, tenant_id=None, enabled=True) # UserManager.create(name, password, email, tenant_id=, enabled=)
self.users_mock.create.assert_called_with( self.users_mock.create.assert_called_with(
identity_fakes.user_name, identity_fakes.user_name,
None, None,
@ -342,6 +346,7 @@ class TestUserList(TestUser):
loaded=True, loaded=True,
), ),
] ]
self.users_mock.list.return_value = [ self.users_mock.list.return_value = [
fakes.FakeResource( fakes.FakeResource(
None, None,
@ -443,18 +448,18 @@ class TestUserSet(TestUser):
identity_fakes.user_name, identity_fakes.user_name,
] ]
verifylist = [ verifylist = [
('user', identity_fakes.user_name), ('name', None),
('password', None),
('email', None),
('project', None),
('enable', False), ('enable', False),
('disable', False), ('disable', False),
('project', None), ('user', identity_fakes.user_name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
# DisplayCommandBase.take_action() returns two tuples result = self.cmd.run(parsed_args)
self.cmd.take_action(parsed_args) self.assertEqual(result, 0)
# SetUser doesn't call anything if no args are passed
self.assertFalse(self.users_mock.update.called)
def test_user_set_name(self): def test_user_set_name(self):
arglist = [ arglist = [
@ -463,6 +468,12 @@ class TestUserSet(TestUser):
] ]
verifylist = [ verifylist = [
('name', 'qwerty'), ('name', 'qwerty'),
('password', None),
('email', None),
('project', None),
('enable', False),
('disable', False),
('user', identity_fakes.user_name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -471,8 +482,10 @@ class TestUserSet(TestUser):
# Set expected values # Set expected values
kwargs = { kwargs = {
'enabled': True,
'name': 'qwerty', 'name': 'qwerty',
} }
# UserManager.update(user, **kwargs)
self.users_mock.update.assert_called_with( self.users_mock.update.assert_called_with(
identity_fakes.user_id, identity_fakes.user_id,
**kwargs **kwargs
@ -484,13 +497,20 @@ class TestUserSet(TestUser):
identity_fakes.user_name, identity_fakes.user_name,
] ]
verifylist = [ verifylist = [
('name', None),
('password', 'secret'), ('password', 'secret'),
('email', None),
('project', None),
('enable', False),
('disable', False),
('user', identity_fakes.user_name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
# DisplayCommandBase.take_action() returns two tuples # DisplayCommandBase.take_action() returns two tuples
self.cmd.take_action(parsed_args) self.cmd.take_action(parsed_args)
# UserManager.update_password(user, password)
self.users_mock.update_password.assert_called_with( self.users_mock.update_password.assert_called_with(
identity_fakes.user_id, identity_fakes.user_id,
'secret', 'secret',
@ -502,7 +522,13 @@ class TestUserSet(TestUser):
identity_fakes.user_name, identity_fakes.user_name,
] ]
verifylist = [ verifylist = [
('name', None),
('password', None),
('email', 'barney@example.com'), ('email', 'barney@example.com'),
('project', None),
('enable', False),
('disable', False),
('user', identity_fakes.user_name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -512,7 +538,9 @@ class TestUserSet(TestUser):
# Set expected values # Set expected values
kwargs = { kwargs = {
'email': 'barney@example.com', 'email': 'barney@example.com',
'enabled': True,
} }
# UserManager.update(user, **kwargs)
self.users_mock.update.assert_called_with( self.users_mock.update.assert_called_with(
identity_fakes.user_id, identity_fakes.user_id,
**kwargs **kwargs
@ -524,13 +552,20 @@ class TestUserSet(TestUser):
identity_fakes.user_name, identity_fakes.user_name,
] ]
verifylist = [ verifylist = [
('name', None),
('password', None),
('email', None),
('project', identity_fakes.project_id), ('project', identity_fakes.project_id),
('enable', False),
('disable', False),
('user', identity_fakes.user_name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
# DisplayCommandBase.take_action() returns two tuples # DisplayCommandBase.take_action() returns two tuples
self.cmd.take_action(parsed_args) self.cmd.take_action(parsed_args)
# UserManager.update_tenant(user, tenant)
self.users_mock.update_tenant.assert_called_with( self.users_mock.update_tenant.assert_called_with(
identity_fakes.user_id, identity_fakes.user_id,
identity_fakes.project_id, identity_fakes.project_id,
@ -542,8 +577,13 @@ class TestUserSet(TestUser):
identity_fakes.user_name, identity_fakes.user_name,
] ]
verifylist = [ verifylist = [
('name', None),
('password', None),
('email', None),
('project', None),
('enable', True), ('enable', True),
('disable', False), ('disable', False),
('user', identity_fakes.user_name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -554,6 +594,7 @@ class TestUserSet(TestUser):
kwargs = { kwargs = {
'enabled': True, 'enabled': True,
} }
# UserManager.update(user, **kwargs)
self.users_mock.update.assert_called_with( self.users_mock.update.assert_called_with(
identity_fakes.user_id, identity_fakes.user_id,
**kwargs **kwargs
@ -565,8 +606,13 @@ class TestUserSet(TestUser):
identity_fakes.user_name, identity_fakes.user_name,
] ]
verifylist = [ verifylist = [
('name', None),
('password', None),
('email', None),
('project', None),
('enable', False), ('enable', False),
('disable', True), ('disable', True),
('user', identity_fakes.user_name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -577,6 +623,7 @@ class TestUserSet(TestUser):
kwargs = { kwargs = {
'enabled': False, 'enabled': False,
} }
# UserManager.update(user, **kwargs)
self.users_mock.update.assert_called_with( self.users_mock.update.assert_called_with(
identity_fakes.user_id, identity_fakes.user_id,
**kwargs **kwargs

View File

@ -70,6 +70,7 @@ class TestCommand(TestCase):
# Build up a fake app # Build up a fake app
self.fake_stdout = fakes.FakeStdout() self.fake_stdout = fakes.FakeStdout()
self.app = fakes.FakeApp(self.fake_stdout) self.app = fakes.FakeApp(self.fake_stdout)
self.app.client_manager = fakes.FakeClientManager()
def check_parser(self, cmd, args, verify_args): def check_parser(self, cmd, args, verify_args):
cmd_parser = cmd.get_parser('check_parser') cmd_parser = cmd.get_parser('check_parser')