Merge "Update Fakes.py and unit tests for commands in identity V2.0"
This commit is contained in:
commit
9e47688e5e
@ -76,19 +76,19 @@ USER = {
|
||||
}
|
||||
|
||||
token_expires = '2014-01-01T00:00:00Z'
|
||||
token_id = 'tttttttt-tttt-tttt-tttt-tttttttttttt'
|
||||
token_id = 'token-id-' + uuid.uuid4().hex
|
||||
|
||||
TOKEN = {
|
||||
'expires': token_expires,
|
||||
'id': token_id,
|
||||
'tenant_id': project_id,
|
||||
'user_id': user_id,
|
||||
'tenant_id': 'project-id',
|
||||
'user_id': 'user-id',
|
||||
}
|
||||
|
||||
UNSCOPED_TOKEN = {
|
||||
'expires': token_expires,
|
||||
'id': token_id,
|
||||
'user_id': user_id,
|
||||
'user_id': 'user-id',
|
||||
}
|
||||
|
||||
endpoint_name = service_name
|
||||
@ -110,8 +110,6 @@ ENDPOINT = {
|
||||
'publicurl': endpoint_publicurl,
|
||||
'service_id': endpoint_service_id,
|
||||
}
|
||||
SERVICE_NAME = 'service-name-' + uuid.uuid4().hex
|
||||
SERVICE_ID = 'service-id-' + uuid.uuid4().hex
|
||||
|
||||
|
||||
def fake_auth_ref(fake_token, fake_service=None):
|
||||
@ -244,7 +242,7 @@ class FakeCatalog(object):
|
||||
|
||||
# Set default attributes.
|
||||
catalog_info = {
|
||||
'id': SERVICE_ID,
|
||||
'id': 'service-id-' + uuid.uuid4().hex,
|
||||
'type': 'compute',
|
||||
'name': 'supernova',
|
||||
'endpoints': [
|
||||
@ -295,8 +293,8 @@ class FakeProject(object):
|
||||
|
||||
# set default attributes.
|
||||
project_info = {
|
||||
'id': 'project-id' + uuid.uuid4().hex,
|
||||
'name': 'project-name' + uuid.uuid4().hex,
|
||||
'id': 'project-id-' + uuid.uuid4().hex,
|
||||
'name': 'project-name-' + uuid.uuid4().hex,
|
||||
'description': 'project_description',
|
||||
'enabled': True,
|
||||
}
|
||||
@ -341,14 +339,14 @@ class FakeEndpoint(object):
|
||||
|
||||
# set default attributes.
|
||||
endpoint_info = {
|
||||
'service_name': SERVICE_NAME,
|
||||
'service_name': 'service-name-' + uuid.uuid4().hex,
|
||||
'adminurl': 'http://endpoint_adminurl',
|
||||
'region': 'endpoint_region',
|
||||
'internalurl': 'http://endpoint_internalurl',
|
||||
'service_type': 'service_type',
|
||||
'id': 'endpoint-id-' + uuid.uuid4().hex,
|
||||
'publicurl': 'http://endpoint_publicurl',
|
||||
'service_id': SERVICE_ID,
|
||||
'service_id': 'service-name-' + uuid.uuid4().hex,
|
||||
|
||||
}
|
||||
endpoint_info.update(attrs)
|
||||
@ -392,8 +390,8 @@ class FakeService(object):
|
||||
|
||||
# set default attributes.
|
||||
service_info = {
|
||||
'id': SERVICE_ID,
|
||||
'name': SERVICE_NAME,
|
||||
'id': 'service-id-' + uuid.uuid4().hex,
|
||||
'name': 'service-name-' + uuid.uuid4().hex,
|
||||
'description': 'service_description',
|
||||
'type': 'service_type',
|
||||
|
||||
@ -464,3 +462,49 @@ class FakeRole(object):
|
||||
roles.append(FakeRole.create_one_role(attrs))
|
||||
|
||||
return roles
|
||||
|
||||
|
||||
class FakeUser(object):
|
||||
"""Fake one or more user."""
|
||||
|
||||
@staticmethod
|
||||
def create_one_user(attrs=None):
|
||||
"""Create a fake user.
|
||||
|
||||
:param Dictionary attrs:
|
||||
A dictionary with all attributes
|
||||
:return:
|
||||
A FakeResource object, with id, name, and so on
|
||||
"""
|
||||
attrs = attrs or {}
|
||||
|
||||
# set default attributes.
|
||||
user_info = {
|
||||
'id': 'user-id-' + uuid.uuid4().hex,
|
||||
'name': 'user-name-' + uuid.uuid4().hex,
|
||||
'tenantId': 'project-id-' + uuid.uuid4().hex,
|
||||
'email': 'admin@openstack.org',
|
||||
'enabled': True,
|
||||
}
|
||||
user_info.update(attrs)
|
||||
|
||||
user = fakes.FakeResource(info=copy.deepcopy(user_info),
|
||||
loaded=True)
|
||||
return user
|
||||
|
||||
@staticmethod
|
||||
def create_users(attrs=None, count=2):
|
||||
"""Create multiple fake users.
|
||||
|
||||
:param Dictionary attrs:
|
||||
A dictionary with all attributes
|
||||
:param int count:
|
||||
The number of users to fake
|
||||
:return:
|
||||
A list of FakeResource objects faking the users
|
||||
"""
|
||||
users = []
|
||||
for i in range(0, count):
|
||||
users.append(FakeUser.create_one_user(attrs))
|
||||
|
||||
return users
|
||||
|
@ -17,8 +17,12 @@ from openstackclient.tests.identity.v2_0 import fakes as identity_fakes
|
||||
|
||||
class TestEndpoint(identity_fakes.TestIdentityv2):
|
||||
|
||||
fake_endpoint = identity_fakes.FakeEndpoint.create_one_endpoint()
|
||||
fake_service = identity_fakes.FakeService.create_one_service()
|
||||
attr = {
|
||||
'service_name': fake_service.name,
|
||||
'service_id': fake_service.id,
|
||||
}
|
||||
fake_endpoint = identity_fakes.FakeEndpoint.create_one_endpoint(attr)
|
||||
|
||||
def setUp(self):
|
||||
super(TestEndpoint, self).setUp()
|
||||
|
@ -13,14 +13,12 @@
|
||||
# under the License.
|
||||
#
|
||||
|
||||
import copy
|
||||
import mock
|
||||
|
||||
from keystoneauth1 import exceptions as ks_exc
|
||||
from osc_lib import exceptions
|
||||
|
||||
from openstackclient.identity.v2_0 import role
|
||||
from openstackclient.tests import fakes
|
||||
from openstackclient.tests.identity.v2_0 import fakes as identity_fakes
|
||||
|
||||
|
||||
@ -34,6 +32,12 @@ class TestRole(identity_fakes.TestIdentityv2):
|
||||
]
|
||||
fake_service = identity_fakes.FakeService.create_one_service(attr)
|
||||
fake_role = identity_fakes.FakeRole.create_one_role()
|
||||
fake_project = identity_fakes.FakeProject.create_one_project()
|
||||
attr = {}
|
||||
attr = {
|
||||
'tenantId': fake_project.id,
|
||||
}
|
||||
fake_user = identity_fakes.FakeUser.create_one_user(attr)
|
||||
|
||||
def setUp(self):
|
||||
super(TestRole, self).setUp()
|
||||
@ -63,42 +67,26 @@ class TestRoleAdd(TestRole):
|
||||
def setUp(self):
|
||||
super(TestRoleAdd, self).setUp()
|
||||
|
||||
self.projects_mock.get.return_value = fakes.FakeResource(
|
||||
None,
|
||||
copy.deepcopy(identity_fakes.PROJECT),
|
||||
loaded=True,
|
||||
)
|
||||
self.projects_mock.get.return_value = self.fake_project
|
||||
|
||||
self.users_mock.get.return_value = fakes.FakeResource(
|
||||
None,
|
||||
copy.deepcopy(identity_fakes.USER),
|
||||
loaded=True,
|
||||
)
|
||||
self.users_mock.get.return_value = self.fake_user
|
||||
|
||||
self.roles_mock.get.return_value = fakes.FakeResource(
|
||||
None,
|
||||
copy.deepcopy(identity_fakes.ROLE),
|
||||
loaded=True,
|
||||
)
|
||||
self.roles_mock.add_user_role.return_value = fakes.FakeResource(
|
||||
None,
|
||||
copy.deepcopy(identity_fakes.ROLE),
|
||||
loaded=True,
|
||||
)
|
||||
self.roles_mock.get.return_value = self.fake_role
|
||||
self.roles_mock.add_user_role.return_value = self.fake_role
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd = role.AddRole(self.app, None)
|
||||
|
||||
def test_role_add(self):
|
||||
arglist = [
|
||||
'--project', identity_fakes.project_name,
|
||||
'--user', identity_fakes.user_name,
|
||||
identity_fakes.role_name,
|
||||
'--project', self.fake_project.name,
|
||||
'--user', self.fake_user.name,
|
||||
self.fake_role.name,
|
||||
]
|
||||
verifylist = [
|
||||
('project', identity_fakes.project_name),
|
||||
('user', identity_fakes.user_name),
|
||||
('role', identity_fakes.role_name),
|
||||
('project', self.fake_project.name),
|
||||
('user', self.fake_user.name),
|
||||
('role', self.fake_role.name),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
@ -109,49 +97,46 @@ class TestRoleAdd(TestRole):
|
||||
|
||||
# RoleManager.add_user_role(user, role, tenant=None)
|
||||
self.roles_mock.add_user_role.assert_called_with(
|
||||
identity_fakes.user_id,
|
||||
identity_fakes.role_id,
|
||||
identity_fakes.project_id,
|
||||
self.fake_user.id,
|
||||
self.fake_role.id,
|
||||
self.fake_project.id,
|
||||
)
|
||||
|
||||
collist = ('id', 'name')
|
||||
self.assertEqual(collist, columns)
|
||||
datalist = (
|
||||
identity_fakes.role_id,
|
||||
identity_fakes.role_name,
|
||||
self.fake_role.id,
|
||||
self.fake_role.name,
|
||||
)
|
||||
self.assertEqual(datalist, data)
|
||||
|
||||
|
||||
class TestRoleCreate(TestRole):
|
||||
|
||||
fake_role_c = identity_fakes.FakeRole.create_one_role()
|
||||
columns = (
|
||||
'id',
|
||||
'name'
|
||||
)
|
||||
datalist = (
|
||||
identity_fakes.role_id,
|
||||
identity_fakes.role_name,
|
||||
fake_role_c.id,
|
||||
fake_role_c.name,
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
super(TestRoleCreate, self).setUp()
|
||||
|
||||
self.roles_mock.create.return_value = fakes.FakeResource(
|
||||
None,
|
||||
copy.deepcopy(identity_fakes.ROLE),
|
||||
loaded=True,
|
||||
)
|
||||
self.roles_mock.create.return_value = self.fake_role_c
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd = role.CreateRole(self.app, None)
|
||||
|
||||
def test_role_create_no_options(self):
|
||||
arglist = [
|
||||
identity_fakes.role_name,
|
||||
self.fake_role_c.name,
|
||||
]
|
||||
verifylist = [
|
||||
('role_name', identity_fakes.role_name),
|
||||
('role_name', self.fake_role_c.name),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
@ -162,7 +147,7 @@ class TestRoleCreate(TestRole):
|
||||
|
||||
# RoleManager.create(name)
|
||||
self.roles_mock.create.assert_called_with(
|
||||
identity_fakes.role_name,
|
||||
self.fake_role_c.name,
|
||||
)
|
||||
|
||||
self.assertEqual(self.columns, columns)
|
||||
@ -175,18 +160,14 @@ class TestRoleCreate(TestRole):
|
||||
# need to make this throw an exception...
|
||||
self.roles_mock.create.side_effect = _raise_conflict
|
||||
|
||||
self.roles_mock.get.return_value = fakes.FakeResource(
|
||||
None,
|
||||
copy.deepcopy(identity_fakes.ROLE),
|
||||
loaded=True,
|
||||
)
|
||||
self.roles_mock.get.return_value = self.fake_role_c
|
||||
|
||||
arglist = [
|
||||
'--or-show',
|
||||
identity_fakes.role_name,
|
||||
self.fake_role_c.name,
|
||||
]
|
||||
verifylist = [
|
||||
('role_name', identity_fakes.role_name),
|
||||
('role_name', self.fake_role_c.name),
|
||||
('or_show', True),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
@ -197,11 +178,11 @@ class TestRoleCreate(TestRole):
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
# RoleManager.get(name, description, enabled)
|
||||
self.roles_mock.get.assert_called_with(identity_fakes.role_name)
|
||||
self.roles_mock.get.assert_called_with(self.fake_role_c.name)
|
||||
|
||||
# RoleManager.create(name)
|
||||
self.roles_mock.create.assert_called_with(
|
||||
identity_fakes.role_name,
|
||||
self.fake_role_c.name,
|
||||
)
|
||||
|
||||
self.assertEqual(self.columns, columns)
|
||||
@ -210,10 +191,10 @@ class TestRoleCreate(TestRole):
|
||||
def test_role_create_or_show_not_exists(self):
|
||||
arglist = [
|
||||
'--or-show',
|
||||
identity_fakes.role_name,
|
||||
self.fake_role_c.name,
|
||||
]
|
||||
verifylist = [
|
||||
('role_name', identity_fakes.role_name),
|
||||
('role_name', self.fake_role_c.name),
|
||||
('or_show', True),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
@ -225,7 +206,7 @@ class TestRoleCreate(TestRole):
|
||||
|
||||
# RoleManager.create(name)
|
||||
self.roles_mock.create.assert_called_with(
|
||||
identity_fakes.role_name,
|
||||
self.fake_role_c.name,
|
||||
)
|
||||
|
||||
self.assertEqual(self.columns, columns)
|
||||
@ -237,11 +218,7 @@ class TestRoleDelete(TestRole):
|
||||
def setUp(self):
|
||||
super(TestRoleDelete, self).setUp()
|
||||
|
||||
self.roles_mock.get.return_value = fakes.FakeResource(
|
||||
None,
|
||||
copy.deepcopy(identity_fakes.ROLE),
|
||||
loaded=True,
|
||||
)
|
||||
self.roles_mock.get.return_value = self.fake_role
|
||||
self.roles_mock.delete.return_value = None
|
||||
|
||||
# Get the command object to test
|
||||
@ -249,17 +226,17 @@ class TestRoleDelete(TestRole):
|
||||
|
||||
def test_role_delete_no_options(self):
|
||||
arglist = [
|
||||
identity_fakes.role_name,
|
||||
self.fake_role.name,
|
||||
]
|
||||
verifylist = [
|
||||
('roles', [identity_fakes.role_name]),
|
||||
('roles', [self.fake_role.name]),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.roles_mock.delete.assert_called_with(
|
||||
identity_fakes.role_id,
|
||||
self.fake_role.id,
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
@ -269,13 +246,7 @@ class TestRoleList(TestRole):
|
||||
def setUp(self):
|
||||
super(TestRoleList, self).setUp()
|
||||
|
||||
self.roles_mock.list.return_value = [
|
||||
fakes.FakeResource(
|
||||
None,
|
||||
copy.deepcopy(identity_fakes.ROLE),
|
||||
loaded=True,
|
||||
),
|
||||
]
|
||||
self.roles_mock.list.return_value = [self.fake_role]
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd = role.ListRole(self.app, None)
|
||||
@ -295,8 +266,8 @@ class TestRoleList(TestRole):
|
||||
collist = ('ID', 'Name')
|
||||
self.assertEqual(collist, columns)
|
||||
datalist = ((
|
||||
identity_fakes.role_id,
|
||||
identity_fakes.role_name,
|
||||
self.fake_role.id,
|
||||
self.fake_role.name,
|
||||
), )
|
||||
self.assertEqual(datalist, tuple(data))
|
||||
|
||||
@ -313,25 +284,11 @@ class TestUserRoleList(TestRole):
|
||||
def setUp(self):
|
||||
super(TestUserRoleList, self).setUp()
|
||||
|
||||
self.projects_mock.get.return_value = fakes.FakeResource(
|
||||
None,
|
||||
copy.deepcopy(identity_fakes.PROJECT),
|
||||
loaded=True,
|
||||
)
|
||||
self.projects_mock.get.return_value = self.fake_project
|
||||
|
||||
self.users_mock.get.return_value = fakes.FakeResource(
|
||||
None,
|
||||
copy.deepcopy(identity_fakes.USER),
|
||||
loaded=True,
|
||||
)
|
||||
self.users_mock.get.return_value = self.fake_user
|
||||
|
||||
self.roles_mock.roles_for_user.return_value = [
|
||||
fakes.FakeResource(
|
||||
None,
|
||||
copy.deepcopy(identity_fakes.ROLE),
|
||||
loaded=True,
|
||||
),
|
||||
]
|
||||
self.roles_mock.roles_for_user.return_value = [self.fake_role]
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd = role.ListUserRole(self.app, None)
|
||||
@ -366,17 +323,17 @@ class TestUserRoleList(TestRole):
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.roles_mock.roles_for_user.assert_called_with(
|
||||
identity_fakes.user_id,
|
||||
identity_fakes.project_id,
|
||||
self.fake_user.id,
|
||||
self.fake_project.id,
|
||||
)
|
||||
|
||||
collist = ('ID', 'Name', 'Project', 'User')
|
||||
self.assertEqual(collist, columns)
|
||||
datalist = ((
|
||||
identity_fakes.role_id,
|
||||
identity_fakes.role_name,
|
||||
identity_fakes.project_name,
|
||||
identity_fakes.user_name,
|
||||
self.fake_role.id,
|
||||
self.fake_role.name,
|
||||
self.fake_project.name,
|
||||
self.fake_user.name,
|
||||
), )
|
||||
self.assertEqual(datalist, tuple(data))
|
||||
|
||||
@ -388,16 +345,12 @@ class TestUserRoleList(TestRole):
|
||||
self.ar_mock = mock.PropertyMock(return_value=auth_ref)
|
||||
type(self.app.client_manager).auth_ref = self.ar_mock
|
||||
|
||||
self.projects_mock.get.return_value = fakes.FakeResource(
|
||||
None,
|
||||
copy.deepcopy(identity_fakes.PROJECT_2),
|
||||
loaded=True,
|
||||
)
|
||||
self.projects_mock.get.return_value = self.fake_project
|
||||
arglist = [
|
||||
'--project', identity_fakes.PROJECT_2['name'],
|
||||
'--project', self.fake_project.name,
|
||||
]
|
||||
verifylist = [
|
||||
('project', identity_fakes.PROJECT_2['name']),
|
||||
('project', self.fake_project.name),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
@ -407,30 +360,26 @@ class TestUserRoleList(TestRole):
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.roles_mock.roles_for_user.assert_called_with(
|
||||
identity_fakes.user_id,
|
||||
identity_fakes.PROJECT_2['id'],
|
||||
self.fake_user.id,
|
||||
self.fake_project.id,
|
||||
)
|
||||
|
||||
self.assertEqual(columns, columns)
|
||||
datalist = ((
|
||||
identity_fakes.role_id,
|
||||
identity_fakes.role_name,
|
||||
identity_fakes.PROJECT_2['name'],
|
||||
identity_fakes.user_name,
|
||||
self.fake_role.id,
|
||||
self.fake_role.name,
|
||||
self.fake_project.name,
|
||||
self.fake_user.name,
|
||||
), )
|
||||
self.assertEqual(datalist, tuple(data))
|
||||
|
||||
def test_user_role_list_project_scoped_token(self):
|
||||
self.projects_mock.get.return_value = fakes.FakeResource(
|
||||
None,
|
||||
copy.deepcopy(identity_fakes.PROJECT_2),
|
||||
loaded=True,
|
||||
)
|
||||
self.projects_mock.get.return_value = self.fake_project
|
||||
arglist = [
|
||||
'--project', identity_fakes.PROJECT_2['name'],
|
||||
'--project', self.fake_project.name,
|
||||
]
|
||||
verifylist = [
|
||||
('project', identity_fakes.PROJECT_2['name']),
|
||||
('project', self.fake_project.name),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
@ -440,16 +389,16 @@ class TestUserRoleList(TestRole):
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.roles_mock.roles_for_user.assert_called_with(
|
||||
identity_fakes.user_id,
|
||||
identity_fakes.PROJECT_2['id'],
|
||||
self.fake_user.id,
|
||||
self.fake_project.id,
|
||||
)
|
||||
|
||||
self.assertEqual(columns, columns)
|
||||
datalist = ((
|
||||
identity_fakes.role_id,
|
||||
identity_fakes.role_name,
|
||||
identity_fakes.PROJECT_2['name'],
|
||||
identity_fakes.user_name,
|
||||
self.fake_role.id,
|
||||
self.fake_role.name,
|
||||
self.fake_project.name,
|
||||
self.fake_user.name,
|
||||
), )
|
||||
self.assertEqual(datalist, tuple(data))
|
||||
|
||||
@ -459,23 +408,11 @@ class TestRoleRemove(TestRole):
|
||||
def setUp(self):
|
||||
super(TestRoleRemove, self).setUp()
|
||||
|
||||
self.projects_mock.get.return_value = fakes.FakeResource(
|
||||
None,
|
||||
copy.deepcopy(identity_fakes.PROJECT),
|
||||
loaded=True,
|
||||
)
|
||||
self.projects_mock.get.return_value = self.fake_project
|
||||
|
||||
self.users_mock.get.return_value = fakes.FakeResource(
|
||||
None,
|
||||
copy.deepcopy(identity_fakes.USER),
|
||||
loaded=True,
|
||||
)
|
||||
self.users_mock.get.return_value = self.fake_user
|
||||
|
||||
self.roles_mock.get.return_value = fakes.FakeResource(
|
||||
None,
|
||||
copy.deepcopy(identity_fakes.ROLE),
|
||||
loaded=True,
|
||||
)
|
||||
self.roles_mock.get.return_value = self.fake_role
|
||||
self.roles_mock.remove_user_role.return_value = None
|
||||
|
||||
# Get the command object to test
|
||||
@ -483,14 +420,14 @@ class TestRoleRemove(TestRole):
|
||||
|
||||
def test_role_remove(self):
|
||||
arglist = [
|
||||
'--project', identity_fakes.project_name,
|
||||
'--user', identity_fakes.user_name,
|
||||
identity_fakes.role_name,
|
||||
'--project', self.fake_project.name,
|
||||
'--user', self.fake_user.name,
|
||||
self.fake_role.name,
|
||||
]
|
||||
verifylist = [
|
||||
('role', identity_fakes.role_name),
|
||||
('project', identity_fakes.project_name),
|
||||
('user', identity_fakes.user_name),
|
||||
('role', self.fake_role.name),
|
||||
('project', self.fake_project.name),
|
||||
('user', self.fake_user.name),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
@ -498,9 +435,9 @@ class TestRoleRemove(TestRole):
|
||||
|
||||
# RoleManager.remove_user_role(user, role, tenant=None)
|
||||
self.roles_mock.remove_user_role.assert_called_with(
|
||||
identity_fakes.user_id,
|
||||
identity_fakes.role_id,
|
||||
identity_fakes.project_id,
|
||||
self.fake_user.id,
|
||||
self.fake_role.id,
|
||||
self.fake_project.id,
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
|
@ -13,14 +13,12 @@
|
||||
# under the License.
|
||||
#
|
||||
|
||||
import copy
|
||||
|
||||
from openstackclient.identity.v2_0 import service
|
||||
from openstackclient.tests import fakes
|
||||
from openstackclient.tests.identity.v2_0 import fakes as identity_fakes
|
||||
|
||||
|
||||
class TestService(identity_fakes.TestIdentityv2):
|
||||
fake_service = identity_fakes.FakeService.create_one_service()
|
||||
|
||||
def setUp(self):
|
||||
super(TestService, self).setUp()
|
||||
@ -32,6 +30,7 @@ class TestService(identity_fakes.TestIdentityv2):
|
||||
|
||||
class TestServiceCreate(TestService):
|
||||
|
||||
fake_service_c = identity_fakes.FakeService.create_one_service()
|
||||
columns = (
|
||||
'description',
|
||||
'id',
|
||||
@ -39,30 +38,26 @@ class TestServiceCreate(TestService):
|
||||
'type',
|
||||
)
|
||||
datalist = (
|
||||
identity_fakes.service_description,
|
||||
identity_fakes.service_id,
|
||||
identity_fakes.service_name,
|
||||
identity_fakes.service_type,
|
||||
fake_service_c.description,
|
||||
fake_service_c.id,
|
||||
fake_service_c.name,
|
||||
fake_service_c.type,
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
super(TestServiceCreate, self).setUp()
|
||||
|
||||
self.services_mock.create.return_value = fakes.FakeResource(
|
||||
None,
|
||||
copy.deepcopy(identity_fakes.SERVICE),
|
||||
loaded=True,
|
||||
)
|
||||
self.services_mock.create.return_value = self.fake_service_c
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd = service.CreateService(self.app, None)
|
||||
|
||||
def test_service_create_with_type_positional(self):
|
||||
arglist = [
|
||||
identity_fakes.service_type,
|
||||
self.fake_service_c.type,
|
||||
]
|
||||
verifylist = [
|
||||
('type_or_name', identity_fakes.service_type),
|
||||
('type_or_name', self.fake_service_c.type),
|
||||
('type', None),
|
||||
('description', None),
|
||||
('name', None),
|
||||
@ -77,7 +72,7 @@ class TestServiceCreate(TestService):
|
||||
# ServiceManager.create(name, service_type, description)
|
||||
self.services_mock.create.assert_called_with(
|
||||
None,
|
||||
identity_fakes.service_type,
|
||||
self.fake_service_c.type,
|
||||
None,
|
||||
)
|
||||
|
||||
@ -86,12 +81,12 @@ class TestServiceCreate(TestService):
|
||||
|
||||
def test_service_create_with_type_option(self):
|
||||
arglist = [
|
||||
'--type', identity_fakes.service_type,
|
||||
identity_fakes.service_name,
|
||||
'--type', self.fake_service_c.type,
|
||||
self.fake_service_c.name,
|
||||
]
|
||||
verifylist = [
|
||||
('type_or_name', identity_fakes.service_name),
|
||||
('type', identity_fakes.service_type),
|
||||
('type_or_name', self.fake_service_c.name),
|
||||
('type', self.fake_service_c.type),
|
||||
('description', None),
|
||||
('name', None),
|
||||
]
|
||||
@ -104,8 +99,8 @@ class TestServiceCreate(TestService):
|
||||
|
||||
# ServiceManager.create(name, service_type, description)
|
||||
self.services_mock.create.assert_called_with(
|
||||
identity_fakes.service_name,
|
||||
identity_fakes.service_type,
|
||||
self.fake_service_c.name,
|
||||
self.fake_service_c.type,
|
||||
None,
|
||||
)
|
||||
|
||||
@ -114,14 +109,14 @@ class TestServiceCreate(TestService):
|
||||
|
||||
def test_service_create_with_name_option(self):
|
||||
arglist = [
|
||||
'--name', identity_fakes.service_name,
|
||||
identity_fakes.service_type,
|
||||
'--name', self.fake_service_c.name,
|
||||
self.fake_service_c.type,
|
||||
]
|
||||
verifylist = [
|
||||
('type_or_name', identity_fakes.service_type),
|
||||
('type_or_name', self.fake_service_c.type),
|
||||
('type', None),
|
||||
('description', None),
|
||||
('name', identity_fakes.service_name),
|
||||
('name', self.fake_service_c.name),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
@ -132,8 +127,8 @@ class TestServiceCreate(TestService):
|
||||
|
||||
# ServiceManager.create(name, service_type, description)
|
||||
self.services_mock.create.assert_called_with(
|
||||
identity_fakes.service_name,
|
||||
identity_fakes.service_type,
|
||||
self.fake_service_c.name,
|
||||
self.fake_service_c.type,
|
||||
None,
|
||||
)
|
||||
|
||||
@ -142,15 +137,15 @@ class TestServiceCreate(TestService):
|
||||
|
||||
def test_service_create_description(self):
|
||||
arglist = [
|
||||
'--name', identity_fakes.service_name,
|
||||
'--description', identity_fakes.service_description,
|
||||
identity_fakes.service_type,
|
||||
'--name', self.fake_service_c.name,
|
||||
'--description', self.fake_service_c.description,
|
||||
self.fake_service_c.type,
|
||||
]
|
||||
verifylist = [
|
||||
('type_or_name', identity_fakes.service_type),
|
||||
('type_or_name', self.fake_service_c.type),
|
||||
('type', None),
|
||||
('description', identity_fakes.service_description),
|
||||
('name', identity_fakes.service_name),
|
||||
('description', self.fake_service_c.description),
|
||||
('name', self.fake_service_c.name),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
@ -161,9 +156,9 @@ class TestServiceCreate(TestService):
|
||||
|
||||
# ServiceManager.create(name, service_type, description)
|
||||
self.services_mock.create.assert_called_with(
|
||||
identity_fakes.service_name,
|
||||
identity_fakes.service_type,
|
||||
identity_fakes.service_description,
|
||||
self.fake_service_c.name,
|
||||
self.fake_service_c.type,
|
||||
self.fake_service_c.description,
|
||||
)
|
||||
|
||||
self.assertEqual(self.columns, columns)
|
||||
@ -175,11 +170,7 @@ class TestServiceDelete(TestService):
|
||||
def setUp(self):
|
||||
super(TestServiceDelete, self).setUp()
|
||||
|
||||
self.services_mock.get.return_value = fakes.FakeResource(
|
||||
None,
|
||||
copy.deepcopy(identity_fakes.SERVICE),
|
||||
loaded=True,
|
||||
)
|
||||
self.services_mock.get.return_value = self.fake_service
|
||||
self.services_mock.delete.return_value = None
|
||||
|
||||
# Get the command object to test
|
||||
@ -187,17 +178,17 @@ class TestServiceDelete(TestService):
|
||||
|
||||
def test_service_delete_no_options(self):
|
||||
arglist = [
|
||||
identity_fakes.service_name,
|
||||
self.fake_service.name,
|
||||
]
|
||||
verifylist = [
|
||||
('services', [identity_fakes.service_name]),
|
||||
('services', [self.fake_service.name]),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.services_mock.delete.assert_called_with(
|
||||
identity_fakes.service_id,
|
||||
self.fake_service.id,
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
@ -207,13 +198,7 @@ class TestServiceList(TestService):
|
||||
def setUp(self):
|
||||
super(TestServiceList, self).setUp()
|
||||
|
||||
self.services_mock.list.return_value = [
|
||||
fakes.FakeResource(
|
||||
None,
|
||||
copy.deepcopy(identity_fakes.SERVICE),
|
||||
loaded=True,
|
||||
),
|
||||
]
|
||||
self.services_mock.list.return_value = [self.fake_service]
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd = service.ListService(self.app, None)
|
||||
@ -233,9 +218,9 @@ class TestServiceList(TestService):
|
||||
collist = ('ID', 'Name', 'Type')
|
||||
self.assertEqual(collist, columns)
|
||||
datalist = ((
|
||||
identity_fakes.service_id,
|
||||
identity_fakes.service_name,
|
||||
identity_fakes.service_type,
|
||||
self.fake_service.id,
|
||||
self.fake_service.name,
|
||||
self.fake_service.type,
|
||||
), )
|
||||
self.assertEqual(datalist, tuple(data))
|
||||
|
||||
@ -258,10 +243,10 @@ class TestServiceList(TestService):
|
||||
collist = ('ID', 'Name', 'Type', 'Description')
|
||||
self.assertEqual(collist, columns)
|
||||
datalist = ((
|
||||
identity_fakes.service_id,
|
||||
identity_fakes.service_name,
|
||||
identity_fakes.service_type,
|
||||
identity_fakes.service_description,
|
||||
self.fake_service.id,
|
||||
self.fake_service.name,
|
||||
self.fake_service.type,
|
||||
self.fake_service.description,
|
||||
), )
|
||||
self.assertEqual(datalist, tuple(data))
|
||||
|
||||
@ -271,21 +256,17 @@ class TestServiceShow(TestService):
|
||||
def setUp(self):
|
||||
super(TestServiceShow, self).setUp()
|
||||
|
||||
self.services_mock.get.return_value = fakes.FakeResource(
|
||||
None,
|
||||
copy.deepcopy(identity_fakes.SERVICE),
|
||||
loaded=True,
|
||||
)
|
||||
self.services_mock.get.return_value = self.fake_service
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd = service.ShowService(self.app, None)
|
||||
|
||||
def test_service_show(self):
|
||||
arglist = [
|
||||
identity_fakes.service_name,
|
||||
self.fake_service.name,
|
||||
]
|
||||
verifylist = [
|
||||
('service', identity_fakes.service_name),
|
||||
('service', self.fake_service.name),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
@ -296,15 +277,15 @@ class TestServiceShow(TestService):
|
||||
|
||||
# ServiceManager.get(id)
|
||||
self.services_mock.get.assert_called_with(
|
||||
identity_fakes.service_name,
|
||||
self.fake_service.name,
|
||||
)
|
||||
|
||||
collist = ('description', 'id', 'name', 'type')
|
||||
self.assertEqual(collist, columns)
|
||||
datalist = (
|
||||
identity_fakes.service_description,
|
||||
identity_fakes.service_id,
|
||||
identity_fakes.service_name,
|
||||
identity_fakes.service_type,
|
||||
self.fake_service.description,
|
||||
self.fake_service.id,
|
||||
self.fake_service.name,
|
||||
self.fake_service.type,
|
||||
)
|
||||
self.assertEqual(datalist, data)
|
||||
|
@ -21,6 +21,9 @@ from openstackclient.tests.identity.v2_0 import fakes as identity_fakes
|
||||
|
||||
class TestToken(identity_fakes.TestIdentityv2):
|
||||
|
||||
fake_user = identity_fakes.FakeUser.create_one_user()
|
||||
fake_project = identity_fakes.FakeProject.create_one_project()
|
||||
|
||||
def setUp(self):
|
||||
super(TestToken, self).setUp()
|
||||
|
||||
@ -57,8 +60,8 @@ class TestTokenIssue(TestToken):
|
||||
datalist = (
|
||||
auth_ref.expires,
|
||||
identity_fakes.token_id,
|
||||
identity_fakes.project_id,
|
||||
identity_fakes.user_id,
|
||||
'project-id',
|
||||
'user-id',
|
||||
)
|
||||
self.assertEqual(datalist, data)
|
||||
|
||||
@ -85,7 +88,7 @@ class TestTokenIssue(TestToken):
|
||||
datalist = (
|
||||
auth_ref.expires,
|
||||
identity_fakes.token_id,
|
||||
identity_fakes.user_id,
|
||||
'user-id',
|
||||
)
|
||||
self.assertEqual(datalist, data)
|
||||
|
||||
|
@ -13,19 +13,23 @@
|
||||
# under the License.
|
||||
#
|
||||
|
||||
import copy
|
||||
import mock
|
||||
|
||||
from keystoneauth1 import exceptions as ks_exc
|
||||
from osc_lib import exceptions
|
||||
|
||||
from openstackclient.identity.v2_0 import user
|
||||
from openstackclient.tests import fakes
|
||||
from openstackclient.tests.identity.v2_0 import fakes as identity_fakes
|
||||
|
||||
|
||||
class TestUser(identity_fakes.TestIdentityv2):
|
||||
|
||||
fake_project = identity_fakes.FakeProject.create_one_project()
|
||||
attr = {
|
||||
'tenantId': fake_project.id,
|
||||
}
|
||||
fake_user = identity_fakes.FakeUser.create_one_user(attr)
|
||||
|
||||
def setUp(self):
|
||||
super(TestUser, self).setUp()
|
||||
|
||||
@ -40,6 +44,12 @@ class TestUser(identity_fakes.TestIdentityv2):
|
||||
|
||||
class TestUserCreate(TestUser):
|
||||
|
||||
fake_project_c = identity_fakes.FakeProject.create_one_project()
|
||||
attr = {
|
||||
'tenantId': fake_project_c.id,
|
||||
}
|
||||
fake_user_c = identity_fakes.FakeUser.create_one_user(attr)
|
||||
|
||||
columns = (
|
||||
'email',
|
||||
'enabled',
|
||||
@ -48,39 +58,31 @@ class TestUserCreate(TestUser):
|
||||
'project_id',
|
||||
)
|
||||
datalist = (
|
||||
identity_fakes.user_email,
|
||||
fake_user_c.email,
|
||||
True,
|
||||
identity_fakes.user_id,
|
||||
identity_fakes.user_name,
|
||||
identity_fakes.project_id,
|
||||
fake_user_c.id,
|
||||
fake_user_c.name,
|
||||
fake_project_c.id,
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
super(TestUserCreate, self).setUp()
|
||||
|
||||
self.projects_mock.get.return_value = fakes.FakeResource(
|
||||
None,
|
||||
copy.deepcopy(identity_fakes.PROJECT),
|
||||
loaded=True,
|
||||
)
|
||||
self.projects_mock.get.return_value = self.fake_project_c
|
||||
|
||||
self.users_mock.create.return_value = fakes.FakeResource(
|
||||
None,
|
||||
copy.deepcopy(identity_fakes.USER),
|
||||
loaded=True,
|
||||
)
|
||||
self.users_mock.create.return_value = self.fake_user_c
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd = user.CreateUser(self.app, None)
|
||||
|
||||
def test_user_create_no_options(self):
|
||||
arglist = [
|
||||
identity_fakes.user_name,
|
||||
self.fake_user_c.name,
|
||||
]
|
||||
verifylist = [
|
||||
('enable', False),
|
||||
('disable', False),
|
||||
('name', identity_fakes.user_name),
|
||||
('name', self.fake_user_c.name),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
@ -96,7 +98,7 @@ class TestUserCreate(TestUser):
|
||||
}
|
||||
# UserManager.create(name, password, email, tenant_id=, enabled=)
|
||||
self.users_mock.create.assert_called_with(
|
||||
identity_fakes.user_name,
|
||||
self.fake_user_c.name,
|
||||
None,
|
||||
None,
|
||||
**kwargs
|
||||
@ -108,10 +110,10 @@ class TestUserCreate(TestUser):
|
||||
def test_user_create_password(self):
|
||||
arglist = [
|
||||
'--password', 'secret',
|
||||
identity_fakes.user_name,
|
||||
self.fake_user_c.name,
|
||||
]
|
||||
verifylist = [
|
||||
('name', identity_fakes.user_name),
|
||||
('name', self.fake_user_c.name),
|
||||
('password_prompt', False),
|
||||
('password', 'secret')
|
||||
]
|
||||
@ -129,7 +131,7 @@ class TestUserCreate(TestUser):
|
||||
}
|
||||
# UserManager.create(name, password, email, tenant_id=, enabled=)
|
||||
self.users_mock.create.assert_called_with(
|
||||
identity_fakes.user_name,
|
||||
self.fake_user_c.name,
|
||||
'secret',
|
||||
None,
|
||||
**kwargs
|
||||
@ -140,10 +142,10 @@ class TestUserCreate(TestUser):
|
||||
def test_user_create_password_prompt(self):
|
||||
arglist = [
|
||||
'--password-prompt',
|
||||
identity_fakes.user_name,
|
||||
self.fake_user_c.name,
|
||||
]
|
||||
verifylist = [
|
||||
('name', identity_fakes.user_name),
|
||||
('name', self.fake_user_c.name),
|
||||
('password_prompt', True)
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
@ -163,7 +165,7 @@ class TestUserCreate(TestUser):
|
||||
}
|
||||
# UserManager.create(name, password, email, tenant_id=, enabled=)
|
||||
self.users_mock.create.assert_called_with(
|
||||
identity_fakes.user_name,
|
||||
self.fake_user_c.name,
|
||||
'abc123',
|
||||
None,
|
||||
**kwargs
|
||||
@ -175,10 +177,10 @@ class TestUserCreate(TestUser):
|
||||
def test_user_create_email(self):
|
||||
arglist = [
|
||||
'--email', 'barney@example.com',
|
||||
identity_fakes.user_name,
|
||||
self.fake_user_c.name,
|
||||
]
|
||||
verifylist = [
|
||||
('name', identity_fakes.user_name),
|
||||
('name', self.fake_user_c.name),
|
||||
('email', 'barney@example.com'),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
@ -195,7 +197,7 @@ class TestUserCreate(TestUser):
|
||||
}
|
||||
# UserManager.create(name, password, email, tenant_id=, enabled=)
|
||||
self.users_mock.create.assert_called_with(
|
||||
identity_fakes.user_name,
|
||||
self.fake_user_c.name,
|
||||
None,
|
||||
'barney@example.com',
|
||||
**kwargs
|
||||
@ -206,27 +208,22 @@ class TestUserCreate(TestUser):
|
||||
|
||||
def test_user_create_project(self):
|
||||
# Return the new project
|
||||
self.projects_mock.get.return_value = fakes.FakeResource(
|
||||
None,
|
||||
copy.deepcopy(identity_fakes.PROJECT_2),
|
||||
loaded=True,
|
||||
)
|
||||
self.projects_mock.get.return_value = self.fake_project_c
|
||||
|
||||
# Set up to return an updated user
|
||||
USER_2 = copy.deepcopy(identity_fakes.USER)
|
||||
USER_2['tenantId'] = identity_fakes.PROJECT_2['id']
|
||||
self.users_mock.create.return_value = fakes.FakeResource(
|
||||
None,
|
||||
USER_2,
|
||||
loaded=True,
|
||||
)
|
||||
attr = {
|
||||
'tenantId': self.fake_project_c.id,
|
||||
}
|
||||
user_2 = identity_fakes.FakeUser.create_one_user(attr)
|
||||
self.users_mock.create.return_value = user_2
|
||||
|
||||
arglist = [
|
||||
'--project', identity_fakes.PROJECT_2['name'],
|
||||
identity_fakes.user_name,
|
||||
'--project', self.fake_project_c.name,
|
||||
user_2.name,
|
||||
]
|
||||
verifylist = [
|
||||
('name', identity_fakes.user_name),
|
||||
('project', identity_fakes.PROJECT_2['name']),
|
||||
('name', user_2.name),
|
||||
('project', self.fake_project_c.name),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
@ -238,11 +235,11 @@ class TestUserCreate(TestUser):
|
||||
# Set expected values
|
||||
kwargs = {
|
||||
'enabled': True,
|
||||
'tenant_id': identity_fakes.PROJECT_2['id'],
|
||||
'tenant_id': self.fake_project_c.id,
|
||||
}
|
||||
# UserManager.create(name, password, email, tenant_id=, enabled=)
|
||||
self.users_mock.create.assert_called_with(
|
||||
identity_fakes.user_name,
|
||||
user_2.name,
|
||||
None,
|
||||
None,
|
||||
**kwargs
|
||||
@ -250,21 +247,21 @@ class TestUserCreate(TestUser):
|
||||
|
||||
self.assertEqual(self.columns, columns)
|
||||
datalist = (
|
||||
identity_fakes.user_email,
|
||||
user_2.email,
|
||||
True,
|
||||
identity_fakes.user_id,
|
||||
identity_fakes.user_name,
|
||||
identity_fakes.PROJECT_2['id'],
|
||||
user_2.id,
|
||||
user_2.name,
|
||||
self.fake_project_c.id,
|
||||
)
|
||||
self.assertEqual(datalist, data)
|
||||
|
||||
def test_user_create_enable(self):
|
||||
arglist = [
|
||||
'--enable',
|
||||
identity_fakes.user_name,
|
||||
self.fake_user_c.name,
|
||||
]
|
||||
verifylist = [
|
||||
('name', identity_fakes.user_name),
|
||||
('name', self.fake_user_c.name),
|
||||
('enable', True),
|
||||
('disable', False),
|
||||
]
|
||||
@ -282,7 +279,7 @@ class TestUserCreate(TestUser):
|
||||
}
|
||||
# UserManager.create(name, password, email, tenant_id=, enabled=)
|
||||
self.users_mock.create.assert_called_with(
|
||||
identity_fakes.user_name,
|
||||
self.fake_user_c.name,
|
||||
None,
|
||||
None,
|
||||
**kwargs
|
||||
@ -294,10 +291,10 @@ class TestUserCreate(TestUser):
|
||||
def test_user_create_disable(self):
|
||||
arglist = [
|
||||
'--disable',
|
||||
identity_fakes.user_name,
|
||||
self.fake_user_c.name,
|
||||
]
|
||||
verifylist = [
|
||||
('name', identity_fakes.user_name),
|
||||
('name', self.fake_user_c.name),
|
||||
('enable', False),
|
||||
('disable', True),
|
||||
]
|
||||
@ -315,7 +312,7 @@ class TestUserCreate(TestUser):
|
||||
}
|
||||
# UserManager.create(name, password, email, tenant_id=, enabled=)
|
||||
self.users_mock.create.assert_called_with(
|
||||
identity_fakes.user_name,
|
||||
self.fake_user_c.name,
|
||||
None,
|
||||
None,
|
||||
**kwargs
|
||||
@ -331,18 +328,14 @@ class TestUserCreate(TestUser):
|
||||
# need to make this throw an exception...
|
||||
self.users_mock.create.side_effect = _raise_conflict
|
||||
|
||||
self.users_mock.get.return_value = fakes.FakeResource(
|
||||
None,
|
||||
copy.deepcopy(identity_fakes.USER),
|
||||
loaded=True,
|
||||
)
|
||||
self.users_mock.get.return_value = self.fake_user_c
|
||||
|
||||
arglist = [
|
||||
'--or-show',
|
||||
identity_fakes.user_name,
|
||||
self.fake_user_c.name,
|
||||
]
|
||||
verifylist = [
|
||||
('name', identity_fakes.user_name),
|
||||
('name', self.fake_user_c.name),
|
||||
('or_show', True),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
@ -353,7 +346,7 @@ class TestUserCreate(TestUser):
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
# UserManager.create(name, password, email, tenant_id=, enabled=)
|
||||
self.users_mock.get.assert_called_with(identity_fakes.user_name)
|
||||
self.users_mock.get.assert_called_with(self.fake_user_c.name)
|
||||
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.datalist, data)
|
||||
@ -361,10 +354,10 @@ class TestUserCreate(TestUser):
|
||||
def test_user_create_or_show_not_exists(self):
|
||||
arglist = [
|
||||
'--or-show',
|
||||
identity_fakes.user_name,
|
||||
self.fake_user_c.name,
|
||||
]
|
||||
verifylist = [
|
||||
('name', identity_fakes.user_name),
|
||||
('name', self.fake_user_c.name),
|
||||
('or_show', True),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
@ -381,7 +374,7 @@ class TestUserCreate(TestUser):
|
||||
}
|
||||
# UserManager.create(name, password, email, tenant_id=, enabled=)
|
||||
self.users_mock.create.assert_called_with(
|
||||
identity_fakes.user_name,
|
||||
self.fake_user_c.name,
|
||||
None,
|
||||
None,
|
||||
**kwargs
|
||||
@ -396,11 +389,7 @@ class TestUserDelete(TestUser):
|
||||
super(TestUserDelete, self).setUp()
|
||||
|
||||
# This is the return value for utils.find_resource()
|
||||
self.users_mock.get.return_value = fakes.FakeResource(
|
||||
None,
|
||||
copy.deepcopy(identity_fakes.USER),
|
||||
loaded=True,
|
||||
)
|
||||
self.users_mock.get.return_value = self.fake_user
|
||||
self.users_mock.delete.return_value = None
|
||||
|
||||
# Get the command object to test
|
||||
@ -408,57 +397,47 @@ class TestUserDelete(TestUser):
|
||||
|
||||
def test_user_delete_no_options(self):
|
||||
arglist = [
|
||||
identity_fakes.user_id,
|
||||
self.fake_user.id,
|
||||
]
|
||||
verifylist = [
|
||||
('users', [identity_fakes.user_id]),
|
||||
('users', [self.fake_user.id]),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.users_mock.delete.assert_called_with(
|
||||
identity_fakes.user_id,
|
||||
self.fake_user.id,
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
|
||||
class TestUserList(TestUser):
|
||||
|
||||
fake_project_l = identity_fakes.FakeProject.create_one_project()
|
||||
attr = {
|
||||
'tenantId': fake_project_l.id,
|
||||
}
|
||||
fake_user_l = identity_fakes.FakeUser.create_one_user(attr)
|
||||
|
||||
columns = (
|
||||
'ID',
|
||||
'Name',
|
||||
)
|
||||
datalist = (
|
||||
(
|
||||
identity_fakes.user_id,
|
||||
identity_fakes.user_name,
|
||||
fake_user_l.id,
|
||||
fake_user_l.name,
|
||||
),
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
super(TestUserList, self).setUp()
|
||||
|
||||
self.projects_mock.get.return_value = fakes.FakeResource(
|
||||
None,
|
||||
copy.deepcopy(identity_fakes.PROJECT_2),
|
||||
loaded=True,
|
||||
)
|
||||
self.projects_mock.list.return_value = [
|
||||
fakes.FakeResource(
|
||||
None,
|
||||
copy.deepcopy(identity_fakes.PROJECT),
|
||||
loaded=True,
|
||||
),
|
||||
]
|
||||
self.projects_mock.get.return_value = self.fake_project_l
|
||||
self.projects_mock.list.return_value = [self.fake_project_l]
|
||||
|
||||
self.users_mock.list.return_value = [
|
||||
fakes.FakeResource(
|
||||
None,
|
||||
copy.deepcopy(identity_fakes.USER),
|
||||
loaded=True,
|
||||
),
|
||||
]
|
||||
self.users_mock.list.return_value = [self.fake_user_l]
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd = user.ListUser(self.app, None)
|
||||
@ -480,13 +459,13 @@ class TestUserList(TestUser):
|
||||
|
||||
def test_user_list_project(self):
|
||||
arglist = [
|
||||
'--project', identity_fakes.project_id,
|
||||
'--project', self.fake_project_l.id,
|
||||
]
|
||||
verifylist = [
|
||||
('project', identity_fakes.project_id),
|
||||
('project', self.fake_project_l.id),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
project_id = identity_fakes.PROJECT_2['id']
|
||||
project_id = self.fake_project_l.id
|
||||
|
||||
# In base command class Lister in cliff, abstract method take_action()
|
||||
# returns a tuple containing the column names and an iterable
|
||||
@ -517,10 +496,10 @@ class TestUserList(TestUser):
|
||||
collist = ('ID', 'Name', 'Project', 'Email', 'Enabled')
|
||||
self.assertEqual(collist, columns)
|
||||
datalist = ((
|
||||
identity_fakes.user_id,
|
||||
identity_fakes.user_name,
|
||||
identity_fakes.project_name,
|
||||
identity_fakes.user_email,
|
||||
self.fake_user_l.id,
|
||||
self.fake_user_l.name,
|
||||
self.fake_project_l.name,
|
||||
self.fake_user_l.email,
|
||||
True,
|
||||
), )
|
||||
self.assertEqual(datalist, tuple(data))
|
||||
@ -531,23 +510,15 @@ class TestUserSet(TestUser):
|
||||
def setUp(self):
|
||||
super(TestUserSet, self).setUp()
|
||||
|
||||
self.projects_mock.get.return_value = fakes.FakeResource(
|
||||
None,
|
||||
copy.deepcopy(identity_fakes.PROJECT),
|
||||
loaded=True,
|
||||
)
|
||||
self.users_mock.get.return_value = fakes.FakeResource(
|
||||
None,
|
||||
copy.deepcopy(identity_fakes.USER),
|
||||
loaded=True,
|
||||
)
|
||||
self.projects_mock.get.return_value = self.fake_project
|
||||
self.users_mock.get.return_value = self.fake_user
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd = user.SetUser(self.app, None)
|
||||
|
||||
def test_user_set_no_options(self):
|
||||
arglist = [
|
||||
identity_fakes.user_name,
|
||||
self.fake_user.name,
|
||||
]
|
||||
verifylist = [
|
||||
('name', None),
|
||||
@ -556,7 +527,7 @@ class TestUserSet(TestUser):
|
||||
('project', None),
|
||||
('enable', False),
|
||||
('disable', False),
|
||||
('user', identity_fakes.user_name),
|
||||
('user', self.fake_user.name),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
@ -588,7 +559,7 @@ class TestUserSet(TestUser):
|
||||
def test_user_set_name(self):
|
||||
arglist = [
|
||||
'--name', 'qwerty',
|
||||
identity_fakes.user_name,
|
||||
self.fake_user.name,
|
||||
]
|
||||
verifylist = [
|
||||
('name', 'qwerty'),
|
||||
@ -597,7 +568,7 @@ class TestUserSet(TestUser):
|
||||
('project', None),
|
||||
('enable', False),
|
||||
('disable', False),
|
||||
('user', identity_fakes.user_name),
|
||||
('user', self.fake_user.name),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
@ -610,7 +581,7 @@ class TestUserSet(TestUser):
|
||||
}
|
||||
# UserManager.update(user, **kwargs)
|
||||
self.users_mock.update.assert_called_with(
|
||||
identity_fakes.user_id,
|
||||
self.fake_user.id,
|
||||
**kwargs
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
@ -618,7 +589,7 @@ class TestUserSet(TestUser):
|
||||
def test_user_set_password(self):
|
||||
arglist = [
|
||||
'--password', 'secret',
|
||||
identity_fakes.user_name,
|
||||
self.fake_user.name,
|
||||
]
|
||||
verifylist = [
|
||||
('name', None),
|
||||
@ -628,7 +599,7 @@ class TestUserSet(TestUser):
|
||||
('project', None),
|
||||
('enable', False),
|
||||
('disable', False),
|
||||
('user', identity_fakes.user_name),
|
||||
('user', self.fake_user.name),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
@ -636,7 +607,7 @@ class TestUserSet(TestUser):
|
||||
|
||||
# UserManager.update_password(user, password)
|
||||
self.users_mock.update_password.assert_called_with(
|
||||
identity_fakes.user_id,
|
||||
self.fake_user.id,
|
||||
'secret',
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
@ -644,7 +615,7 @@ class TestUserSet(TestUser):
|
||||
def test_user_set_password_prompt(self):
|
||||
arglist = [
|
||||
'--password-prompt',
|
||||
identity_fakes.user_name,
|
||||
self.fake_user.name,
|
||||
]
|
||||
verifylist = [
|
||||
('name', None),
|
||||
@ -654,7 +625,7 @@ class TestUserSet(TestUser):
|
||||
('project', None),
|
||||
('enable', False),
|
||||
('disable', False),
|
||||
('user', identity_fakes.user_name),
|
||||
('user', self.fake_user.name),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
@ -665,7 +636,7 @@ class TestUserSet(TestUser):
|
||||
|
||||
# UserManager.update_password(user, password)
|
||||
self.users_mock.update_password.assert_called_with(
|
||||
identity_fakes.user_id,
|
||||
self.fake_user.id,
|
||||
'abc123',
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
@ -673,7 +644,7 @@ class TestUserSet(TestUser):
|
||||
def test_user_set_email(self):
|
||||
arglist = [
|
||||
'--email', 'barney@example.com',
|
||||
identity_fakes.user_name,
|
||||
self.fake_user.name,
|
||||
]
|
||||
verifylist = [
|
||||
('name', None),
|
||||
@ -682,7 +653,7 @@ class TestUserSet(TestUser):
|
||||
('project', None),
|
||||
('enable', False),
|
||||
('disable', False),
|
||||
('user', identity_fakes.user_name),
|
||||
('user', self.fake_user.name),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
@ -695,24 +666,24 @@ class TestUserSet(TestUser):
|
||||
}
|
||||
# UserManager.update(user, **kwargs)
|
||||
self.users_mock.update.assert_called_with(
|
||||
identity_fakes.user_id,
|
||||
self.fake_user.id,
|
||||
**kwargs
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_user_set_project(self):
|
||||
arglist = [
|
||||
'--project', identity_fakes.project_id,
|
||||
identity_fakes.user_name,
|
||||
'--project', self.fake_project.id,
|
||||
self.fake_user.name,
|
||||
]
|
||||
verifylist = [
|
||||
('name', None),
|
||||
('password', None),
|
||||
('email', None),
|
||||
('project', identity_fakes.project_id),
|
||||
('project', self.fake_project.id),
|
||||
('enable', False),
|
||||
('disable', False),
|
||||
('user', identity_fakes.user_name),
|
||||
('user', self.fake_user.name),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
@ -720,15 +691,15 @@ class TestUserSet(TestUser):
|
||||
|
||||
# UserManager.update_tenant(user, tenant)
|
||||
self.users_mock.update_tenant.assert_called_with(
|
||||
identity_fakes.user_id,
|
||||
identity_fakes.project_id,
|
||||
self.fake_user.id,
|
||||
self.fake_project.id,
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_user_set_enable(self):
|
||||
arglist = [
|
||||
'--enable',
|
||||
identity_fakes.user_name,
|
||||
self.fake_user.name,
|
||||
]
|
||||
verifylist = [
|
||||
('name', None),
|
||||
@ -737,7 +708,7 @@ class TestUserSet(TestUser):
|
||||
('project', None),
|
||||
('enable', True),
|
||||
('disable', False),
|
||||
('user', identity_fakes.user_name),
|
||||
('user', self.fake_user.name),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
@ -749,7 +720,7 @@ class TestUserSet(TestUser):
|
||||
}
|
||||
# UserManager.update(user, **kwargs)
|
||||
self.users_mock.update.assert_called_with(
|
||||
identity_fakes.user_id,
|
||||
self.fake_user.id,
|
||||
**kwargs
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
@ -757,7 +728,7 @@ class TestUserSet(TestUser):
|
||||
def test_user_set_disable(self):
|
||||
arglist = [
|
||||
'--disable',
|
||||
identity_fakes.user_name,
|
||||
self.fake_user.name,
|
||||
]
|
||||
verifylist = [
|
||||
('name', None),
|
||||
@ -766,7 +737,7 @@ class TestUserSet(TestUser):
|
||||
('project', None),
|
||||
('enable', False),
|
||||
('disable', True),
|
||||
('user', identity_fakes.user_name),
|
||||
('user', self.fake_user.name),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
@ -778,7 +749,7 @@ class TestUserSet(TestUser):
|
||||
}
|
||||
# UserManager.update(user, **kwargs)
|
||||
self.users_mock.update.assert_called_with(
|
||||
identity_fakes.user_id,
|
||||
self.fake_user.id,
|
||||
**kwargs
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
@ -789,21 +760,17 @@ class TestUserShow(TestUser):
|
||||
def setUp(self):
|
||||
super(TestUserShow, self).setUp()
|
||||
|
||||
self.users_mock.get.return_value = fakes.FakeResource(
|
||||
None,
|
||||
copy.deepcopy(identity_fakes.USER),
|
||||
loaded=True,
|
||||
)
|
||||
self.users_mock.get.return_value = self.fake_user
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd = user.ShowUser(self.app, None)
|
||||
|
||||
def test_user_show(self):
|
||||
arglist = [
|
||||
identity_fakes.user_id,
|
||||
self.fake_user.id,
|
||||
]
|
||||
verifylist = [
|
||||
('user', identity_fakes.user_id),
|
||||
('user', self.fake_user.id),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
@ -812,15 +779,15 @@ class TestUserShow(TestUser):
|
||||
# data to be shown.
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.users_mock.get.assert_called_with(identity_fakes.user_id)
|
||||
self.users_mock.get.assert_called_with(self.fake_user.id)
|
||||
|
||||
collist = ('email', 'enabled', 'id', 'name', 'project_id')
|
||||
self.assertEqual(collist, columns)
|
||||
datalist = (
|
||||
identity_fakes.user_email,
|
||||
self.fake_user.email,
|
||||
True,
|
||||
identity_fakes.user_id,
|
||||
identity_fakes.user_name,
|
||||
identity_fakes.project_id,
|
||||
self.fake_user.id,
|
||||
self.fake_user.name,
|
||||
self.fake_project.id,
|
||||
)
|
||||
self.assertEqual(datalist, data)
|
||||
|
Loading…
Reference in New Issue
Block a user