Refactor identity v3 unit tests with fake class

Refactor unit tests in identity v3 for "user", "endpoint", "group"
and "service" with fake classes.

Change-Id: I57316bbf762c805f8e9ae225b394bbe58ebdd416
Partially-Implements: blueprint refactor-identity-unit-test
This commit is contained in:
Huanxuan Ao 2016-07-26 18:05:36 +08:00
parent 2a1c2b2275
commit 5125b6f73b
5 changed files with 573 additions and 610 deletions

View File

@ -730,7 +730,7 @@ class FakeUser(object):
'default_project_id': 'project-' + uuid.uuid4().hex, 'default_project_id': 'project-' + uuid.uuid4().hex,
'email': 'user-email-' + uuid.uuid4().hex, 'email': 'user-email-' + uuid.uuid4().hex,
'enabled': True, 'enabled': True,
'domain_id': 'domain-id' + uuid.uuid4().hex, 'domain_id': 'domain-id-' + uuid.uuid4().hex,
'links': 'links-' + uuid.uuid4().hex, 'links': 'links-' + uuid.uuid4().hex,
} }
user_info.update(attrs) user_info.update(attrs)
@ -738,3 +738,125 @@ class FakeUser(object):
user = fakes.FakeResource(info=copy.deepcopy(user_info), user = fakes.FakeResource(info=copy.deepcopy(user_info),
loaded=True) loaded=True)
return user return user
class FakeGroup(object):
"""Fake one or more group."""
@staticmethod
def create_one_group(attrs=None):
"""Create a fake group.
:param Dictionary attrs:
A dictionary with all attributes
:return:
A FakeResource object, with id, name, and so on
"""
attrs = attrs or {}
# set default attributes.
group_info = {
'id': 'group-id-' + uuid.uuid4().hex,
'name': 'group-name-' + uuid.uuid4().hex,
'links': 'links-' + uuid.uuid4().hex,
'domain_id': 'domain-id-' + uuid.uuid4().hex,
'description': 'group-description-' + uuid.uuid4().hex,
}
group_info.update(attrs)
group = fakes.FakeResource(info=copy.deepcopy(group_info),
loaded=True)
return group
class FakeEndpoint(object):
"""Fake one or more endpoint."""
@staticmethod
def create_one_endpoint(attrs=None):
"""Create a fake endpoint.
:param Dictionary attrs:
A dictionary with all attributes
:return:
A FakeResource object, with id, url, and so on
"""
attrs = attrs or {}
# set default attributes.
endpoint_info = {
'id': 'endpoint-id-' + uuid.uuid4().hex,
'url': 'url-' + uuid.uuid4().hex,
'region': 'endpoint-region-' + uuid.uuid4().hex,
'interface': 'admin',
'service_id': 'service-id-' + uuid.uuid4().hex,
'enabled': True,
'links': 'links-' + uuid.uuid4().hex,
}
endpoint_info.update(attrs)
endpoint = fakes.FakeResource(info=copy.deepcopy(endpoint_info),
loaded=True)
return endpoint
class FakeService(object):
"""Fake one or more service."""
@staticmethod
def create_one_service(attrs=None):
"""Create a fake service.
:param Dictionary attrs:
A dictionary with all attributes
:return:
A FakeResource object, with id, name, and so on
"""
attrs = attrs or {}
# set default attributes.
service_info = {
'id': 'service-id-' + uuid.uuid4().hex,
'name': 'service-name-' + uuid.uuid4().hex,
'type': 'service-type-' + uuid.uuid4().hex,
'description': 'service-description-' + uuid.uuid4().hex,
'enabled': True,
'links': 'links-' + uuid.uuid4().hex,
}
service_info.update(attrs)
service = fakes.FakeResource(info=copy.deepcopy(service_info),
loaded=True)
return service
class FakeRoleAssignment(object):
"""Fake one or more role assignment."""
@staticmethod
def create_one_role_assignment(attrs=None):
"""Create a fake role assignment.
:param Dictionary attrs:
A dictionary with all attributes
:return:
A FakeResource object, with scope, user, and so on
"""
attrs = attrs or {}
# set default attributes.
role_assignment_info = {
'scope': {'project': {'id': 'project-id-' + uuid.uuid4().hex}},
'user': {'id': 'user-id-' + uuid.uuid4().hex},
'role': {'id': 'role-id-' + uuid.uuid4().hex},
}
role_assignment_info.update(attrs)
role_assignment = fakes.FakeResource(
info=copy.deepcopy(role_assignment_info), loaded=True)
return role_assignment

View File

@ -10,11 +10,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import copy
from openstackclient.identity.v3 import endpoint from openstackclient.identity.v3 import endpoint
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
@ -31,12 +27,11 @@ class TestEndpoint(identity_fakes.TestIdentityv3):
self.services_mock = self.app.client_manager.identity.services self.services_mock = self.app.client_manager.identity.services
self.services_mock.reset_mock() self.services_mock.reset_mock()
def get_fake_service_name(self):
return identity_fakes.service_name
class TestEndpointCreate(TestEndpoint): class TestEndpointCreate(TestEndpoint):
service = identity_fakes.FakeService.create_one_service()
columns = ( columns = (
'enabled', 'enabled',
'id', 'id',
@ -51,33 +46,27 @@ class TestEndpointCreate(TestEndpoint):
def setUp(self): def setUp(self):
super(TestEndpointCreate, self).setUp() super(TestEndpointCreate, self).setUp()
self.endpoints_mock.create.return_value = fakes.FakeResource( self.endpoint = identity_fakes.FakeEndpoint.create_one_endpoint(
None, attrs={'service_id': self.service.id})
copy.deepcopy(identity_fakes.ENDPOINT), self.endpoints_mock.create.return_value = self.endpoint
loaded=True,
)
# This is the return value for common.find_resource(service) # This is the return value for common.find_resource(service)
self.services_mock.get.return_value = fakes.FakeResource( self.services_mock.get.return_value = self.service
None,
copy.deepcopy(identity_fakes.SERVICE),
loaded=True,
)
# Get the command object to test # Get the command object to test
self.cmd = endpoint.CreateEndpoint(self.app, None) self.cmd = endpoint.CreateEndpoint(self.app, None)
def test_endpoint_create_no_options(self): def test_endpoint_create_no_options(self):
arglist = [ arglist = [
identity_fakes.service_id, self.service.id,
identity_fakes.endpoint_interface, self.endpoint.interface,
identity_fakes.endpoint_url, self.endpoint.url,
] ]
verifylist = [ verifylist = [
('enabled', True), ('enabled', True),
('service', identity_fakes.service_id), ('service', self.service.id),
('interface', identity_fakes.endpoint_interface), ('interface', self.endpoint.interface),
('url', identity_fakes.endpoint_url), ('url', self.endpoint.url),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -88,9 +77,9 @@ class TestEndpointCreate(TestEndpoint):
# Set expected values # Set expected values
kwargs = { kwargs = {
'service': identity_fakes.service_id, 'service': self.service.id,
'url': identity_fakes.endpoint_url, 'url': self.endpoint.url,
'interface': identity_fakes.endpoint_interface, 'interface': self.endpoint.interface,
'enabled': True, 'enabled': True,
'region': None, 'region': None,
} }
@ -102,29 +91,29 @@ class TestEndpointCreate(TestEndpoint):
self.assertEqual(self.columns, columns) self.assertEqual(self.columns, columns)
datalist = ( datalist = (
True, True,
identity_fakes.endpoint_id, self.endpoint.id,
identity_fakes.endpoint_interface, self.endpoint.interface,
identity_fakes.endpoint_region, self.endpoint.region,
identity_fakes.service_id, self.service.id,
self.get_fake_service_name(), self.service.name,
identity_fakes.service_type, self.service.type,
identity_fakes.endpoint_url, self.endpoint.url,
) )
self.assertEqual(datalist, data) self.assertEqual(datalist, data)
def test_endpoint_create_region(self): def test_endpoint_create_region(self):
arglist = [ arglist = [
identity_fakes.service_id, self.service.id,
identity_fakes.endpoint_interface, self.endpoint.interface,
identity_fakes.endpoint_url, self.endpoint.url,
'--region', identity_fakes.endpoint_region, '--region', self.endpoint.region,
] ]
verifylist = [ verifylist = [
('enabled', True), ('enabled', True),
('service', identity_fakes.service_id), ('service', self.service.id),
('interface', identity_fakes.endpoint_interface), ('interface', self.endpoint.interface),
('url', identity_fakes.endpoint_url), ('url', self.endpoint.url),
('region', identity_fakes.endpoint_region), ('region', self.endpoint.region),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -135,11 +124,11 @@ class TestEndpointCreate(TestEndpoint):
# Set expected values # Set expected values
kwargs = { kwargs = {
'service': identity_fakes.service_id, 'service': self.service.id,
'url': identity_fakes.endpoint_url, 'url': self.endpoint.url,
'interface': identity_fakes.endpoint_interface, 'interface': self.endpoint.interface,
'enabled': True, 'enabled': True,
'region': identity_fakes.endpoint_region, 'region': self.endpoint.region,
} }
self.endpoints_mock.create.assert_called_with( self.endpoints_mock.create.assert_called_with(
@ -149,28 +138,28 @@ class TestEndpointCreate(TestEndpoint):
self.assertEqual(self.columns, columns) self.assertEqual(self.columns, columns)
datalist = ( datalist = (
True, True,
identity_fakes.endpoint_id, self.endpoint.id,
identity_fakes.endpoint_interface, self.endpoint.interface,
identity_fakes.endpoint_region, self.endpoint.region,
identity_fakes.service_id, self.service.id,
self.get_fake_service_name(), self.service.name,
identity_fakes.service_type, self.service.type,
identity_fakes.endpoint_url, self.endpoint.url,
) )
self.assertEqual(datalist, data) self.assertEqual(datalist, data)
def test_endpoint_create_enable(self): def test_endpoint_create_enable(self):
arglist = [ arglist = [
identity_fakes.service_id, self.service.id,
identity_fakes.endpoint_interface, self.endpoint.interface,
identity_fakes.endpoint_url, self.endpoint.url,
'--enable' '--enable'
] ]
verifylist = [ verifylist = [
('enabled', True), ('enabled', True),
('service', identity_fakes.service_id), ('service', self.service.id),
('interface', identity_fakes.endpoint_interface), ('interface', self.endpoint.interface),
('url', identity_fakes.endpoint_url), ('url', self.endpoint.url),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -181,9 +170,9 @@ class TestEndpointCreate(TestEndpoint):
# Set expected values # Set expected values
kwargs = { kwargs = {
'service': identity_fakes.service_id, 'service': self.service.id,
'url': identity_fakes.endpoint_url, 'url': self.endpoint.url,
'interface': identity_fakes.endpoint_interface, 'interface': self.endpoint.interface,
'enabled': True, 'enabled': True,
'region': None, 'region': None,
} }
@ -195,28 +184,28 @@ class TestEndpointCreate(TestEndpoint):
self.assertEqual(self.columns, columns) self.assertEqual(self.columns, columns)
datalist = ( datalist = (
True, True,
identity_fakes.endpoint_id, self.endpoint.id,
identity_fakes.endpoint_interface, self.endpoint.interface,
identity_fakes.endpoint_region, self.endpoint.region,
identity_fakes.service_id, self.service.id,
self.get_fake_service_name(), self.service.name,
identity_fakes.service_type, self.service.type,
identity_fakes.endpoint_url, self.endpoint.url,
) )
self.assertEqual(datalist, data) self.assertEqual(datalist, data)
def test_endpoint_create_disable(self): def test_endpoint_create_disable(self):
arglist = [ arglist = [
identity_fakes.service_id, self.service.id,
identity_fakes.endpoint_interface, self.endpoint.interface,
identity_fakes.endpoint_url, self.endpoint.url,
'--disable', '--disable',
] ]
verifylist = [ verifylist = [
('enabled', False), ('enabled', False),
('service', identity_fakes.service_id), ('service', self.service.id),
('interface', identity_fakes.endpoint_interface), ('interface', self.endpoint.interface),
('url', identity_fakes.endpoint_url), ('url', self.endpoint.url),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -227,9 +216,9 @@ class TestEndpointCreate(TestEndpoint):
# Set expected values # Set expected values
kwargs = { kwargs = {
'service': identity_fakes.service_id, 'service': self.service.id,
'url': identity_fakes.endpoint_url, 'url': self.endpoint.url,
'interface': identity_fakes.endpoint_interface, 'interface': self.endpoint.interface,
'enabled': False, 'enabled': False,
'region': None, 'region': None,
} }
@ -241,28 +230,26 @@ class TestEndpointCreate(TestEndpoint):
self.assertEqual(self.columns, columns) self.assertEqual(self.columns, columns)
datalist = ( datalist = (
True, True,
identity_fakes.endpoint_id, self.endpoint.id,
identity_fakes.endpoint_interface, self.endpoint.interface,
identity_fakes.endpoint_region, self.endpoint.region,
identity_fakes.service_id, self.service.id,
self.get_fake_service_name(), self.service.name,
identity_fakes.service_type, self.service.type,
identity_fakes.endpoint_url, self.endpoint.url,
) )
self.assertEqual(datalist, data) self.assertEqual(datalist, data)
class TestEndpointDelete(TestEndpoint): class TestEndpointDelete(TestEndpoint):
endpoint = identity_fakes.FakeEndpoint.create_one_endpoint()
def setUp(self): def setUp(self):
super(TestEndpointDelete, self).setUp() super(TestEndpointDelete, self).setUp()
# This is the return value for utils.find_resource(endpoint) # This is the return value for utils.find_resource(endpoint)
self.endpoints_mock.get.return_value = fakes.FakeResource( self.endpoints_mock.get.return_value = self.endpoint
None,
copy.deepcopy(identity_fakes.ENDPOINT),
loaded=True,
)
self.endpoints_mock.delete.return_value = None self.endpoints_mock.delete.return_value = None
# Get the command object to test # Get the command object to test
@ -270,23 +257,27 @@ class TestEndpointDelete(TestEndpoint):
def test_endpoint_delete(self): def test_endpoint_delete(self):
arglist = [ arglist = [
identity_fakes.endpoint_id, self.endpoint.id,
] ]
verifylist = [ verifylist = [
('endpoint', [identity_fakes.endpoint_id]), ('endpoint', [self.endpoint.id]),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args) result = self.cmd.take_action(parsed_args)
self.endpoints_mock.delete.assert_called_with( self.endpoints_mock.delete.assert_called_with(
identity_fakes.endpoint_id, self.endpoint.id,
) )
self.assertIsNone(result) self.assertIsNone(result)
class TestEndpointList(TestEndpoint): class TestEndpointList(TestEndpoint):
service = identity_fakes.FakeService.create_one_service()
endpoint = identity_fakes.FakeEndpoint.create_one_endpoint(
attrs={'service_id': service.id})
columns = ( columns = (
'ID', 'ID',
'Region', 'Region',
@ -300,20 +291,10 @@ class TestEndpointList(TestEndpoint):
def setUp(self): def setUp(self):
super(TestEndpointList, self).setUp() super(TestEndpointList, self).setUp()
self.endpoints_mock.list.return_value = [ self.endpoints_mock.list.return_value = [self.endpoint]
fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.ENDPOINT),
loaded=True,
),
]
# This is the return value for common.find_resource(service) # This is the return value for common.find_resource(service)
self.services_mock.get.return_value = fakes.FakeResource( self.services_mock.get.return_value = self.service
None,
copy.deepcopy(identity_fakes.SERVICE),
loaded=True,
)
# Get the command object to test # Get the command object to test
self.cmd = endpoint.ListEndpoint(self.app, None) self.cmd = endpoint.ListEndpoint(self.app, None)
@ -332,23 +313,23 @@ class TestEndpointList(TestEndpoint):
self.assertEqual(self.columns, columns) self.assertEqual(self.columns, columns)
datalist = ( datalist = (
( (
identity_fakes.endpoint_id, self.endpoint.id,
identity_fakes.endpoint_region, self.endpoint.region,
self.get_fake_service_name(), self.service.name,
identity_fakes.service_type, self.service.type,
True, True,
identity_fakes.endpoint_interface, self.endpoint.interface,
identity_fakes.endpoint_url, self.endpoint.url,
), ),
) )
self.assertEqual(datalist, tuple(data)) self.assertEqual(datalist, tuple(data))
def test_endpoint_list_service(self): def test_endpoint_list_service(self):
arglist = [ arglist = [
'--service', identity_fakes.service_id, '--service', self.service.id,
] ]
verifylist = [ verifylist = [
('service', identity_fakes.service_id), ('service', self.service.id),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -359,30 +340,30 @@ class TestEndpointList(TestEndpoint):
# Set expected values # Set expected values
kwargs = { kwargs = {
'service': identity_fakes.service_id, 'service': self.service.id,
} }
self.endpoints_mock.list.assert_called_with(**kwargs) self.endpoints_mock.list.assert_called_with(**kwargs)
self.assertEqual(self.columns, columns) self.assertEqual(self.columns, columns)
datalist = ( datalist = (
( (
identity_fakes.endpoint_id, self.endpoint.id,
identity_fakes.endpoint_region, self.endpoint.region,
self.get_fake_service_name(), self.service.name,
identity_fakes.service_type, self.service.type,
True, True,
identity_fakes.endpoint_interface, self.endpoint.interface,
identity_fakes.endpoint_url, self.endpoint.url,
), ),
) )
self.assertEqual(datalist, tuple(data)) self.assertEqual(datalist, tuple(data))
def test_endpoint_list_interface(self): def test_endpoint_list_interface(self):
arglist = [ arglist = [
'--interface', identity_fakes.endpoint_interface, '--interface', self.endpoint.interface,
] ]
verifylist = [ verifylist = [
('interface', identity_fakes.endpoint_interface), ('interface', self.endpoint.interface),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -393,30 +374,30 @@ class TestEndpointList(TestEndpoint):
# Set expected values # Set expected values
kwargs = { kwargs = {
'interface': identity_fakes.endpoint_interface, 'interface': self.endpoint.interface,
} }
self.endpoints_mock.list.assert_called_with(**kwargs) self.endpoints_mock.list.assert_called_with(**kwargs)
self.assertEqual(self.columns, columns) self.assertEqual(self.columns, columns)
datalist = ( datalist = (
( (
identity_fakes.endpoint_id, self.endpoint.id,
identity_fakes.endpoint_region, self.endpoint.region,
self.get_fake_service_name(), self.service.name,
identity_fakes.service_type, self.service.type,
True, True,
identity_fakes.endpoint_interface, self.endpoint.interface,
identity_fakes.endpoint_url, self.endpoint.url,
), ),
) )
self.assertEqual(datalist, tuple(data)) self.assertEqual(datalist, tuple(data))
def test_endpoint_list_region(self): def test_endpoint_list_region(self):
arglist = [ arglist = [
'--region', identity_fakes.endpoint_region, '--region', self.endpoint.region,
] ]
verifylist = [ verifylist = [
('region', identity_fakes.endpoint_region), ('region', self.endpoint.region),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -427,20 +408,20 @@ class TestEndpointList(TestEndpoint):
# Set expected values # Set expected values
kwargs = { kwargs = {
'region': identity_fakes.endpoint_region, 'region': self.endpoint.region,
} }
self.endpoints_mock.list.assert_called_with(**kwargs) self.endpoints_mock.list.assert_called_with(**kwargs)
self.assertEqual(self.columns, columns) self.assertEqual(self.columns, columns)
datalist = ( datalist = (
( (
identity_fakes.endpoint_id, self.endpoint.id,
identity_fakes.endpoint_region, self.endpoint.region,
self.get_fake_service_name(), self.service.name,
identity_fakes.service_type, self.service.type,
True, True,
identity_fakes.endpoint_interface, self.endpoint.interface,
identity_fakes.endpoint_url, self.endpoint.url,
), ),
) )
self.assertEqual(datalist, tuple(data)) self.assertEqual(datalist, tuple(data))
@ -448,38 +429,30 @@ class TestEndpointList(TestEndpoint):
class TestEndpointSet(TestEndpoint): class TestEndpointSet(TestEndpoint):
service = identity_fakes.FakeService.create_one_service()
endpoint = identity_fakes.FakeEndpoint.create_one_endpoint(
attrs={'service_id': service.id})
def setUp(self): def setUp(self):
super(TestEndpointSet, self).setUp() super(TestEndpointSet, self).setUp()
# This is the return value for utils.find_resource(endpoint) # This is the return value for utils.find_resource(endpoint)
self.endpoints_mock.get.return_value = fakes.FakeResource( self.endpoints_mock.get.return_value = self.endpoint
None,
copy.deepcopy(identity_fakes.ENDPOINT),
loaded=True,
)
self.endpoints_mock.update.return_value = fakes.FakeResource( self.endpoints_mock.update.return_value = self.endpoint
None,
copy.deepcopy(identity_fakes.ENDPOINT),
loaded=True,
)
# This is the return value for common.find_resource(service) # This is the return value for common.find_resource(service)
self.services_mock.get.return_value = fakes.FakeResource( self.services_mock.get.return_value = self.service
None,
copy.deepcopy(identity_fakes.SERVICE),
loaded=True,
)
# Get the command object to test # Get the command object to test
self.cmd = endpoint.SetEndpoint(self.app, None) self.cmd = endpoint.SetEndpoint(self.app, None)
def test_endpoint_set_no_options(self): def test_endpoint_set_no_options(self):
arglist = [ arglist = [
identity_fakes.endpoint_id, self.endpoint.id,
] ]
verifylist = [ verifylist = [
('endpoint', identity_fakes.endpoint_id), ('endpoint', self.endpoint.id),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -493,7 +466,7 @@ class TestEndpointSet(TestEndpoint):
'url': None, 'url': None,
} }
self.endpoints_mock.update.assert_called_with( self.endpoints_mock.update.assert_called_with(
identity_fakes.endpoint_id, self.endpoint.id,
**kwargs **kwargs
) )
self.assertIsNone(result) self.assertIsNone(result)
@ -501,11 +474,11 @@ class TestEndpointSet(TestEndpoint):
def test_endpoint_set_interface(self): def test_endpoint_set_interface(self):
arglist = [ arglist = [
'--interface', 'public', '--interface', 'public',
identity_fakes.endpoint_id self.endpoint.id
] ]
verifylist = [ verifylist = [
('interface', 'public'), ('interface', 'public'),
('endpoint', identity_fakes.endpoint_id), ('endpoint', self.endpoint.id),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -520,7 +493,7 @@ class TestEndpointSet(TestEndpoint):
'service': None, 'service': None,
} }
self.endpoints_mock.update.assert_called_with( self.endpoints_mock.update.assert_called_with(
identity_fakes.endpoint_id, self.endpoint.id,
**kwargs **kwargs
) )
self.assertIsNone(result) self.assertIsNone(result)
@ -528,11 +501,11 @@ class TestEndpointSet(TestEndpoint):
def test_endpoint_set_url(self): def test_endpoint_set_url(self):
arglist = [ arglist = [
'--url', 'http://localhost:5000', '--url', 'http://localhost:5000',
identity_fakes.endpoint_id self.endpoint.id
] ]
verifylist = [ verifylist = [
('url', 'http://localhost:5000'), ('url', 'http://localhost:5000'),
('endpoint', identity_fakes.endpoint_id), ('endpoint', self.endpoint.id),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -547,19 +520,19 @@ class TestEndpointSet(TestEndpoint):
'service': None, 'service': None,
} }
self.endpoints_mock.update.assert_called_with( self.endpoints_mock.update.assert_called_with(
identity_fakes.endpoint_id, self.endpoint.id,
**kwargs **kwargs
) )
self.assertIsNone(result) self.assertIsNone(result)
def test_endpoint_set_service(self): def test_endpoint_set_service(self):
arglist = [ arglist = [
'--service', identity_fakes.service_id, '--service', self.service.id,
identity_fakes.endpoint_id self.endpoint.id
] ]
verifylist = [ verifylist = [
('service', identity_fakes.service_id), ('service', self.service.id),
('endpoint', identity_fakes.endpoint_id), ('endpoint', self.endpoint.id),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -571,10 +544,10 @@ class TestEndpointSet(TestEndpoint):
'interface': None, 'interface': None,
'url': None, 'url': None,
'region': None, 'region': None,
'service': identity_fakes.service_id, 'service': self.service.id,
} }
self.endpoints_mock.update.assert_called_with( self.endpoints_mock.update.assert_called_with(
identity_fakes.endpoint_id, self.endpoint.id,
**kwargs **kwargs
) )
self.assertIsNone(result) self.assertIsNone(result)
@ -582,11 +555,11 @@ class TestEndpointSet(TestEndpoint):
def test_endpoint_set_region(self): def test_endpoint_set_region(self):
arglist = [ arglist = [
'--region', 'e-rzzz', '--region', 'e-rzzz',
identity_fakes.endpoint_id self.endpoint.id
] ]
verifylist = [ verifylist = [
('region', 'e-rzzz'), ('region', 'e-rzzz'),
('endpoint', identity_fakes.endpoint_id), ('endpoint', self.endpoint.id),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -601,7 +574,7 @@ class TestEndpointSet(TestEndpoint):
'service': None, 'service': None,
} }
self.endpoints_mock.update.assert_called_with( self.endpoints_mock.update.assert_called_with(
identity_fakes.endpoint_id, self.endpoint.id,
**kwargs **kwargs
) )
self.assertIsNone(result) self.assertIsNone(result)
@ -609,11 +582,11 @@ class TestEndpointSet(TestEndpoint):
def test_endpoint_set_enable(self): def test_endpoint_set_enable(self):
arglist = [ arglist = [
'--enable', '--enable',
identity_fakes.endpoint_id self.endpoint.id
] ]
verifylist = [ verifylist = [
('enabled', True), ('enabled', True),
('endpoint', identity_fakes.endpoint_id), ('endpoint', self.endpoint.id),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -628,7 +601,7 @@ class TestEndpointSet(TestEndpoint):
'service': None, 'service': None,
} }
self.endpoints_mock.update.assert_called_with( self.endpoints_mock.update.assert_called_with(
identity_fakes.endpoint_id, self.endpoint.id,
**kwargs **kwargs
) )
self.assertIsNone(result) self.assertIsNone(result)
@ -636,11 +609,11 @@ class TestEndpointSet(TestEndpoint):
def test_endpoint_set_disable(self): def test_endpoint_set_disable(self):
arglist = [ arglist = [
'--disable', '--disable',
identity_fakes.endpoint_id self.endpoint.id
] ]
verifylist = [ verifylist = [
('disabled', True), ('disabled', True),
('endpoint', identity_fakes.endpoint_id), ('endpoint', self.endpoint.id),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -655,7 +628,7 @@ class TestEndpointSet(TestEndpoint):
'service': None, 'service': None,
} }
self.endpoints_mock.update.assert_called_with( self.endpoints_mock.update.assert_called_with(
identity_fakes.endpoint_id, self.endpoint.id,
**kwargs **kwargs
) )
self.assertIsNone(result) self.assertIsNone(result)
@ -663,31 +636,27 @@ class TestEndpointSet(TestEndpoint):
class TestEndpointShow(TestEndpoint): class TestEndpointShow(TestEndpoint):
service = identity_fakes.FakeService.create_one_service()
endpoint = identity_fakes.FakeEndpoint.create_one_endpoint(
attrs={'service_id': service.id})
def setUp(self): def setUp(self):
super(TestEndpointShow, self).setUp() super(TestEndpointShow, self).setUp()
self.endpoints_mock.get.return_value = fakes.FakeResource( self.endpoints_mock.get.return_value = self.endpoint
None,
copy.deepcopy(identity_fakes.ENDPOINT),
loaded=True,
)
# This is the return value for common.find_resource(service) # This is the return value for common.find_resource(service)
self.services_mock.get.return_value = fakes.FakeResource( self.services_mock.get.return_value = self.service
None,
copy.deepcopy(identity_fakes.SERVICE),
loaded=True,
)
# Get the command object to test # Get the command object to test
self.cmd = endpoint.ShowEndpoint(self.app, None) self.cmd = endpoint.ShowEndpoint(self.app, None)
def test_endpoint_show(self): def test_endpoint_show(self):
arglist = [ arglist = [
identity_fakes.endpoint_id, self.endpoint.id,
] ]
verifylist = [ verifylist = [
('endpoint', identity_fakes.endpoint_id), ('endpoint', self.endpoint.id),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -696,7 +665,7 @@ class TestEndpointShow(TestEndpoint):
# data to be shown. # data to be shown.
columns, data = self.cmd.take_action(parsed_args) columns, data = self.cmd.take_action(parsed_args)
self.endpoints_mock.get.assert_called_with( self.endpoints_mock.get.assert_called_with(
identity_fakes.endpoint_id, self.endpoint.id,
) )
collist = ( collist = (
@ -712,89 +681,70 @@ class TestEndpointShow(TestEndpoint):
self.assertEqual(collist, columns) self.assertEqual(collist, columns)
datalist = ( datalist = (
True, True,
identity_fakes.endpoint_id, self.endpoint.id,
identity_fakes.endpoint_interface, self.endpoint.interface,
identity_fakes.endpoint_region, self.endpoint.region,
identity_fakes.service_id, self.service.id,
self.get_fake_service_name(), self.service.name,
identity_fakes.service_type, self.service.type,
identity_fakes.endpoint_url, self.endpoint.url,
) )
self.assertEqual(datalist, data) self.assertEqual(datalist, data)
class TestEndpointCreateServiceWithoutName(TestEndpointCreate): class TestEndpointCreateServiceWithoutName(TestEndpointCreate):
service = identity_fakes.FakeService.create_one_service(
attrs={'service_name': ''})
def setUp(self): def setUp(self):
super(TestEndpointCreate, self).setUp() super(TestEndpointCreate, self).setUp()
self.endpoints_mock.create.return_value = fakes.FakeResource( self.endpoint = identity_fakes.FakeEndpoint.create_one_endpoint(
None, attrs={'service_id': self.service.id})
copy.deepcopy(identity_fakes.ENDPOINT),
loaded=True, self.endpoints_mock.create.return_value = self.endpoint
)
# This is the return value for common.find_resource(service) # This is the return value for common.find_resource(service)
self.services_mock.get.return_value = fakes.FakeResource( self.services_mock.get.return_value = self.service
None,
copy.deepcopy(identity_fakes.SERVICE_WITHOUT_NAME),
loaded=True,
)
# Get the command object to test # Get the command object to test
self.cmd = endpoint.CreateEndpoint(self.app, None) self.cmd = endpoint.CreateEndpoint(self.app, None)
def get_fake_service_name(self):
return ''
class TestEndpointListServiceWithoutName(TestEndpointList): class TestEndpointListServiceWithoutName(TestEndpointList):
service = identity_fakes.FakeService.create_one_service(
attrs={'service_name': ''})
endpoint = identity_fakes.FakeEndpoint.create_one_endpoint(
attrs={'service_id': service.id})
def setUp(self): def setUp(self):
super(TestEndpointList, self).setUp() super(TestEndpointList, self).setUp()
self.endpoints_mock.list.return_value = [ self.endpoints_mock.list.return_value = [self.endpoint]
fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.ENDPOINT),
loaded=True,
),
]
# This is the return value for common.find_resource(service) # This is the return value for common.find_resource(service)
self.services_mock.get.return_value = fakes.FakeResource( self.services_mock.get.return_value = self.service
None,
copy.deepcopy(identity_fakes.SERVICE_WITHOUT_NAME),
loaded=True,
)
# Get the command object to test # Get the command object to test
self.cmd = endpoint.ListEndpoint(self.app, None) self.cmd = endpoint.ListEndpoint(self.app, None)
def get_fake_service_name(self):
return ''
class TestEndpointShowServiceWithoutName(TestEndpointShow): class TestEndpointShowServiceWithoutName(TestEndpointShow):
service = identity_fakes.FakeService.create_one_service(
attrs={'service_name': ''})
endpoint = identity_fakes.FakeEndpoint.create_one_endpoint(
attrs={'service_id': service.id})
def setUp(self): def setUp(self):
super(TestEndpointShow, self).setUp() super(TestEndpointShow, self).setUp()
self.endpoints_mock.get.return_value = fakes.FakeResource( self.endpoints_mock.get.return_value = self.endpoint
None,
copy.deepcopy(identity_fakes.ENDPOINT),
loaded=True,
)
# This is the return value for common.find_resource(service) # This is the return value for common.find_resource(service)
self.services_mock.get.return_value = fakes.FakeResource( self.services_mock.get.return_value = self.service
None,
copy.deepcopy(identity_fakes.SERVICE_WITHOUT_NAME),
loaded=True,
)
# Get the command object to test # Get the command object to test
self.cmd = endpoint.ShowEndpoint(self.app, None) self.cmd = endpoint.ShowEndpoint(self.app, None)
def get_fake_service_name(self):
return ''

View File

@ -11,10 +11,7 @@
# under the License. # under the License.
# #
import copy
from openstackclient.identity.v3 import group from openstackclient.identity.v3 import group
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
@ -38,44 +35,30 @@ class TestGroup(identity_fakes.TestIdentityv3):
class TestGroupList(TestGroup): class TestGroupList(TestGroup):
domain = identity_fakes.FakeDomain.create_one_domain()
group = identity_fakes.FakeGroup.create_one_group()
user = identity_fakes.FakeUser.create_one_user()
columns = ( columns = (
'ID', 'ID',
'Name', 'Name',
) )
datalist = ( datalist = (
( (
identity_fakes.group_id, group.id,
identity_fakes.group_name, group.name,
), ),
) )
def setUp(self): def setUp(self):
super(TestGroupList, self).setUp() super(TestGroupList, self).setUp()
self.groups_mock.get.return_value = fakes.FakeResource( self.groups_mock.get.return_value = self.group
None, self.groups_mock.list.return_value = [self.group]
copy.deepcopy(identity_fakes.GROUP),
loaded=True,
)
self.groups_mock.list.return_value = [
fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.GROUP),
loaded=True,
),
]
self.domains_mock.get.return_value = fakes.FakeResource( self.domains_mock.get.return_value = self.domain
None,
copy.deepcopy(identity_fakes.DOMAIN),
loaded=True,
)
self.users_mock.get.return_value = fakes.FakeResource( self.users_mock.get.return_value = self.user
None,
copy.deepcopy(identity_fakes.USER),
loaded=True,
)
# Get the command object to test # Get the command object to test
self.cmd = group.ListGroup(self.app, None) self.cmd = group.ListGroup(self.app, None)
@ -105,10 +88,10 @@ class TestGroupList(TestGroup):
def test_group_list_domain(self): def test_group_list_domain(self):
arglist = [ arglist = [
'--domain', identity_fakes.domain_id, '--domain', self.domain.id,
] ]
verifylist = [ verifylist = [
('domain', identity_fakes.domain_id), ('domain', self.domain.id),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -119,7 +102,7 @@ class TestGroupList(TestGroup):
# Set expected values # Set expected values
kwargs = { kwargs = {
'domain': identity_fakes.domain_id, 'domain': self.domain.id,
'user': None, 'user': None,
} }
@ -132,10 +115,10 @@ class TestGroupList(TestGroup):
def test_group_list_user(self): def test_group_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),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -147,7 +130,7 @@ class TestGroupList(TestGroup):
# Set expected values # Set expected values
kwargs = { kwargs = {
'domain': None, 'domain': None,
'user': identity_fakes.user_id, 'user': self.user.id,
} }
self.groups_mock.list.assert_called_with( self.groups_mock.list.assert_called_with(
@ -186,10 +169,10 @@ class TestGroupList(TestGroup):
'Description', 'Description',
) )
datalist = (( datalist = ((
identity_fakes.group_id, self.group.id,
identity_fakes.group_name, self.group.name,
'', self.group.domain_id,
'', self.group.description,
), ) ), )
self.assertEqual(columns, columns) self.assertEqual(columns, columns)
self.assertEqual(datalist, tuple(data)) self.assertEqual(datalist, tuple(data))

View File

@ -13,13 +13,10 @@
# under the License. # under the License.
# #
import copy
from keystoneclient import exceptions as identity_exc from keystoneclient import exceptions as identity_exc
from osc_lib import exceptions from osc_lib import exceptions
from openstackclient.identity.v3 import service from openstackclient.identity.v3 import service
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
@ -42,37 +39,34 @@ class TestServiceCreate(TestService):
'name', 'name',
'type', 'type',
) )
datalist = (
identity_fakes.service_description,
True,
identity_fakes.service_id,
identity_fakes.service_name,
identity_fakes.service_type,
)
def setUp(self): def setUp(self):
super(TestServiceCreate, self).setUp() super(TestServiceCreate, self).setUp()
self.services_mock.create.return_value = fakes.FakeResource( self.service = identity_fakes.FakeService.create_one_service()
None, self.datalist = (
copy.deepcopy(identity_fakes.SERVICE), self.service.description,
loaded=True, True,
self.service.id,
self.service.name,
self.service.type,
) )
self.services_mock.create.return_value = self.service
# 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_name(self): def test_service_create_name(self):
arglist = [ arglist = [
'--name', identity_fakes.service_name, '--name', self.service.name,
identity_fakes.service_type, self.service.type,
] ]
verifylist = [ verifylist = [
('name', identity_fakes.service_name), ('name', self.service.name),
('description', None), ('description', None),
('enable', False), ('enable', False),
('disable', False), ('disable', False),
('type', identity_fakes.service_type), ('type', self.service.type),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -83,8 +77,8 @@ class TestServiceCreate(TestService):
# ServiceManager.create(name=, type=, enabled=, **kwargs) # ServiceManager.create(name=, type=, enabled=, **kwargs)
self.services_mock.create.assert_called_with( self.services_mock.create.assert_called_with(
name=identity_fakes.service_name, name=self.service.name,
type=identity_fakes.service_type, type=self.service.type,
description=None, description=None,
enabled=True, enabled=True,
) )
@ -94,15 +88,15 @@ class TestServiceCreate(TestService):
def test_service_create_description(self): def test_service_create_description(self):
arglist = [ arglist = [
'--description', identity_fakes.service_description, '--description', self.service.description,
identity_fakes.service_type, self.service.type,
] ]
verifylist = [ verifylist = [
('name', None), ('name', None),
('description', identity_fakes.service_description), ('description', self.service.description),
('enable', False), ('enable', False),
('disable', False), ('disable', False),
('type', identity_fakes.service_type), ('type', self.service.type),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -114,8 +108,8 @@ class TestServiceCreate(TestService):
# ServiceManager.create(name=, type=, enabled=, **kwargs) # ServiceManager.create(name=, type=, enabled=, **kwargs)
self.services_mock.create.assert_called_with( self.services_mock.create.assert_called_with(
name=None, name=None,
type=identity_fakes.service_type, type=self.service.type,
description=identity_fakes.service_description, description=self.service.description,
enabled=True, enabled=True,
) )
@ -125,14 +119,14 @@ class TestServiceCreate(TestService):
def test_service_create_enable(self): def test_service_create_enable(self):
arglist = [ arglist = [
'--enable', '--enable',
identity_fakes.service_type, self.service.type,
] ]
verifylist = [ verifylist = [
('name', None), ('name', None),
('description', None), ('description', None),
('enable', True), ('enable', True),
('disable', False), ('disable', False),
('type', identity_fakes.service_type), ('type', self.service.type),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -144,7 +138,7 @@ class TestServiceCreate(TestService):
# ServiceManager.create(name=, type=, enabled=, **kwargs) # ServiceManager.create(name=, type=, enabled=, **kwargs)
self.services_mock.create.assert_called_with( self.services_mock.create.assert_called_with(
name=None, name=None,
type=identity_fakes.service_type, type=self.service.type,
description=None, description=None,
enabled=True, enabled=True,
) )
@ -155,14 +149,14 @@ class TestServiceCreate(TestService):
def test_service_create_disable(self): def test_service_create_disable(self):
arglist = [ arglist = [
'--disable', '--disable',
identity_fakes.service_type, self.service.type,
] ]
verifylist = [ verifylist = [
('name', None), ('name', None),
('description', None), ('description', None),
('enable', False), ('enable', False),
('disable', True), ('disable', True),
('type', identity_fakes.service_type), ('type', self.service.type),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -174,7 +168,7 @@ class TestServiceCreate(TestService):
# ServiceManager.create(name=, type=, enabled=, **kwargs) # ServiceManager.create(name=, type=, enabled=, **kwargs)
self.services_mock.create.assert_called_with( self.services_mock.create.assert_called_with(
name=None, name=None,
type=identity_fakes.service_type, type=self.service.type,
description=None, description=None,
enabled=False, enabled=False,
) )
@ -185,15 +179,13 @@ class TestServiceCreate(TestService):
class TestServiceDelete(TestService): class TestServiceDelete(TestService):
service = identity_fakes.FakeService.create_one_service()
def setUp(self): def setUp(self):
super(TestServiceDelete, self).setUp() super(TestServiceDelete, self).setUp()
self.services_mock.get.side_effect = identity_exc.NotFound(None) self.services_mock.get.side_effect = identity_exc.NotFound(None)
self.services_mock.find.return_value = fakes.FakeResource( self.services_mock.find.return_value = self.service
None,
copy.deepcopy(identity_fakes.SERVICE),
loaded=True,
)
self.services_mock.delete.return_value = None self.services_mock.delete.return_value = None
# Get the command object to test # Get the command object to test
@ -201,33 +193,29 @@ class TestServiceDelete(TestService):
def test_service_delete_no_options(self): def test_service_delete_no_options(self):
arglist = [ arglist = [
identity_fakes.service_name, self.service.name,
] ]
verifylist = [ verifylist = [
('service', [identity_fakes.service_name]), ('service', [self.service.name]),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args) result = self.cmd.take_action(parsed_args)
self.services_mock.delete.assert_called_with( self.services_mock.delete.assert_called_with(
identity_fakes.service_id, self.service.id,
) )
self.assertIsNone(result) self.assertIsNone(result)
class TestServiceList(TestService): class TestServiceList(TestService):
service = identity_fakes.FakeService.create_one_service()
def setUp(self): def setUp(self):
super(TestServiceList, self).setUp() super(TestServiceList, self).setUp()
self.services_mock.list.return_value = [ self.services_mock.list.return_value = [self.service]
fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.SERVICE),
loaded=True,
),
]
# Get the command object to test # Get the command object to test
self.cmd = service.ListService(self.app, None) self.cmd = service.ListService(self.app, None)
@ -247,9 +235,9 @@ class TestServiceList(TestService):
collist = ('ID', 'Name', 'Type') collist = ('ID', 'Name', 'Type')
self.assertEqual(collist, columns) self.assertEqual(collist, columns)
datalist = (( datalist = ((
identity_fakes.service_id, self.service.id,
identity_fakes.service_name, self.service.name,
identity_fakes.service_type, self.service.type,
), ) ), )
self.assertEqual(datalist, tuple(data)) self.assertEqual(datalist, tuple(data))
@ -272,10 +260,10 @@ class TestServiceList(TestService):
collist = ('ID', 'Name', 'Type', 'Description', 'Enabled') collist = ('ID', 'Name', 'Type', 'Description', 'Enabled')
self.assertEqual(collist, columns) self.assertEqual(collist, columns)
datalist = (( datalist = ((
identity_fakes.service_id, self.service.id,
identity_fakes.service_name, self.service.name,
identity_fakes.service_type, self.service.type,
identity_fakes.service_description, self.service.description,
True, True,
), ) ), )
self.assertEqual(datalist, tuple(data)) self.assertEqual(datalist, tuple(data))
@ -283,27 +271,21 @@ class TestServiceList(TestService):
class TestServiceSet(TestService): class TestServiceSet(TestService):
service = identity_fakes.FakeService.create_one_service()
def setUp(self): def setUp(self):
super(TestServiceSet, self).setUp() super(TestServiceSet, self).setUp()
self.services_mock.get.side_effect = identity_exc.NotFound(None) self.services_mock.get.side_effect = identity_exc.NotFound(None)
self.services_mock.find.return_value = fakes.FakeResource( self.services_mock.find.return_value = self.service
None, self.services_mock.update.return_value = self.service
copy.deepcopy(identity_fakes.SERVICE),
loaded=True,
)
self.services_mock.update.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.SERVICE),
loaded=True,
)
# Get the command object to test # Get the command object to test
self.cmd = service.SetService(self.app, None) self.cmd = service.SetService(self.app, None)
def test_service_set_no_options(self): def test_service_set_no_options(self):
arglist = [ arglist = [
identity_fakes.service_name, self.service.name,
] ]
verifylist = [ verifylist = [
('type', None), ('type', None),
@ -311,7 +293,7 @@ class TestServiceSet(TestService):
('description', None), ('description', None),
('enable', False), ('enable', False),
('disable', False), ('disable', False),
('service', identity_fakes.service_name), ('service', self.service.name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -321,16 +303,16 @@ class TestServiceSet(TestService):
def test_service_set_type(self): def test_service_set_type(self):
arglist = [ arglist = [
'--type', identity_fakes.service_type, '--type', self.service.type,
identity_fakes.service_name, self.service.name,
] ]
verifylist = [ verifylist = [
('type', identity_fakes.service_type), ('type', self.service.type),
('name', None), ('name', None),
('description', None), ('description', None),
('enable', False), ('enable', False),
('disable', False), ('disable', False),
('service', identity_fakes.service_name), ('service', self.service.name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -338,27 +320,27 @@ class TestServiceSet(TestService):
# Set expected values # Set expected values
kwargs = { kwargs = {
'type': identity_fakes.service_type, 'type': self.service.type,
} }
# ServiceManager.update(service, name=, type=, enabled=, **kwargs) # ServiceManager.update(service, name=, type=, enabled=, **kwargs)
self.services_mock.update.assert_called_with( self.services_mock.update.assert_called_with(
identity_fakes.service_id, self.service.id,
**kwargs **kwargs
) )
self.assertIsNone(result) self.assertIsNone(result)
def test_service_set_name(self): def test_service_set_name(self):
arglist = [ arglist = [
'--name', identity_fakes.service_name, '--name', self.service.name,
identity_fakes.service_name, self.service.name,
] ]
verifylist = [ verifylist = [
('type', None), ('type', None),
('name', identity_fakes.service_name), ('name', self.service.name),
('description', None), ('description', None),
('enable', False), ('enable', False),
('disable', False), ('disable', False),
('service', identity_fakes.service_name), ('service', self.service.name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -366,27 +348,27 @@ class TestServiceSet(TestService):
# Set expected values # Set expected values
kwargs = { kwargs = {
'name': identity_fakes.service_name, 'name': self.service.name,
} }
# ServiceManager.update(service, name=, type=, enabled=, **kwargs) # ServiceManager.update(service, name=, type=, enabled=, **kwargs)
self.services_mock.update.assert_called_with( self.services_mock.update.assert_called_with(
identity_fakes.service_id, self.service.id,
**kwargs **kwargs
) )
self.assertIsNone(result) self.assertIsNone(result)
def test_service_set_description(self): def test_service_set_description(self):
arglist = [ arglist = [
'--description', identity_fakes.service_description, '--description', self.service.description,
identity_fakes.service_name, self.service.name,
] ]
verifylist = [ verifylist = [
('type', None), ('type', None),
('name', None), ('name', None),
('description', identity_fakes.service_description), ('description', self.service.description),
('enable', False), ('enable', False),
('disable', False), ('disable', False),
('service', identity_fakes.service_name), ('service', self.service.name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -394,11 +376,11 @@ class TestServiceSet(TestService):
# Set expected values # Set expected values
kwargs = { kwargs = {
'description': identity_fakes.service_description, 'description': self.service.description,
} }
# ServiceManager.update(service, name=, type=, enabled=, **kwargs) # ServiceManager.update(service, name=, type=, enabled=, **kwargs)
self.services_mock.update.assert_called_with( self.services_mock.update.assert_called_with(
identity_fakes.service_id, self.service.id,
**kwargs **kwargs
) )
self.assertIsNone(result) self.assertIsNone(result)
@ -406,7 +388,7 @@ class TestServiceSet(TestService):
def test_service_set_enable(self): def test_service_set_enable(self):
arglist = [ arglist = [
'--enable', '--enable',
identity_fakes.service_name, self.service.name,
] ]
verifylist = [ verifylist = [
('type', None), ('type', None),
@ -414,7 +396,7 @@ class TestServiceSet(TestService):
('description', None), ('description', None),
('enable', True), ('enable', True),
('disable', False), ('disable', False),
('service', identity_fakes.service_name), ('service', self.service.name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -426,7 +408,7 @@ class TestServiceSet(TestService):
} }
# ServiceManager.update(service, name=, type=, enabled=, **kwargs) # ServiceManager.update(service, name=, type=, enabled=, **kwargs)
self.services_mock.update.assert_called_with( self.services_mock.update.assert_called_with(
identity_fakes.service_id, self.service.id,
**kwargs **kwargs
) )
self.assertIsNone(result) self.assertIsNone(result)
@ -434,7 +416,7 @@ class TestServiceSet(TestService):
def test_service_set_disable(self): def test_service_set_disable(self):
arglist = [ arglist = [
'--disable', '--disable',
identity_fakes.service_name, self.service.name,
] ]
verifylist = [ verifylist = [
('type', None), ('type', None),
@ -442,7 +424,7 @@ class TestServiceSet(TestService):
('description', None), ('description', None),
('enable', False), ('enable', False),
('disable', True), ('disable', True),
('service', identity_fakes.service_name), ('service', self.service.name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -454,7 +436,7 @@ class TestServiceSet(TestService):
} }
# ServiceManager.update(service, name=, type=, enabled=, **kwargs) # ServiceManager.update(service, name=, type=, enabled=, **kwargs)
self.services_mock.update.assert_called_with( self.services_mock.update.assert_called_with(
identity_fakes.service_id, self.service.id,
**kwargs **kwargs
) )
self.assertIsNone(result) self.assertIsNone(result)
@ -462,25 +444,23 @@ class TestServiceSet(TestService):
class TestServiceShow(TestService): class TestServiceShow(TestService):
service = identity_fakes.FakeService.create_one_service()
def setUp(self): def setUp(self):
super(TestServiceShow, self).setUp() super(TestServiceShow, self).setUp()
self.services_mock.get.side_effect = identity_exc.NotFound(None) self.services_mock.get.side_effect = identity_exc.NotFound(None)
self.services_mock.find.return_value = fakes.FakeResource( self.services_mock.find.return_value = self.service
None,
copy.deepcopy(identity_fakes.SERVICE),
loaded=True,
)
# Get the command object to test # Get the command object to test
self.cmd = service.ShowService(self.app, None) self.cmd = service.ShowService(self.app, None)
def test_service_show(self): def test_service_show(self):
arglist = [ arglist = [
identity_fakes.service_name, self.service.name,
] ]
verifylist = [ verifylist = [
('service', identity_fakes.service_name), ('service', self.service.name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -491,17 +471,17 @@ class TestServiceShow(TestService):
# ServiceManager.get(id) # ServiceManager.get(id)
self.services_mock.find.assert_called_with( self.services_mock.find.assert_called_with(
name=identity_fakes.service_name name=self.service.name
) )
collist = ('description', 'enabled', 'id', 'name', 'type') collist = ('description', 'enabled', 'id', 'name', 'type')
self.assertEqual(collist, columns) self.assertEqual(collist, columns)
datalist = ( datalist = (
identity_fakes.service_description, self.service.description,
True, True,
identity_fakes.service_id, self.service.id,
identity_fakes.service_name, self.service.name,
identity_fakes.service_type, self.service.type,
) )
self.assertEqual(datalist, data) self.assertEqual(datalist, data)

View File

@ -14,11 +14,9 @@
# #
import contextlib import contextlib
import copy
import mock import mock
from openstackclient.identity.v3 import user from openstackclient.identity.v3 import user
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
@ -51,6 +49,9 @@ class TestUser(identity_fakes.TestIdentityv3):
class TestUserCreate(TestUser): class TestUserCreate(TestUser):
domain = identity_fakes.FakeDomain.create_one_domain()
project = identity_fakes.FakeProject.create_one_project()
columns = ( columns = (
'default_project_id', 'default_project_id',
'domain_id', 'domain_id',
@ -59,47 +60,38 @@ class TestUserCreate(TestUser):
'id', 'id',
'name', 'name',
) )
datalist = (
identity_fakes.project_id,
identity_fakes.domain_id,
identity_fakes.user_email,
True,
identity_fakes.user_id,
identity_fakes.user_name,
)
def setUp(self): def setUp(self):
super(TestUserCreate, self).setUp() super(TestUserCreate, self).setUp()
self.domains_mock.get.return_value = fakes.FakeResource( self.user = identity_fakes.FakeUser.create_one_user(
None, attrs={'domain_id': self.domain.id,
copy.deepcopy(identity_fakes.DOMAIN), 'default_project_id': self.project.id}
loaded=True, )
self.datalist = (
self.project.id,
self.domain.id,
self.user.email,
True,
self.user.id,
self.user.name,
) )
self.projects_mock.get.return_value = fakes.FakeResource( self.domains_mock.get.return_value = self.domain
None, self.projects_mock.get.return_value = self.project
copy.deepcopy(identity_fakes.PROJECT), self.users_mock.create.return_value = self.user
loaded=True,
)
self.users_mock.create.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.USER),
loaded=True,
)
# Get the command object to test # Get the command object to test
self.cmd = user.CreateUser(self.app, None) self.cmd = user.CreateUser(self.app, None)
def test_user_create_no_options(self): def test_user_create_no_options(self):
arglist = [ arglist = [
identity_fakes.user_name, self.user.name,
] ]
verifylist = [ verifylist = [
('enable', False), ('enable', False),
('disable', False), ('disable', False),
('name', identity_fakes.user_name), ('name', self.user.name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -110,7 +102,7 @@ class TestUserCreate(TestUser):
# Set expected values # Set expected values
kwargs = { kwargs = {
'name': identity_fakes.user_name, 'name': self.user.name,
'default_project': None, 'default_project': None,
'description': None, 'description': None,
'domain': None, 'domain': None,
@ -131,14 +123,14 @@ class TestUserCreate(TestUser):
def test_user_create_password(self): def test_user_create_password(self):
arglist = [ arglist = [
'--password', 'secret', '--password', 'secret',
identity_fakes.user_name, self.user.name,
] ]
verifylist = [ verifylist = [
('password', 'secret'), ('password', 'secret'),
('password_prompt', False), ('password_prompt', False),
('enable', False), ('enable', False),
('disable', False), ('disable', False),
('name', identity_fakes.user_name), ('name', self.user.name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -149,7 +141,7 @@ class TestUserCreate(TestUser):
# Set expected values # Set expected values
kwargs = { kwargs = {
'name': identity_fakes.user_name, 'name': self.user.name,
'default_project': None, 'default_project': None,
'description': None, 'description': None,
'domain': None, 'domain': None,
@ -168,14 +160,14 @@ class TestUserCreate(TestUser):
def test_user_create_password_prompt(self): def test_user_create_password_prompt(self):
arglist = [ arglist = [
'--password-prompt', '--password-prompt',
identity_fakes.user_name, self.user.name,
] ]
verifylist = [ verifylist = [
('password', None), ('password', None),
('password_prompt', True), ('password_prompt', True),
('enable', False), ('enable', False),
('disable', False), ('disable', False),
('name', identity_fakes.user_name), ('name', self.user.name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -189,7 +181,7 @@ class TestUserCreate(TestUser):
# Set expected values # Set expected values
kwargs = { kwargs = {
'name': identity_fakes.user_name, 'name': self.user.name,
'default_project': None, 'default_project': None,
'description': None, 'description': None,
'domain': None, 'domain': None,
@ -209,13 +201,13 @@ class TestUserCreate(TestUser):
def test_user_create_email(self): def test_user_create_email(self):
arglist = [ arglist = [
'--email', 'barney@example.com', '--email', 'barney@example.com',
identity_fakes.user_name, self.user.name,
] ]
verifylist = [ verifylist = [
('email', 'barney@example.com'), ('email', 'barney@example.com'),
('enable', False), ('enable', False),
('disable', False), ('disable', False),
('name', identity_fakes.user_name), ('name', self.user.name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -226,7 +218,7 @@ class TestUserCreate(TestUser):
# Set expected values # Set expected values
kwargs = { kwargs = {
'name': identity_fakes.user_name, 'name': self.user.name,
'default_project': None, 'default_project': None,
'description': None, 'description': None,
'domain': None, 'domain': None,
@ -244,30 +236,15 @@ class TestUserCreate(TestUser):
self.assertEqual(self.datalist, data) self.assertEqual(self.datalist, data)
def test_user_create_project(self): 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,
)
# Set up to return an updated user
USER_2 = copy.deepcopy(identity_fakes.USER)
USER_2['default_project_id'] = identity_fakes.PROJECT_2['id']
self.users_mock.create.return_value = fakes.FakeResource(
None,
USER_2,
loaded=True,
)
arglist = [ arglist = [
'--project', identity_fakes.PROJECT_2['name'], '--project', self.project.name,
identity_fakes.user_name, self.user.name,
] ]
verifylist = [ verifylist = [
('project', identity_fakes.PROJECT_2['name']), ('project', self.project.name),
('enable', False), ('enable', False),
('disable', False), ('disable', False),
('name', identity_fakes.user_name), ('name', self.user.name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -278,8 +255,8 @@ class TestUserCreate(TestUser):
# Set expected values # Set expected values
kwargs = { kwargs = {
'name': identity_fakes.user_name, 'name': self.user.name,
'default_project': identity_fakes.PROJECT_2['id'], 'default_project': self.project.id,
'description': None, 'description': None,
'domain': None, 'domain': None,
'email': None, 'email': None,
@ -294,42 +271,27 @@ class TestUserCreate(TestUser):
self.assertEqual(self.columns, columns) self.assertEqual(self.columns, columns)
datalist = ( datalist = (
identity_fakes.PROJECT_2['id'], self.project.id,
identity_fakes.domain_id, self.domain.id,
identity_fakes.user_email, self.user.email,
True, True,
identity_fakes.user_id, self.user.id,
identity_fakes.user_name, self.user.name,
) )
self.assertEqual(datalist, data) self.assertEqual(datalist, data)
def test_user_create_project_domain(self): def test_user_create_project_domain(self):
# Return the new project
self.projects_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.PROJECT_2),
loaded=True,
)
# Set up to return an updated user
USER_2 = copy.deepcopy(identity_fakes.USER)
USER_2['default_project_id'] = identity_fakes.PROJECT_2['id']
self.users_mock.create.return_value = fakes.FakeResource(
None,
USER_2,
loaded=True,
)
arglist = [ arglist = [
'--project', identity_fakes.PROJECT_2['name'], '--project', self.project.name,
'--project-domain', identity_fakes.PROJECT_2['domain_id'], '--project-domain', self.project.domain_id,
identity_fakes.user_name, self.user.name,
] ]
verifylist = [ verifylist = [
('project', identity_fakes.PROJECT_2['name']), ('project', self.project.name),
('project_domain', identity_fakes.PROJECT_2['domain_id']), ('project_domain', self.project.domain_id),
('enable', False), ('enable', False),
('disable', False), ('disable', False),
('name', identity_fakes.user_name), ('name', self.user.name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -340,8 +302,8 @@ class TestUserCreate(TestUser):
# Set expected values # Set expected values
kwargs = { kwargs = {
'name': identity_fakes.user_name, 'name': self.user.name,
'default_project': identity_fakes.PROJECT_2['id'], 'default_project': self.project.id,
'description': None, 'description': None,
'domain': None, 'domain': None,
'email': None, 'email': None,
@ -356,25 +318,25 @@ class TestUserCreate(TestUser):
self.assertEqual(self.columns, columns) self.assertEqual(self.columns, columns)
datalist = ( datalist = (
identity_fakes.PROJECT_2['id'], self.project.id,
identity_fakes.domain_id, self.domain.id,
identity_fakes.user_email, self.user.email,
True, True,
identity_fakes.user_id, self.user.id,
identity_fakes.user_name, self.user.name,
) )
self.assertEqual(datalist, data) self.assertEqual(datalist, data)
def test_user_create_domain(self): def test_user_create_domain(self):
arglist = [ arglist = [
'--domain', identity_fakes.domain_name, '--domain', self.domain.name,
identity_fakes.user_name, self.user.name,
] ]
verifylist = [ verifylist = [
('domain', identity_fakes.domain_name), ('domain', self.domain.name),
('enable', False), ('enable', False),
('disable', False), ('disable', False),
('name', identity_fakes.user_name), ('name', self.user.name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -385,10 +347,10 @@ class TestUserCreate(TestUser):
# Set expected values # Set expected values
kwargs = { kwargs = {
'name': identity_fakes.user_name, 'name': self.user.name,
'default_project': None, 'default_project': None,
'description': None, 'description': None,
'domain': identity_fakes.domain_id, 'domain': self.domain.id,
'email': None, 'email': None,
'enabled': True, 'enabled': True,
'password': None, 'password': None,
@ -405,12 +367,12 @@ class TestUserCreate(TestUser):
def test_user_create_enable(self): def test_user_create_enable(self):
arglist = [ arglist = [
'--enable', '--enable',
identity_fakes.user_name, self.user.name,
] ]
verifylist = [ verifylist = [
('enable', True), ('enable', True),
('disable', False), ('disable', False),
('name', identity_fakes.user_name), ('name', self.user.name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -421,7 +383,7 @@ class TestUserCreate(TestUser):
# Set expected values # Set expected values
kwargs = { kwargs = {
'name': identity_fakes.user_name, 'name': self.user.name,
'default_project': None, 'default_project': None,
'description': None, 'description': None,
'domain': None, 'domain': None,
@ -441,10 +403,10 @@ class TestUserCreate(TestUser):
def test_user_create_disable(self): def test_user_create_disable(self):
arglist = [ arglist = [
'--disable', '--disable',
identity_fakes.user_name, self.user.name,
] ]
verifylist = [ verifylist = [
('name', identity_fakes.user_name), ('name', self.user.name),
('enable', False), ('enable', False),
('disable', True), ('disable', True),
] ]
@ -457,7 +419,7 @@ class TestUserCreate(TestUser):
# Set expected values # Set expected values
kwargs = { kwargs = {
'name': identity_fakes.user_name, 'name': self.user.name,
'default_project': None, 'default_project': None,
'description': None, 'description': None,
'domain': None, 'domain': None,
@ -475,15 +437,13 @@ class TestUserCreate(TestUser):
class TestUserDelete(TestUser): class TestUserDelete(TestUser):
user = identity_fakes.FakeUser.create_one_user()
def setUp(self): def setUp(self):
super(TestUserDelete, self).setUp() super(TestUserDelete, self).setUp()
# This is the return value for utils.find_resource() # This is the return value for utils.find_resource()
self.users_mock.get.return_value = fakes.FakeResource( self.users_mock.get.return_value = self.user
None,
copy.deepcopy(identity_fakes.USER),
loaded=True,
)
self.users_mock.delete.return_value = None self.users_mock.delete.return_value = None
# Get the command object to test # Get the command object to test
@ -491,76 +451,54 @@ class TestUserDelete(TestUser):
def test_user_delete_no_options(self): def test_user_delete_no_options(self):
arglist = [ arglist = [
identity_fakes.user_id, self.user.id,
] ]
verifylist = [ verifylist = [
('users', [identity_fakes.user_id]), ('users', [self.user.id]),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args) result = self.cmd.take_action(parsed_args)
self.users_mock.delete.assert_called_with( self.users_mock.delete.assert_called_with(
identity_fakes.user_id, self.user.id,
) )
self.assertIsNone(result) self.assertIsNone(result)
class TestUserList(TestUser): class TestUserList(TestUser):
domain = identity_fakes.FakeDomain.create_one_domain()
project = identity_fakes.FakeProject.create_one_project()
user = identity_fakes.FakeUser.create_one_user(
attrs={'domain_id': domain.id,
'default_project_id': project.id}
)
group = identity_fakes.FakeGroup.create_one_group()
role_assignment = (
identity_fakes.FakeRoleAssignment.create_one_role_assignment(
attrs={'user': {'id': user.id}}))
columns = [ columns = [
'ID', 'ID',
'Name' 'Name'
] ]
datalist = ( datalist = (
( (
identity_fakes.user_id, user.id,
identity_fakes.user_name, user.name,
), ),
) )
def setUp(self): def setUp(self):
super(TestUserList, self).setUp() super(TestUserList, self).setUp()
self.users_mock.get.return_value = fakes.FakeResource( self.users_mock.get.return_value = self.user
None, self.users_mock.list.return_value = [self.user]
copy.deepcopy(identity_fakes.USER), self.domains_mock.get.return_value = self.domain
loaded=True, self.groups_mock.get.return_value = self.group
) self.projects_mock.get.return_value = self.project
self.users_mock.list.return_value = [ self.role_assignments_mock.list.return_value = [self.role_assignment]
fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.USER),
loaded=True,
),
]
self.domains_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.DOMAIN),
loaded=True,
)
self.groups_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.GROUP),
loaded=True,
)
self.projects_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.PROJECT),
loaded=True,
)
self.role_assignments_mock.list.return_value = [
fakes.FakeResource(
None,
copy.deepcopy(
identity_fakes.ASSIGNMENT_WITH_PROJECT_ID_AND_USER_ID),
loaded=True,
)
]
# Get the command object to test # Get the command object to test
self.cmd = user.ListUser(self.app, None) self.cmd = user.ListUser(self.app, None)
@ -590,10 +528,10 @@ class TestUserList(TestUser):
def test_user_list_domain(self): def test_user_list_domain(self):
arglist = [ arglist = [
'--domain', identity_fakes.domain_id, '--domain', self.domain.id,
] ]
verifylist = [ verifylist = [
('domain', identity_fakes.domain_id), ('domain', self.domain.id),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -604,7 +542,7 @@ class TestUserList(TestUser):
# Set expected values # Set expected values
kwargs = { kwargs = {
'domain': identity_fakes.domain_id, 'domain': self.domain.id,
'group': None, 'group': None,
} }
@ -617,10 +555,10 @@ class TestUserList(TestUser):
def test_user_list_group(self): def test_user_list_group(self):
arglist = [ arglist = [
'--group', identity_fakes.group_name, '--group', self.group.name,
] ]
verifylist = [ verifylist = [
('group', identity_fakes.group_name), ('group', self.group.name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -632,7 +570,7 @@ class TestUserList(TestUser):
# Set expected values # Set expected values
kwargs = { kwargs = {
'domain': None, 'domain': None,
'group': identity_fakes.group_id, 'group': self.group.id,
} }
self.users_mock.list.assert_called_with( self.users_mock.list.assert_called_with(
@ -678,12 +616,12 @@ class TestUserList(TestUser):
self.assertEqual(collist, columns) self.assertEqual(collist, columns)
datalist = ( datalist = (
( (
identity_fakes.user_id, self.user.id,
identity_fakes.user_name, self.user.name,
identity_fakes.project_id, self.project.id,
identity_fakes.domain_id, self.domain.id,
'', '',
identity_fakes.user_email, self.user.email,
True, True,
), ),
) )
@ -691,10 +629,10 @@ class TestUserList(TestUser):
def test_user_list_project(self): def test_user_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),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -704,11 +642,11 @@ class TestUserList(TestUser):
columns, data = self.cmd.take_action(parsed_args) columns, data = self.cmd.take_action(parsed_args)
kwargs = { kwargs = {
'project': identity_fakes.project_id, 'project': self.project.id,
} }
self.role_assignments_mock.list.assert_called_with(**kwargs) self.role_assignments_mock.list.assert_called_with(**kwargs)
self.users_mock.get.assert_called_with(identity_fakes.user_id) self.users_mock.get.assert_called_with(self.user.id)
self.assertEqual(self.columns, columns) self.assertEqual(self.columns, columns)
self.assertEqual(self.datalist, tuple(data)) self.assertEqual(self.datalist, tuple(data))
@ -716,32 +654,24 @@ class TestUserList(TestUser):
class TestUserSet(TestUser): class TestUserSet(TestUser):
project = identity_fakes.FakeProject.create_one_project()
user = identity_fakes.FakeUser.create_one_user(
attrs={'default_project_id': project.id}
)
def setUp(self): def setUp(self):
super(TestUserSet, self).setUp() super(TestUserSet, self).setUp()
self.projects_mock.get.return_value = fakes.FakeResource( self.projects_mock.get.return_value = self.project
None, self.users_mock.get.return_value = self.user
copy.deepcopy(identity_fakes.PROJECT), self.users_mock.update.return_value = self.user
loaded=True,
)
self.users_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.USER),
loaded=True,
)
self.users_mock.update.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.USER),
loaded=True,
)
# Get the command object to test # Get the command object to test
self.cmd = user.SetUser(self.app, None) self.cmd = user.SetUser(self.app, None)
def test_user_set_no_options(self): def test_user_set_no_options(self):
arglist = [ arglist = [
identity_fakes.user_name, self.user.name,
] ]
verifylist = [ verifylist = [
('name', None), ('name', None),
@ -750,7 +680,7 @@ class TestUserSet(TestUser):
('project', None), ('project', None),
('enable', False), ('enable', False),
('disable', False), ('disable', False),
('user', identity_fakes.user_name), ('user', self.user.name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -761,7 +691,7 @@ class TestUserSet(TestUser):
def test_user_set_name(self): def test_user_set_name(self):
arglist = [ arglist = [
'--name', 'qwerty', '--name', 'qwerty',
identity_fakes.user_name, self.user.name,
] ]
verifylist = [ verifylist = [
('name', 'qwerty'), ('name', 'qwerty'),
@ -770,7 +700,7 @@ class TestUserSet(TestUser):
('project', None), ('project', None),
('enable', False), ('enable', False),
('disable', False), ('disable', False),
('user', identity_fakes.user_name), ('user', self.user.name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -784,7 +714,7 @@ class TestUserSet(TestUser):
# UserManager.update(user, name=, domain=, project=, password=, # UserManager.update(user, name=, domain=, project=, password=,
# email=, description=, enabled=, default_project=) # email=, description=, enabled=, default_project=)
self.users_mock.update.assert_called_with( self.users_mock.update.assert_called_with(
identity_fakes.user_id, self.user.id,
**kwargs **kwargs
) )
self.assertIsNone(result) self.assertIsNone(result)
@ -792,7 +722,7 @@ class TestUserSet(TestUser):
def test_user_set_password(self): def test_user_set_password(self):
arglist = [ arglist = [
'--password', 'secret', '--password', 'secret',
identity_fakes.user_name, self.user.name,
] ]
verifylist = [ verifylist = [
('name', None), ('name', None),
@ -802,7 +732,7 @@ class TestUserSet(TestUser):
('project', None), ('project', None),
('enable', False), ('enable', False),
('disable', False), ('disable', False),
('user', identity_fakes.user_name), ('user', self.user.name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -816,7 +746,7 @@ class TestUserSet(TestUser):
# UserManager.update(user, name=, domain=, project=, password=, # UserManager.update(user, name=, domain=, project=, password=,
# email=, description=, enabled=, default_project=) # email=, description=, enabled=, default_project=)
self.users_mock.update.assert_called_with( self.users_mock.update.assert_called_with(
identity_fakes.user_id, self.user.id,
**kwargs **kwargs
) )
self.assertIsNone(result) self.assertIsNone(result)
@ -824,7 +754,7 @@ class TestUserSet(TestUser):
def test_user_set_password_prompt(self): def test_user_set_password_prompt(self):
arglist = [ arglist = [
'--password-prompt', '--password-prompt',
identity_fakes.user_name, self.user.name,
] ]
verifylist = [ verifylist = [
('name', None), ('name', None),
@ -834,7 +764,7 @@ class TestUserSet(TestUser):
('project', None), ('project', None),
('enable', False), ('enable', False),
('disable', False), ('disable', False),
('user', identity_fakes.user_name), ('user', self.user.name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -851,7 +781,7 @@ class TestUserSet(TestUser):
# UserManager.update(user, name=, domain=, project=, password=, # UserManager.update(user, name=, domain=, project=, password=,
# email=, description=, enabled=, default_project=) # email=, description=, enabled=, default_project=)
self.users_mock.update.assert_called_with( self.users_mock.update.assert_called_with(
identity_fakes.user_id, self.user.id,
**kwargs **kwargs
) )
self.assertIsNone(result) self.assertIsNone(result)
@ -859,7 +789,7 @@ class TestUserSet(TestUser):
def test_user_set_email(self): def test_user_set_email(self):
arglist = [ arglist = [
'--email', 'barney@example.com', '--email', 'barney@example.com',
identity_fakes.user_name, self.user.name,
] ]
verifylist = [ verifylist = [
('name', None), ('name', None),
@ -868,7 +798,7 @@ class TestUserSet(TestUser):
('project', None), ('project', None),
('enable', False), ('enable', False),
('disable', False), ('disable', False),
('user', identity_fakes.user_name), ('user', self.user.name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -882,24 +812,24 @@ class TestUserSet(TestUser):
# UserManager.update(user, name=, domain=, project=, password=, # UserManager.update(user, name=, domain=, project=, password=,
# email=, description=, enabled=, default_project=) # email=, description=, enabled=, default_project=)
self.users_mock.update.assert_called_with( self.users_mock.update.assert_called_with(
identity_fakes.user_id, self.user.id,
**kwargs **kwargs
) )
self.assertIsNone(result) self.assertIsNone(result)
def test_user_set_project(self): def test_user_set_project(self):
arglist = [ arglist = [
'--project', identity_fakes.project_id, '--project', self.project.id,
identity_fakes.user_name, self.user.name,
] ]
verifylist = [ verifylist = [
('name', None), ('name', None),
('password', None), ('password', None),
('email', None), ('email', None),
('project', identity_fakes.project_id), ('project', self.project.id),
('enable', False), ('enable', False),
('disable', False), ('disable', False),
('user', identity_fakes.user_name), ('user', self.user.name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -908,31 +838,31 @@ class TestUserSet(TestUser):
# Set expected values # Set expected values
kwargs = { kwargs = {
'enabled': True, 'enabled': True,
'default_project': identity_fakes.project_id, 'default_project': self.project.id,
} }
# UserManager.update(user, name=, domain=, project=, password=, # UserManager.update(user, name=, domain=, project=, password=,
# email=, description=, enabled=, default_project=) # email=, description=, enabled=, default_project=)
self.users_mock.update.assert_called_with( self.users_mock.update.assert_called_with(
identity_fakes.user_id, self.user.id,
**kwargs **kwargs
) )
self.assertIsNone(result) self.assertIsNone(result)
def test_user_set_project_domain(self): def test_user_set_project_domain(self):
arglist = [ arglist = [
'--project', identity_fakes.project_id, '--project', self.project.id,
'--project-domain', identity_fakes.domain_id, '--project-domain', self.project.domain_id,
identity_fakes.user_name, self.user.name,
] ]
verifylist = [ verifylist = [
('name', None), ('name', None),
('password', None), ('password', None),
('email', None), ('email', None),
('project', identity_fakes.project_id), ('project', self.project.id),
('project_domain', identity_fakes.domain_id), ('project_domain', self.project.domain_id),
('enable', False), ('enable', False),
('disable', False), ('disable', False),
('user', identity_fakes.user_name), ('user', self.user.name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -941,12 +871,12 @@ class TestUserSet(TestUser):
# Set expected values # Set expected values
kwargs = { kwargs = {
'enabled': True, 'enabled': True,
'default_project': identity_fakes.project_id, 'default_project': self.project.id,
} }
# UserManager.update(user, name=, domain=, project=, password=, # UserManager.update(user, name=, domain=, project=, password=,
# email=, description=, enabled=, default_project=) # email=, description=, enabled=, default_project=)
self.users_mock.update.assert_called_with( self.users_mock.update.assert_called_with(
identity_fakes.user_id, self.user.id,
**kwargs **kwargs
) )
self.assertIsNone(result) self.assertIsNone(result)
@ -954,7 +884,7 @@ class TestUserSet(TestUser):
def test_user_set_enable(self): def test_user_set_enable(self):
arglist = [ arglist = [
'--enable', '--enable',
identity_fakes.user_name, self.user.name,
] ]
verifylist = [ verifylist = [
('name', None), ('name', None),
@ -963,7 +893,7 @@ class TestUserSet(TestUser):
('project', None), ('project', None),
('enable', True), ('enable', True),
('disable', False), ('disable', False),
('user', identity_fakes.user_name), ('user', self.user.name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -976,7 +906,7 @@ class TestUserSet(TestUser):
# UserManager.update(user, name=, domain=, project=, password=, # UserManager.update(user, name=, domain=, project=, password=,
# email=, description=, enabled=, default_project=) # email=, description=, enabled=, default_project=)
self.users_mock.update.assert_called_with( self.users_mock.update.assert_called_with(
identity_fakes.user_id, self.user.id,
**kwargs **kwargs
) )
self.assertIsNone(result) self.assertIsNone(result)
@ -984,7 +914,7 @@ class TestUserSet(TestUser):
def test_user_set_disable(self): def test_user_set_disable(self):
arglist = [ arglist = [
'--disable', '--disable',
identity_fakes.user_name, self.user.name,
] ]
verifylist = [ verifylist = [
('name', None), ('name', None),
@ -993,7 +923,7 @@ class TestUserSet(TestUser):
('project', None), ('project', None),
('enable', False), ('enable', False),
('disable', True), ('disable', True),
('user', identity_fakes.user_name), ('user', self.user.name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -1006,7 +936,7 @@ class TestUserSet(TestUser):
# UserManager.update(user, name=, domain=, project=, password=, # UserManager.update(user, name=, domain=, project=, password=,
# email=, description=, enabled=, default_project=) # email=, description=, enabled=, default_project=)
self.users_mock.update.assert_called_with( self.users_mock.update.assert_called_with(
identity_fakes.user_id, self.user.id,
**kwargs **kwargs
) )
self.assertIsNone(result) self.assertIsNone(result)
@ -1082,35 +1012,33 @@ class TestUserSetPassword(TestUser):
class TestUserShow(TestUser): class TestUserShow(TestUser):
user = identity_fakes.FakeUser.create_one_user()
def setUp(self): def setUp(self):
super(TestUserShow, self).setUp() super(TestUserShow, self).setUp()
self.users_mock.get.return_value = fakes.FakeResource( self.users_mock.get.return_value = self.user
None,
copy.deepcopy(identity_fakes.USER),
loaded=True,
)
# Get the command object to test # Get the command object to test
self.cmd = user.ShowUser(self.app, None) self.cmd = user.ShowUser(self.app, None)
self.app.client_manager.identity.auth.client.get_user_id.\ self.app.client_manager.identity.auth.client.get_user_id.\
return_value = 'bbbbbbb-aaaa-aaaa-aaaa-bbbbbbbaaaa' return_value = self.user.id
self.app.client_manager.identity.tokens.get_token_data.return_value = \ self.app.client_manager.identity.tokens.get_token_data.return_value = \
{'token': {'token':
{'user': {'user':
{'domain': {}, {'domain': {},
'id': 'bbbbbbb-aaaa-aaaa-aaaa-bbbbbbbaaaa', 'id': self.user.id,
'name': 'bbbbbbb-aaaa-aaaa-aaaa-bbbbbbbaaaa' 'name': self.user.name,
} }
} }
} }
def test_user_show(self): def test_user_show(self):
arglist = [ arglist = [
identity_fakes.user_id, self.user.id,
] ]
verifylist = [ verifylist = [
('user', identity_fakes.user_id), ('user', self.user.id),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -1119,17 +1047,17 @@ class TestUserShow(TestUser):
# data to be shown. # data to be shown.
columns, data = self.cmd.take_action(parsed_args) 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.user.id)
collist = ('default_project_id', 'domain_id', 'email', collist = ('default_project_id', 'domain_id', 'email',
'enabled', 'id', 'name') 'enabled', 'id', 'name')
self.assertEqual(collist, columns) self.assertEqual(collist, columns)
datalist = ( datalist = (
identity_fakes.project_id, self.user.default_project_id,
identity_fakes.domain_id, self.user.domain_id,
identity_fakes.user_email, self.user.email,
True, True,
identity_fakes.user_id, self.user.id,
identity_fakes.user_name, self.user.name,
) )
self.assertEqual(datalist, data) self.assertEqual(datalist, data)