diff --git a/openstackclient/tests/identity/v3/fakes.py b/openstackclient/tests/identity/v3/fakes.py index bad15b6cde..50e901c983 100644 --- a/openstackclient/tests/identity/v3/fakes.py +++ b/openstackclient/tests/identity/v3/fakes.py @@ -730,7 +730,7 @@ class FakeUser(object): 'default_project_id': 'project-' + uuid.uuid4().hex, 'email': 'user-email-' + uuid.uuid4().hex, 'enabled': True, - 'domain_id': 'domain-id' + uuid.uuid4().hex, + 'domain_id': 'domain-id-' + uuid.uuid4().hex, 'links': 'links-' + uuid.uuid4().hex, } user_info.update(attrs) @@ -738,3 +738,125 @@ class FakeUser(object): user = fakes.FakeResource(info=copy.deepcopy(user_info), loaded=True) 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 diff --git a/openstackclient/tests/identity/v3/test_endpoint.py b/openstackclient/tests/identity/v3/test_endpoint.py index 042763199e..b2463a0d5e 100644 --- a/openstackclient/tests/identity/v3/test_endpoint.py +++ b/openstackclient/tests/identity/v3/test_endpoint.py @@ -10,11 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. - -import copy - from openstackclient.identity.v3 import endpoint -from openstackclient.tests import 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.reset_mock() - def get_fake_service_name(self): - return identity_fakes.service_name - class TestEndpointCreate(TestEndpoint): + service = identity_fakes.FakeService.create_one_service() + columns = ( 'enabled', 'id', @@ -51,33 +46,27 @@ class TestEndpointCreate(TestEndpoint): def setUp(self): super(TestEndpointCreate, self).setUp() - self.endpoints_mock.create.return_value = fakes.FakeResource( - None, - copy.deepcopy(identity_fakes.ENDPOINT), - loaded=True, - ) + self.endpoint = identity_fakes.FakeEndpoint.create_one_endpoint( + attrs={'service_id': self.service.id}) + self.endpoints_mock.create.return_value = self.endpoint # This is the return value for common.find_resource(service) - self.services_mock.get.return_value = fakes.FakeResource( - None, - copy.deepcopy(identity_fakes.SERVICE), - loaded=True, - ) + self.services_mock.get.return_value = self.service # Get the command object to test self.cmd = endpoint.CreateEndpoint(self.app, None) def test_endpoint_create_no_options(self): arglist = [ - identity_fakes.service_id, - identity_fakes.endpoint_interface, - identity_fakes.endpoint_url, + self.service.id, + self.endpoint.interface, + self.endpoint.url, ] verifylist = [ ('enabled', True), - ('service', identity_fakes.service_id), - ('interface', identity_fakes.endpoint_interface), - ('url', identity_fakes.endpoint_url), + ('service', self.service.id), + ('interface', self.endpoint.interface), + ('url', self.endpoint.url), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -88,9 +77,9 @@ class TestEndpointCreate(TestEndpoint): # Set expected values kwargs = { - 'service': identity_fakes.service_id, - 'url': identity_fakes.endpoint_url, - 'interface': identity_fakes.endpoint_interface, + 'service': self.service.id, + 'url': self.endpoint.url, + 'interface': self.endpoint.interface, 'enabled': True, 'region': None, } @@ -102,29 +91,29 @@ class TestEndpointCreate(TestEndpoint): self.assertEqual(self.columns, columns) datalist = ( True, - identity_fakes.endpoint_id, - identity_fakes.endpoint_interface, - identity_fakes.endpoint_region, - identity_fakes.service_id, - self.get_fake_service_name(), - identity_fakes.service_type, - identity_fakes.endpoint_url, + self.endpoint.id, + self.endpoint.interface, + self.endpoint.region, + self.service.id, + self.service.name, + self.service.type, + self.endpoint.url, ) self.assertEqual(datalist, data) def test_endpoint_create_region(self): arglist = [ - identity_fakes.service_id, - identity_fakes.endpoint_interface, - identity_fakes.endpoint_url, - '--region', identity_fakes.endpoint_region, + self.service.id, + self.endpoint.interface, + self.endpoint.url, + '--region', self.endpoint.region, ] verifylist = [ ('enabled', True), - ('service', identity_fakes.service_id), - ('interface', identity_fakes.endpoint_interface), - ('url', identity_fakes.endpoint_url), - ('region', identity_fakes.endpoint_region), + ('service', self.service.id), + ('interface', self.endpoint.interface), + ('url', self.endpoint.url), + ('region', self.endpoint.region), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -135,11 +124,11 @@ class TestEndpointCreate(TestEndpoint): # Set expected values kwargs = { - 'service': identity_fakes.service_id, - 'url': identity_fakes.endpoint_url, - 'interface': identity_fakes.endpoint_interface, + 'service': self.service.id, + 'url': self.endpoint.url, + 'interface': self.endpoint.interface, 'enabled': True, - 'region': identity_fakes.endpoint_region, + 'region': self.endpoint.region, } self.endpoints_mock.create.assert_called_with( @@ -149,28 +138,28 @@ class TestEndpointCreate(TestEndpoint): self.assertEqual(self.columns, columns) datalist = ( True, - identity_fakes.endpoint_id, - identity_fakes.endpoint_interface, - identity_fakes.endpoint_region, - identity_fakes.service_id, - self.get_fake_service_name(), - identity_fakes.service_type, - identity_fakes.endpoint_url, + self.endpoint.id, + self.endpoint.interface, + self.endpoint.region, + self.service.id, + self.service.name, + self.service.type, + self.endpoint.url, ) self.assertEqual(datalist, data) def test_endpoint_create_enable(self): arglist = [ - identity_fakes.service_id, - identity_fakes.endpoint_interface, - identity_fakes.endpoint_url, + self.service.id, + self.endpoint.interface, + self.endpoint.url, '--enable' ] verifylist = [ ('enabled', True), - ('service', identity_fakes.service_id), - ('interface', identity_fakes.endpoint_interface), - ('url', identity_fakes.endpoint_url), + ('service', self.service.id), + ('interface', self.endpoint.interface), + ('url', self.endpoint.url), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -181,9 +170,9 @@ class TestEndpointCreate(TestEndpoint): # Set expected values kwargs = { - 'service': identity_fakes.service_id, - 'url': identity_fakes.endpoint_url, - 'interface': identity_fakes.endpoint_interface, + 'service': self.service.id, + 'url': self.endpoint.url, + 'interface': self.endpoint.interface, 'enabled': True, 'region': None, } @@ -195,28 +184,28 @@ class TestEndpointCreate(TestEndpoint): self.assertEqual(self.columns, columns) datalist = ( True, - identity_fakes.endpoint_id, - identity_fakes.endpoint_interface, - identity_fakes.endpoint_region, - identity_fakes.service_id, - self.get_fake_service_name(), - identity_fakes.service_type, - identity_fakes.endpoint_url, + self.endpoint.id, + self.endpoint.interface, + self.endpoint.region, + self.service.id, + self.service.name, + self.service.type, + self.endpoint.url, ) self.assertEqual(datalist, data) def test_endpoint_create_disable(self): arglist = [ - identity_fakes.service_id, - identity_fakes.endpoint_interface, - identity_fakes.endpoint_url, + self.service.id, + self.endpoint.interface, + self.endpoint.url, '--disable', ] verifylist = [ ('enabled', False), - ('service', identity_fakes.service_id), - ('interface', identity_fakes.endpoint_interface), - ('url', identity_fakes.endpoint_url), + ('service', self.service.id), + ('interface', self.endpoint.interface), + ('url', self.endpoint.url), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -227,9 +216,9 @@ class TestEndpointCreate(TestEndpoint): # Set expected values kwargs = { - 'service': identity_fakes.service_id, - 'url': identity_fakes.endpoint_url, - 'interface': identity_fakes.endpoint_interface, + 'service': self.service.id, + 'url': self.endpoint.url, + 'interface': self.endpoint.interface, 'enabled': False, 'region': None, } @@ -241,28 +230,26 @@ class TestEndpointCreate(TestEndpoint): self.assertEqual(self.columns, columns) datalist = ( True, - identity_fakes.endpoint_id, - identity_fakes.endpoint_interface, - identity_fakes.endpoint_region, - identity_fakes.service_id, - self.get_fake_service_name(), - identity_fakes.service_type, - identity_fakes.endpoint_url, + self.endpoint.id, + self.endpoint.interface, + self.endpoint.region, + self.service.id, + self.service.name, + self.service.type, + self.endpoint.url, ) self.assertEqual(datalist, data) class TestEndpointDelete(TestEndpoint): + endpoint = identity_fakes.FakeEndpoint.create_one_endpoint() + def setUp(self): super(TestEndpointDelete, self).setUp() # This is the return value for utils.find_resource(endpoint) - self.endpoints_mock.get.return_value = fakes.FakeResource( - None, - copy.deepcopy(identity_fakes.ENDPOINT), - loaded=True, - ) + self.endpoints_mock.get.return_value = self.endpoint self.endpoints_mock.delete.return_value = None # Get the command object to test @@ -270,23 +257,27 @@ class TestEndpointDelete(TestEndpoint): def test_endpoint_delete(self): arglist = [ - identity_fakes.endpoint_id, + self.endpoint.id, ] verifylist = [ - ('endpoint', [identity_fakes.endpoint_id]), + ('endpoint', [self.endpoint.id]), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) self.endpoints_mock.delete.assert_called_with( - identity_fakes.endpoint_id, + self.endpoint.id, ) self.assertIsNone(result) class TestEndpointList(TestEndpoint): + service = identity_fakes.FakeService.create_one_service() + endpoint = identity_fakes.FakeEndpoint.create_one_endpoint( + attrs={'service_id': service.id}) + columns = ( 'ID', 'Region', @@ -300,20 +291,10 @@ class TestEndpointList(TestEndpoint): def setUp(self): super(TestEndpointList, self).setUp() - self.endpoints_mock.list.return_value = [ - fakes.FakeResource( - None, - copy.deepcopy(identity_fakes.ENDPOINT), - loaded=True, - ), - ] + self.endpoints_mock.list.return_value = [self.endpoint] # This is the return value for common.find_resource(service) - self.services_mock.get.return_value = fakes.FakeResource( - None, - copy.deepcopy(identity_fakes.SERVICE), - loaded=True, - ) + self.services_mock.get.return_value = self.service # Get the command object to test self.cmd = endpoint.ListEndpoint(self.app, None) @@ -332,23 +313,23 @@ class TestEndpointList(TestEndpoint): self.assertEqual(self.columns, columns) datalist = ( ( - identity_fakes.endpoint_id, - identity_fakes.endpoint_region, - self.get_fake_service_name(), - identity_fakes.service_type, + self.endpoint.id, + self.endpoint.region, + self.service.name, + self.service.type, True, - identity_fakes.endpoint_interface, - identity_fakes.endpoint_url, + self.endpoint.interface, + self.endpoint.url, ), ) self.assertEqual(datalist, tuple(data)) def test_endpoint_list_service(self): arglist = [ - '--service', identity_fakes.service_id, + '--service', self.service.id, ] verifylist = [ - ('service', identity_fakes.service_id), + ('service', self.service.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -359,30 +340,30 @@ class TestEndpointList(TestEndpoint): # Set expected values kwargs = { - 'service': identity_fakes.service_id, + 'service': self.service.id, } self.endpoints_mock.list.assert_called_with(**kwargs) self.assertEqual(self.columns, columns) datalist = ( ( - identity_fakes.endpoint_id, - identity_fakes.endpoint_region, - self.get_fake_service_name(), - identity_fakes.service_type, + self.endpoint.id, + self.endpoint.region, + self.service.name, + self.service.type, True, - identity_fakes.endpoint_interface, - identity_fakes.endpoint_url, + self.endpoint.interface, + self.endpoint.url, ), ) self.assertEqual(datalist, tuple(data)) def test_endpoint_list_interface(self): arglist = [ - '--interface', identity_fakes.endpoint_interface, + '--interface', self.endpoint.interface, ] verifylist = [ - ('interface', identity_fakes.endpoint_interface), + ('interface', self.endpoint.interface), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -393,30 +374,30 @@ class TestEndpointList(TestEndpoint): # Set expected values kwargs = { - 'interface': identity_fakes.endpoint_interface, + 'interface': self.endpoint.interface, } self.endpoints_mock.list.assert_called_with(**kwargs) self.assertEqual(self.columns, columns) datalist = ( ( - identity_fakes.endpoint_id, - identity_fakes.endpoint_region, - self.get_fake_service_name(), - identity_fakes.service_type, + self.endpoint.id, + self.endpoint.region, + self.service.name, + self.service.type, True, - identity_fakes.endpoint_interface, - identity_fakes.endpoint_url, + self.endpoint.interface, + self.endpoint.url, ), ) self.assertEqual(datalist, tuple(data)) def test_endpoint_list_region(self): arglist = [ - '--region', identity_fakes.endpoint_region, + '--region', self.endpoint.region, ] verifylist = [ - ('region', identity_fakes.endpoint_region), + ('region', self.endpoint.region), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -427,20 +408,20 @@ class TestEndpointList(TestEndpoint): # Set expected values kwargs = { - 'region': identity_fakes.endpoint_region, + 'region': self.endpoint.region, } self.endpoints_mock.list.assert_called_with(**kwargs) self.assertEqual(self.columns, columns) datalist = ( ( - identity_fakes.endpoint_id, - identity_fakes.endpoint_region, - self.get_fake_service_name(), - identity_fakes.service_type, + self.endpoint.id, + self.endpoint.region, + self.service.name, + self.service.type, True, - identity_fakes.endpoint_interface, - identity_fakes.endpoint_url, + self.endpoint.interface, + self.endpoint.url, ), ) self.assertEqual(datalist, tuple(data)) @@ -448,38 +429,30 @@ class TestEndpointList(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): super(TestEndpointSet, self).setUp() # This is the return value for utils.find_resource(endpoint) - self.endpoints_mock.get.return_value = fakes.FakeResource( - None, - copy.deepcopy(identity_fakes.ENDPOINT), - loaded=True, - ) + self.endpoints_mock.get.return_value = self.endpoint - self.endpoints_mock.update.return_value = fakes.FakeResource( - None, - copy.deepcopy(identity_fakes.ENDPOINT), - loaded=True, - ) + self.endpoints_mock.update.return_value = self.endpoint # This is the return value for common.find_resource(service) - self.services_mock.get.return_value = fakes.FakeResource( - None, - copy.deepcopy(identity_fakes.SERVICE), - loaded=True, - ) + self.services_mock.get.return_value = self.service # Get the command object to test self.cmd = endpoint.SetEndpoint(self.app, None) def test_endpoint_set_no_options(self): arglist = [ - identity_fakes.endpoint_id, + self.endpoint.id, ] verifylist = [ - ('endpoint', identity_fakes.endpoint_id), + ('endpoint', self.endpoint.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -493,7 +466,7 @@ class TestEndpointSet(TestEndpoint): 'url': None, } self.endpoints_mock.update.assert_called_with( - identity_fakes.endpoint_id, + self.endpoint.id, **kwargs ) self.assertIsNone(result) @@ -501,11 +474,11 @@ class TestEndpointSet(TestEndpoint): def test_endpoint_set_interface(self): arglist = [ '--interface', 'public', - identity_fakes.endpoint_id + self.endpoint.id ] verifylist = [ ('interface', 'public'), - ('endpoint', identity_fakes.endpoint_id), + ('endpoint', self.endpoint.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -520,7 +493,7 @@ class TestEndpointSet(TestEndpoint): 'service': None, } self.endpoints_mock.update.assert_called_with( - identity_fakes.endpoint_id, + self.endpoint.id, **kwargs ) self.assertIsNone(result) @@ -528,11 +501,11 @@ class TestEndpointSet(TestEndpoint): def test_endpoint_set_url(self): arglist = [ '--url', 'http://localhost:5000', - identity_fakes.endpoint_id + self.endpoint.id ] verifylist = [ ('url', 'http://localhost:5000'), - ('endpoint', identity_fakes.endpoint_id), + ('endpoint', self.endpoint.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -547,19 +520,19 @@ class TestEndpointSet(TestEndpoint): 'service': None, } self.endpoints_mock.update.assert_called_with( - identity_fakes.endpoint_id, + self.endpoint.id, **kwargs ) self.assertIsNone(result) def test_endpoint_set_service(self): arglist = [ - '--service', identity_fakes.service_id, - identity_fakes.endpoint_id + '--service', self.service.id, + self.endpoint.id ] verifylist = [ - ('service', identity_fakes.service_id), - ('endpoint', identity_fakes.endpoint_id), + ('service', self.service.id), + ('endpoint', self.endpoint.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -571,10 +544,10 @@ class TestEndpointSet(TestEndpoint): 'interface': None, 'url': None, 'region': None, - 'service': identity_fakes.service_id, + 'service': self.service.id, } self.endpoints_mock.update.assert_called_with( - identity_fakes.endpoint_id, + self.endpoint.id, **kwargs ) self.assertIsNone(result) @@ -582,11 +555,11 @@ class TestEndpointSet(TestEndpoint): def test_endpoint_set_region(self): arglist = [ '--region', 'e-rzzz', - identity_fakes.endpoint_id + self.endpoint.id ] verifylist = [ ('region', 'e-rzzz'), - ('endpoint', identity_fakes.endpoint_id), + ('endpoint', self.endpoint.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -601,7 +574,7 @@ class TestEndpointSet(TestEndpoint): 'service': None, } self.endpoints_mock.update.assert_called_with( - identity_fakes.endpoint_id, + self.endpoint.id, **kwargs ) self.assertIsNone(result) @@ -609,11 +582,11 @@ class TestEndpointSet(TestEndpoint): def test_endpoint_set_enable(self): arglist = [ '--enable', - identity_fakes.endpoint_id + self.endpoint.id ] verifylist = [ ('enabled', True), - ('endpoint', identity_fakes.endpoint_id), + ('endpoint', self.endpoint.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -628,7 +601,7 @@ class TestEndpointSet(TestEndpoint): 'service': None, } self.endpoints_mock.update.assert_called_with( - identity_fakes.endpoint_id, + self.endpoint.id, **kwargs ) self.assertIsNone(result) @@ -636,11 +609,11 @@ class TestEndpointSet(TestEndpoint): def test_endpoint_set_disable(self): arglist = [ '--disable', - identity_fakes.endpoint_id + self.endpoint.id ] verifylist = [ ('disabled', True), - ('endpoint', identity_fakes.endpoint_id), + ('endpoint', self.endpoint.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -655,7 +628,7 @@ class TestEndpointSet(TestEndpoint): 'service': None, } self.endpoints_mock.update.assert_called_with( - identity_fakes.endpoint_id, + self.endpoint.id, **kwargs ) self.assertIsNone(result) @@ -663,31 +636,27 @@ class TestEndpointSet(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): super(TestEndpointShow, self).setUp() - self.endpoints_mock.get.return_value = fakes.FakeResource( - None, - copy.deepcopy(identity_fakes.ENDPOINT), - loaded=True, - ) + self.endpoints_mock.get.return_value = self.endpoint # This is the return value for common.find_resource(service) - self.services_mock.get.return_value = fakes.FakeResource( - None, - copy.deepcopy(identity_fakes.SERVICE), - loaded=True, - ) + self.services_mock.get.return_value = self.service # Get the command object to test self.cmd = endpoint.ShowEndpoint(self.app, None) def test_endpoint_show(self): arglist = [ - identity_fakes.endpoint_id, + self.endpoint.id, ] verifylist = [ - ('endpoint', identity_fakes.endpoint_id), + ('endpoint', self.endpoint.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -696,7 +665,7 @@ class TestEndpointShow(TestEndpoint): # data to be shown. columns, data = self.cmd.take_action(parsed_args) self.endpoints_mock.get.assert_called_with( - identity_fakes.endpoint_id, + self.endpoint.id, ) collist = ( @@ -712,89 +681,70 @@ class TestEndpointShow(TestEndpoint): self.assertEqual(collist, columns) datalist = ( True, - identity_fakes.endpoint_id, - identity_fakes.endpoint_interface, - identity_fakes.endpoint_region, - identity_fakes.service_id, - self.get_fake_service_name(), - identity_fakes.service_type, - identity_fakes.endpoint_url, + self.endpoint.id, + self.endpoint.interface, + self.endpoint.region, + self.service.id, + self.service.name, + self.service.type, + self.endpoint.url, ) self.assertEqual(datalist, data) class TestEndpointCreateServiceWithoutName(TestEndpointCreate): + service = identity_fakes.FakeService.create_one_service( + attrs={'service_name': ''}) + def setUp(self): super(TestEndpointCreate, self).setUp() - self.endpoints_mock.create.return_value = fakes.FakeResource( - None, - copy.deepcopy(identity_fakes.ENDPOINT), - loaded=True, - ) + self.endpoint = identity_fakes.FakeEndpoint.create_one_endpoint( + attrs={'service_id': self.service.id}) + + self.endpoints_mock.create.return_value = self.endpoint # This is the return value for common.find_resource(service) - self.services_mock.get.return_value = fakes.FakeResource( - None, - copy.deepcopy(identity_fakes.SERVICE_WITHOUT_NAME), - loaded=True, - ) + self.services_mock.get.return_value = self.service # Get the command object to test self.cmd = endpoint.CreateEndpoint(self.app, None) - def get_fake_service_name(self): - return '' - 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): super(TestEndpointList, self).setUp() - self.endpoints_mock.list.return_value = [ - fakes.FakeResource( - None, - copy.deepcopy(identity_fakes.ENDPOINT), - loaded=True, - ), - ] + self.endpoints_mock.list.return_value = [self.endpoint] # This is the return value for common.find_resource(service) - self.services_mock.get.return_value = fakes.FakeResource( - None, - copy.deepcopy(identity_fakes.SERVICE_WITHOUT_NAME), - loaded=True, - ) + self.services_mock.get.return_value = self.service # Get the command object to test self.cmd = endpoint.ListEndpoint(self.app, None) - def get_fake_service_name(self): - return '' - 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): super(TestEndpointShow, self).setUp() - self.endpoints_mock.get.return_value = fakes.FakeResource( - None, - copy.deepcopy(identity_fakes.ENDPOINT), - loaded=True, - ) + self.endpoints_mock.get.return_value = self.endpoint # This is the return value for common.find_resource(service) - self.services_mock.get.return_value = fakes.FakeResource( - None, - copy.deepcopy(identity_fakes.SERVICE_WITHOUT_NAME), - loaded=True, - ) + self.services_mock.get.return_value = self.service # Get the command object to test self.cmd = endpoint.ShowEndpoint(self.app, None) - - def get_fake_service_name(self): - return '' diff --git a/openstackclient/tests/identity/v3/test_group.py b/openstackclient/tests/identity/v3/test_group.py index c5f5dbca7b..112008d35e 100644 --- a/openstackclient/tests/identity/v3/test_group.py +++ b/openstackclient/tests/identity/v3/test_group.py @@ -11,10 +11,7 @@ # under the License. # -import copy - from openstackclient.identity.v3 import group -from openstackclient.tests import fakes from openstackclient.tests.identity.v3 import fakes as identity_fakes @@ -38,44 +35,30 @@ class TestGroup(identity_fakes.TestIdentityv3): 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 = ( 'ID', 'Name', ) datalist = ( ( - identity_fakes.group_id, - identity_fakes.group_name, + group.id, + group.name, ), ) def setUp(self): super(TestGroupList, self).setUp() - self.groups_mock.get.return_value = fakes.FakeResource( - None, - copy.deepcopy(identity_fakes.GROUP), - loaded=True, - ) - self.groups_mock.list.return_value = [ - fakes.FakeResource( - None, - copy.deepcopy(identity_fakes.GROUP), - loaded=True, - ), - ] + self.groups_mock.get.return_value = self.group + self.groups_mock.list.return_value = [self.group] - self.domains_mock.get.return_value = fakes.FakeResource( - None, - copy.deepcopy(identity_fakes.DOMAIN), - loaded=True, - ) + self.domains_mock.get.return_value = self.domain - self.users_mock.get.return_value = fakes.FakeResource( - None, - copy.deepcopy(identity_fakes.USER), - loaded=True, - ) + self.users_mock.get.return_value = self.user # Get the command object to test self.cmd = group.ListGroup(self.app, None) @@ -105,10 +88,10 @@ class TestGroupList(TestGroup): def test_group_list_domain(self): arglist = [ - '--domain', identity_fakes.domain_id, + '--domain', self.domain.id, ] verifylist = [ - ('domain', identity_fakes.domain_id), + ('domain', self.domain.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -119,7 +102,7 @@ class TestGroupList(TestGroup): # Set expected values kwargs = { - 'domain': identity_fakes.domain_id, + 'domain': self.domain.id, 'user': None, } @@ -132,10 +115,10 @@ class TestGroupList(TestGroup): def test_group_list_user(self): arglist = [ - '--user', identity_fakes.user_name, + '--user', self.user.name, ] verifylist = [ - ('user', identity_fakes.user_name), + ('user', self.user.name), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -147,7 +130,7 @@ class TestGroupList(TestGroup): # Set expected values kwargs = { 'domain': None, - 'user': identity_fakes.user_id, + 'user': self.user.id, } self.groups_mock.list.assert_called_with( @@ -186,10 +169,10 @@ class TestGroupList(TestGroup): 'Description', ) datalist = (( - identity_fakes.group_id, - identity_fakes.group_name, - '', - '', + self.group.id, + self.group.name, + self.group.domain_id, + self.group.description, ), ) self.assertEqual(columns, columns) self.assertEqual(datalist, tuple(data)) diff --git a/openstackclient/tests/identity/v3/test_service.py b/openstackclient/tests/identity/v3/test_service.py index 65d8ebd7de..76c66aa5e1 100644 --- a/openstackclient/tests/identity/v3/test_service.py +++ b/openstackclient/tests/identity/v3/test_service.py @@ -13,13 +13,10 @@ # under the License. # -import copy - from keystoneclient import exceptions as identity_exc from osc_lib import exceptions from openstackclient.identity.v3 import service -from openstackclient.tests import fakes from openstackclient.tests.identity.v3 import fakes as identity_fakes @@ -42,37 +39,34 @@ class TestServiceCreate(TestService): 'name', 'type', ) - datalist = ( - identity_fakes.service_description, - True, - identity_fakes.service_id, - identity_fakes.service_name, - identity_fakes.service_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.service = identity_fakes.FakeService.create_one_service() + self.datalist = ( + self.service.description, + True, + self.service.id, + self.service.name, + self.service.type, ) + self.services_mock.create.return_value = self.service # Get the command object to test self.cmd = service.CreateService(self.app, None) def test_service_create_name(self): arglist = [ - '--name', identity_fakes.service_name, - identity_fakes.service_type, + '--name', self.service.name, + self.service.type, ] verifylist = [ - ('name', identity_fakes.service_name), + ('name', self.service.name), ('description', None), ('enable', False), ('disable', False), - ('type', identity_fakes.service_type), + ('type', self.service.type), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -83,8 +77,8 @@ class TestServiceCreate(TestService): # ServiceManager.create(name=, type=, enabled=, **kwargs) self.services_mock.create.assert_called_with( - name=identity_fakes.service_name, - type=identity_fakes.service_type, + name=self.service.name, + type=self.service.type, description=None, enabled=True, ) @@ -94,15 +88,15 @@ class TestServiceCreate(TestService): def test_service_create_description(self): arglist = [ - '--description', identity_fakes.service_description, - identity_fakes.service_type, + '--description', self.service.description, + self.service.type, ] verifylist = [ ('name', None), - ('description', identity_fakes.service_description), + ('description', self.service.description), ('enable', False), ('disable', False), - ('type', identity_fakes.service_type), + ('type', self.service.type), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -114,8 +108,8 @@ class TestServiceCreate(TestService): # ServiceManager.create(name=, type=, enabled=, **kwargs) self.services_mock.create.assert_called_with( name=None, - type=identity_fakes.service_type, - description=identity_fakes.service_description, + type=self.service.type, + description=self.service.description, enabled=True, ) @@ -125,14 +119,14 @@ class TestServiceCreate(TestService): def test_service_create_enable(self): arglist = [ '--enable', - identity_fakes.service_type, + self.service.type, ] verifylist = [ ('name', None), ('description', None), ('enable', True), ('disable', False), - ('type', identity_fakes.service_type), + ('type', self.service.type), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -144,7 +138,7 @@ class TestServiceCreate(TestService): # ServiceManager.create(name=, type=, enabled=, **kwargs) self.services_mock.create.assert_called_with( name=None, - type=identity_fakes.service_type, + type=self.service.type, description=None, enabled=True, ) @@ -155,14 +149,14 @@ class TestServiceCreate(TestService): def test_service_create_disable(self): arglist = [ '--disable', - identity_fakes.service_type, + self.service.type, ] verifylist = [ ('name', None), ('description', None), ('enable', False), ('disable', True), - ('type', identity_fakes.service_type), + ('type', self.service.type), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -174,7 +168,7 @@ class TestServiceCreate(TestService): # ServiceManager.create(name=, type=, enabled=, **kwargs) self.services_mock.create.assert_called_with( name=None, - type=identity_fakes.service_type, + type=self.service.type, description=None, enabled=False, ) @@ -185,15 +179,13 @@ class TestServiceCreate(TestService): class TestServiceDelete(TestService): + service = identity_fakes.FakeService.create_one_service() + def setUp(self): super(TestServiceDelete, self).setUp() self.services_mock.get.side_effect = identity_exc.NotFound(None) - self.services_mock.find.return_value = fakes.FakeResource( - None, - copy.deepcopy(identity_fakes.SERVICE), - loaded=True, - ) + self.services_mock.find.return_value = self.service self.services_mock.delete.return_value = None # Get the command object to test @@ -201,33 +193,29 @@ class TestServiceDelete(TestService): def test_service_delete_no_options(self): arglist = [ - identity_fakes.service_name, + self.service.name, ] verifylist = [ - ('service', [identity_fakes.service_name]), + ('service', [self.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.service.id, ) self.assertIsNone(result) class TestServiceList(TestService): + service = identity_fakes.FakeService.create_one_service() + 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.service] # Get the command object to test self.cmd = service.ListService(self.app, None) @@ -247,9 +235,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.service.id, + self.service.name, + self.service.type, ), ) self.assertEqual(datalist, tuple(data)) @@ -272,10 +260,10 @@ class TestServiceList(TestService): collist = ('ID', 'Name', 'Type', 'Description', 'Enabled') self.assertEqual(collist, columns) datalist = (( - identity_fakes.service_id, - identity_fakes.service_name, - identity_fakes.service_type, - identity_fakes.service_description, + self.service.id, + self.service.name, + self.service.type, + self.service.description, True, ), ) self.assertEqual(datalist, tuple(data)) @@ -283,27 +271,21 @@ class TestServiceList(TestService): class TestServiceSet(TestService): + service = identity_fakes.FakeService.create_one_service() + def setUp(self): super(TestServiceSet, self).setUp() self.services_mock.get.side_effect = identity_exc.NotFound(None) - self.services_mock.find.return_value = fakes.FakeResource( - None, - copy.deepcopy(identity_fakes.SERVICE), - loaded=True, - ) - self.services_mock.update.return_value = fakes.FakeResource( - None, - copy.deepcopy(identity_fakes.SERVICE), - loaded=True, - ) + self.services_mock.find.return_value = self.service + self.services_mock.update.return_value = self.service # Get the command object to test self.cmd = service.SetService(self.app, None) def test_service_set_no_options(self): arglist = [ - identity_fakes.service_name, + self.service.name, ] verifylist = [ ('type', None), @@ -311,7 +293,7 @@ class TestServiceSet(TestService): ('description', None), ('enable', False), ('disable', False), - ('service', identity_fakes.service_name), + ('service', self.service.name), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -321,16 +303,16 @@ class TestServiceSet(TestService): def test_service_set_type(self): arglist = [ - '--type', identity_fakes.service_type, - identity_fakes.service_name, + '--type', self.service.type, + self.service.name, ] verifylist = [ - ('type', identity_fakes.service_type), + ('type', self.service.type), ('name', None), ('description', None), ('enable', False), ('disable', False), - ('service', identity_fakes.service_name), + ('service', self.service.name), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -338,27 +320,27 @@ class TestServiceSet(TestService): # Set expected values kwargs = { - 'type': identity_fakes.service_type, + 'type': self.service.type, } # ServiceManager.update(service, name=, type=, enabled=, **kwargs) self.services_mock.update.assert_called_with( - identity_fakes.service_id, + self.service.id, **kwargs ) self.assertIsNone(result) def test_service_set_name(self): arglist = [ - '--name', identity_fakes.service_name, - identity_fakes.service_name, + '--name', self.service.name, + self.service.name, ] verifylist = [ ('type', None), - ('name', identity_fakes.service_name), + ('name', self.service.name), ('description', None), ('enable', False), ('disable', False), - ('service', identity_fakes.service_name), + ('service', self.service.name), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -366,27 +348,27 @@ class TestServiceSet(TestService): # Set expected values kwargs = { - 'name': identity_fakes.service_name, + 'name': self.service.name, } # ServiceManager.update(service, name=, type=, enabled=, **kwargs) self.services_mock.update.assert_called_with( - identity_fakes.service_id, + self.service.id, **kwargs ) self.assertIsNone(result) def test_service_set_description(self): arglist = [ - '--description', identity_fakes.service_description, - identity_fakes.service_name, + '--description', self.service.description, + self.service.name, ] verifylist = [ ('type', None), ('name', None), - ('description', identity_fakes.service_description), + ('description', self.service.description), ('enable', False), ('disable', False), - ('service', identity_fakes.service_name), + ('service', self.service.name), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -394,11 +376,11 @@ class TestServiceSet(TestService): # Set expected values kwargs = { - 'description': identity_fakes.service_description, + 'description': self.service.description, } # ServiceManager.update(service, name=, type=, enabled=, **kwargs) self.services_mock.update.assert_called_with( - identity_fakes.service_id, + self.service.id, **kwargs ) self.assertIsNone(result) @@ -406,7 +388,7 @@ class TestServiceSet(TestService): def test_service_set_enable(self): arglist = [ '--enable', - identity_fakes.service_name, + self.service.name, ] verifylist = [ ('type', None), @@ -414,7 +396,7 @@ class TestServiceSet(TestService): ('description', None), ('enable', True), ('disable', False), - ('service', identity_fakes.service_name), + ('service', self.service.name), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -426,7 +408,7 @@ class TestServiceSet(TestService): } # ServiceManager.update(service, name=, type=, enabled=, **kwargs) self.services_mock.update.assert_called_with( - identity_fakes.service_id, + self.service.id, **kwargs ) self.assertIsNone(result) @@ -434,7 +416,7 @@ class TestServiceSet(TestService): def test_service_set_disable(self): arglist = [ '--disable', - identity_fakes.service_name, + self.service.name, ] verifylist = [ ('type', None), @@ -442,7 +424,7 @@ class TestServiceSet(TestService): ('description', None), ('enable', False), ('disable', True), - ('service', identity_fakes.service_name), + ('service', self.service.name), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -454,7 +436,7 @@ class TestServiceSet(TestService): } # ServiceManager.update(service, name=, type=, enabled=, **kwargs) self.services_mock.update.assert_called_with( - identity_fakes.service_id, + self.service.id, **kwargs ) self.assertIsNone(result) @@ -462,25 +444,23 @@ class TestServiceSet(TestService): class TestServiceShow(TestService): + service = identity_fakes.FakeService.create_one_service() + def setUp(self): super(TestServiceShow, self).setUp() self.services_mock.get.side_effect = identity_exc.NotFound(None) - self.services_mock.find.return_value = fakes.FakeResource( - None, - copy.deepcopy(identity_fakes.SERVICE), - loaded=True, - ) + self.services_mock.find.return_value = self.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.service.name, ] verifylist = [ - ('service', identity_fakes.service_name), + ('service', self.service.name), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -491,17 +471,17 @@ class TestServiceShow(TestService): # ServiceManager.get(id) self.services_mock.find.assert_called_with( - name=identity_fakes.service_name + name=self.service.name ) collist = ('description', 'enabled', 'id', 'name', 'type') self.assertEqual(collist, columns) datalist = ( - identity_fakes.service_description, + self.service.description, True, - identity_fakes.service_id, - identity_fakes.service_name, - identity_fakes.service_type, + self.service.id, + self.service.name, + self.service.type, ) self.assertEqual(datalist, data) diff --git a/openstackclient/tests/identity/v3/test_user.py b/openstackclient/tests/identity/v3/test_user.py index 7b99a4cbbc..c3d9e749df 100644 --- a/openstackclient/tests/identity/v3/test_user.py +++ b/openstackclient/tests/identity/v3/test_user.py @@ -14,11 +14,9 @@ # import contextlib -import copy import mock from openstackclient.identity.v3 import user -from openstackclient.tests import fakes from openstackclient.tests.identity.v3 import fakes as identity_fakes @@ -51,6 +49,9 @@ class TestUser(identity_fakes.TestIdentityv3): class TestUserCreate(TestUser): + domain = identity_fakes.FakeDomain.create_one_domain() + project = identity_fakes.FakeProject.create_one_project() + columns = ( 'default_project_id', 'domain_id', @@ -59,47 +60,38 @@ class TestUserCreate(TestUser): 'id', '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): super(TestUserCreate, self).setUp() - self.domains_mock.get.return_value = fakes.FakeResource( - None, - copy.deepcopy(identity_fakes.DOMAIN), - loaded=True, + self.user = identity_fakes.FakeUser.create_one_user( + attrs={'domain_id': self.domain.id, + 'default_project_id': self.project.id} + ) + 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( - None, - copy.deepcopy(identity_fakes.PROJECT), - loaded=True, - ) - - self.users_mock.create.return_value = fakes.FakeResource( - None, - copy.deepcopy(identity_fakes.USER), - loaded=True, - ) + self.domains_mock.get.return_value = self.domain + self.projects_mock.get.return_value = self.project + self.users_mock.create.return_value = self.user # 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.user.name, ] verifylist = [ ('enable', False), ('disable', False), - ('name', identity_fakes.user_name), + ('name', self.user.name), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -110,7 +102,7 @@ class TestUserCreate(TestUser): # Set expected values kwargs = { - 'name': identity_fakes.user_name, + 'name': self.user.name, 'default_project': None, 'description': None, 'domain': None, @@ -131,14 +123,14 @@ class TestUserCreate(TestUser): def test_user_create_password(self): arglist = [ '--password', 'secret', - identity_fakes.user_name, + self.user.name, ] verifylist = [ ('password', 'secret'), ('password_prompt', False), ('enable', False), ('disable', False), - ('name', identity_fakes.user_name), + ('name', self.user.name), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -149,7 +141,7 @@ class TestUserCreate(TestUser): # Set expected values kwargs = { - 'name': identity_fakes.user_name, + 'name': self.user.name, 'default_project': None, 'description': None, 'domain': None, @@ -168,14 +160,14 @@ class TestUserCreate(TestUser): def test_user_create_password_prompt(self): arglist = [ '--password-prompt', - identity_fakes.user_name, + self.user.name, ] verifylist = [ ('password', None), ('password_prompt', True), ('enable', False), ('disable', False), - ('name', identity_fakes.user_name), + ('name', self.user.name), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -189,7 +181,7 @@ class TestUserCreate(TestUser): # Set expected values kwargs = { - 'name': identity_fakes.user_name, + 'name': self.user.name, 'default_project': None, 'description': None, 'domain': None, @@ -209,13 +201,13 @@ class TestUserCreate(TestUser): def test_user_create_email(self): arglist = [ '--email', 'barney@example.com', - identity_fakes.user_name, + self.user.name, ] verifylist = [ ('email', 'barney@example.com'), ('enable', False), ('disable', False), - ('name', identity_fakes.user_name), + ('name', self.user.name), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -226,7 +218,7 @@ class TestUserCreate(TestUser): # Set expected values kwargs = { - 'name': identity_fakes.user_name, + 'name': self.user.name, 'default_project': None, 'description': None, 'domain': None, @@ -244,30 +236,15 @@ class TestUserCreate(TestUser): self.assertEqual(self.datalist, data) 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 = [ - '--project', identity_fakes.PROJECT_2['name'], - identity_fakes.user_name, + '--project', self.project.name, + self.user.name, ] verifylist = [ - ('project', identity_fakes.PROJECT_2['name']), + ('project', self.project.name), ('enable', False), ('disable', False), - ('name', identity_fakes.user_name), + ('name', self.user.name), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -278,8 +255,8 @@ class TestUserCreate(TestUser): # Set expected values kwargs = { - 'name': identity_fakes.user_name, - 'default_project': identity_fakes.PROJECT_2['id'], + 'name': self.user.name, + 'default_project': self.project.id, 'description': None, 'domain': None, 'email': None, @@ -294,42 +271,27 @@ class TestUserCreate(TestUser): self.assertEqual(self.columns, columns) datalist = ( - identity_fakes.PROJECT_2['id'], - identity_fakes.domain_id, - identity_fakes.user_email, + self.project.id, + self.domain.id, + self.user.email, True, - identity_fakes.user_id, - identity_fakes.user_name, + self.user.id, + self.user.name, ) self.assertEqual(datalist, data) 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 = [ - '--project', identity_fakes.PROJECT_2['name'], - '--project-domain', identity_fakes.PROJECT_2['domain_id'], - identity_fakes.user_name, + '--project', self.project.name, + '--project-domain', self.project.domain_id, + self.user.name, ] verifylist = [ - ('project', identity_fakes.PROJECT_2['name']), - ('project_domain', identity_fakes.PROJECT_2['domain_id']), + ('project', self.project.name), + ('project_domain', self.project.domain_id), ('enable', False), ('disable', False), - ('name', identity_fakes.user_name), + ('name', self.user.name), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -340,8 +302,8 @@ class TestUserCreate(TestUser): # Set expected values kwargs = { - 'name': identity_fakes.user_name, - 'default_project': identity_fakes.PROJECT_2['id'], + 'name': self.user.name, + 'default_project': self.project.id, 'description': None, 'domain': None, 'email': None, @@ -356,25 +318,25 @@ class TestUserCreate(TestUser): self.assertEqual(self.columns, columns) datalist = ( - identity_fakes.PROJECT_2['id'], - identity_fakes.domain_id, - identity_fakes.user_email, + self.project.id, + self.domain.id, + self.user.email, True, - identity_fakes.user_id, - identity_fakes.user_name, + self.user.id, + self.user.name, ) self.assertEqual(datalist, data) def test_user_create_domain(self): arglist = [ - '--domain', identity_fakes.domain_name, - identity_fakes.user_name, + '--domain', self.domain.name, + self.user.name, ] verifylist = [ - ('domain', identity_fakes.domain_name), + ('domain', self.domain.name), ('enable', False), ('disable', False), - ('name', identity_fakes.user_name), + ('name', self.user.name), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -385,10 +347,10 @@ class TestUserCreate(TestUser): # Set expected values kwargs = { - 'name': identity_fakes.user_name, + 'name': self.user.name, 'default_project': None, 'description': None, - 'domain': identity_fakes.domain_id, + 'domain': self.domain.id, 'email': None, 'enabled': True, 'password': None, @@ -405,12 +367,12 @@ class TestUserCreate(TestUser): def test_user_create_enable(self): arglist = [ '--enable', - identity_fakes.user_name, + self.user.name, ] verifylist = [ ('enable', True), ('disable', False), - ('name', identity_fakes.user_name), + ('name', self.user.name), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -421,7 +383,7 @@ class TestUserCreate(TestUser): # Set expected values kwargs = { - 'name': identity_fakes.user_name, + 'name': self.user.name, 'default_project': None, 'description': None, 'domain': None, @@ -441,10 +403,10 @@ class TestUserCreate(TestUser): def test_user_create_disable(self): arglist = [ '--disable', - identity_fakes.user_name, + self.user.name, ] verifylist = [ - ('name', identity_fakes.user_name), + ('name', self.user.name), ('enable', False), ('disable', True), ] @@ -457,7 +419,7 @@ class TestUserCreate(TestUser): # Set expected values kwargs = { - 'name': identity_fakes.user_name, + 'name': self.user.name, 'default_project': None, 'description': None, 'domain': None, @@ -475,15 +437,13 @@ class TestUserCreate(TestUser): class TestUserDelete(TestUser): + user = identity_fakes.FakeUser.create_one_user() + def setUp(self): 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.user self.users_mock.delete.return_value = None # Get the command object to test @@ -491,76 +451,54 @@ class TestUserDelete(TestUser): def test_user_delete_no_options(self): arglist = [ - identity_fakes.user_id, + self.user.id, ] verifylist = [ - ('users', [identity_fakes.user_id]), + ('users', [self.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.user.id, ) self.assertIsNone(result) 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 = [ 'ID', 'Name' ] datalist = ( ( - identity_fakes.user_id, - identity_fakes.user_name, + user.id, + user.name, ), ) def setUp(self): super(TestUserList, self).setUp() - self.users_mock.get.return_value = fakes.FakeResource( - None, - copy.deepcopy(identity_fakes.USER), - loaded=True, - ) - self.users_mock.list.return_value = [ - 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, - ) - ] + self.users_mock.get.return_value = self.user + self.users_mock.list.return_value = [self.user] + self.domains_mock.get.return_value = self.domain + self.groups_mock.get.return_value = self.group + self.projects_mock.get.return_value = self.project + self.role_assignments_mock.list.return_value = [self.role_assignment] # Get the command object to test self.cmd = user.ListUser(self.app, None) @@ -590,10 +528,10 @@ class TestUserList(TestUser): def test_user_list_domain(self): arglist = [ - '--domain', identity_fakes.domain_id, + '--domain', self.domain.id, ] verifylist = [ - ('domain', identity_fakes.domain_id), + ('domain', self.domain.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -604,7 +542,7 @@ class TestUserList(TestUser): # Set expected values kwargs = { - 'domain': identity_fakes.domain_id, + 'domain': self.domain.id, 'group': None, } @@ -617,10 +555,10 @@ class TestUserList(TestUser): def test_user_list_group(self): arglist = [ - '--group', identity_fakes.group_name, + '--group', self.group.name, ] verifylist = [ - ('group', identity_fakes.group_name), + ('group', self.group.name), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -632,7 +570,7 @@ class TestUserList(TestUser): # Set expected values kwargs = { 'domain': None, - 'group': identity_fakes.group_id, + 'group': self.group.id, } self.users_mock.list.assert_called_with( @@ -678,12 +616,12 @@ class TestUserList(TestUser): self.assertEqual(collist, columns) datalist = ( ( - identity_fakes.user_id, - identity_fakes.user_name, - identity_fakes.project_id, - identity_fakes.domain_id, + self.user.id, + self.user.name, + self.project.id, + self.domain.id, '', - identity_fakes.user_email, + self.user.email, True, ), ) @@ -691,10 +629,10 @@ class TestUserList(TestUser): def test_user_list_project(self): arglist = [ - '--project', identity_fakes.project_name, + '--project', self.project.name, ] verifylist = [ - ('project', identity_fakes.project_name), + ('project', self.project.name), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -704,11 +642,11 @@ class TestUserList(TestUser): columns, data = self.cmd.take_action(parsed_args) kwargs = { - 'project': identity_fakes.project_id, + 'project': self.project.id, } 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.datalist, tuple(data)) @@ -716,32 +654,24 @@ class TestUserList(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): 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.users_mock.update.return_value = fakes.FakeResource( - None, - copy.deepcopy(identity_fakes.USER), - loaded=True, - ) + self.projects_mock.get.return_value = self.project + self.users_mock.get.return_value = self.user + self.users_mock.update.return_value = self.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.user.name, ] verifylist = [ ('name', None), @@ -750,7 +680,7 @@ class TestUserSet(TestUser): ('project', None), ('enable', False), ('disable', False), - ('user', identity_fakes.user_name), + ('user', self.user.name), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -761,7 +691,7 @@ class TestUserSet(TestUser): def test_user_set_name(self): arglist = [ '--name', 'qwerty', - identity_fakes.user_name, + self.user.name, ] verifylist = [ ('name', 'qwerty'), @@ -770,7 +700,7 @@ class TestUserSet(TestUser): ('project', None), ('enable', False), ('disable', False), - ('user', identity_fakes.user_name), + ('user', self.user.name), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -784,7 +714,7 @@ class TestUserSet(TestUser): # UserManager.update(user, name=, domain=, project=, password=, # email=, description=, enabled=, default_project=) self.users_mock.update.assert_called_with( - identity_fakes.user_id, + self.user.id, **kwargs ) self.assertIsNone(result) @@ -792,7 +722,7 @@ class TestUserSet(TestUser): def test_user_set_password(self): arglist = [ '--password', 'secret', - identity_fakes.user_name, + self.user.name, ] verifylist = [ ('name', None), @@ -802,7 +732,7 @@ class TestUserSet(TestUser): ('project', None), ('enable', False), ('disable', False), - ('user', identity_fakes.user_name), + ('user', self.user.name), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -816,7 +746,7 @@ class TestUserSet(TestUser): # UserManager.update(user, name=, domain=, project=, password=, # email=, description=, enabled=, default_project=) self.users_mock.update.assert_called_with( - identity_fakes.user_id, + self.user.id, **kwargs ) self.assertIsNone(result) @@ -824,7 +754,7 @@ class TestUserSet(TestUser): def test_user_set_password_prompt(self): arglist = [ '--password-prompt', - identity_fakes.user_name, + self.user.name, ] verifylist = [ ('name', None), @@ -834,7 +764,7 @@ class TestUserSet(TestUser): ('project', None), ('enable', False), ('disable', False), - ('user', identity_fakes.user_name), + ('user', self.user.name), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -851,7 +781,7 @@ class TestUserSet(TestUser): # UserManager.update(user, name=, domain=, project=, password=, # email=, description=, enabled=, default_project=) self.users_mock.update.assert_called_with( - identity_fakes.user_id, + self.user.id, **kwargs ) self.assertIsNone(result) @@ -859,7 +789,7 @@ class TestUserSet(TestUser): def test_user_set_email(self): arglist = [ '--email', 'barney@example.com', - identity_fakes.user_name, + self.user.name, ] verifylist = [ ('name', None), @@ -868,7 +798,7 @@ class TestUserSet(TestUser): ('project', None), ('enable', False), ('disable', False), - ('user', identity_fakes.user_name), + ('user', self.user.name), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -882,24 +812,24 @@ class TestUserSet(TestUser): # UserManager.update(user, name=, domain=, project=, password=, # email=, description=, enabled=, default_project=) self.users_mock.update.assert_called_with( - identity_fakes.user_id, + self.user.id, **kwargs ) self.assertIsNone(result) def test_user_set_project(self): arglist = [ - '--project', identity_fakes.project_id, - identity_fakes.user_name, + '--project', self.project.id, + self.user.name, ] verifylist = [ ('name', None), ('password', None), ('email', None), - ('project', identity_fakes.project_id), + ('project', self.project.id), ('enable', False), ('disable', False), - ('user', identity_fakes.user_name), + ('user', self.user.name), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -908,31 +838,31 @@ class TestUserSet(TestUser): # Set expected values kwargs = { 'enabled': True, - 'default_project': identity_fakes.project_id, + 'default_project': self.project.id, } # UserManager.update(user, name=, domain=, project=, password=, # email=, description=, enabled=, default_project=) self.users_mock.update.assert_called_with( - identity_fakes.user_id, + self.user.id, **kwargs ) self.assertIsNone(result) def test_user_set_project_domain(self): arglist = [ - '--project', identity_fakes.project_id, - '--project-domain', identity_fakes.domain_id, - identity_fakes.user_name, + '--project', self.project.id, + '--project-domain', self.project.domain_id, + self.user.name, ] verifylist = [ ('name', None), ('password', None), ('email', None), - ('project', identity_fakes.project_id), - ('project_domain', identity_fakes.domain_id), + ('project', self.project.id), + ('project_domain', self.project.domain_id), ('enable', False), ('disable', False), - ('user', identity_fakes.user_name), + ('user', self.user.name), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -941,12 +871,12 @@ class TestUserSet(TestUser): # Set expected values kwargs = { 'enabled': True, - 'default_project': identity_fakes.project_id, + 'default_project': self.project.id, } # UserManager.update(user, name=, domain=, project=, password=, # email=, description=, enabled=, default_project=) self.users_mock.update.assert_called_with( - identity_fakes.user_id, + self.user.id, **kwargs ) self.assertIsNone(result) @@ -954,7 +884,7 @@ class TestUserSet(TestUser): def test_user_set_enable(self): arglist = [ '--enable', - identity_fakes.user_name, + self.user.name, ] verifylist = [ ('name', None), @@ -963,7 +893,7 @@ class TestUserSet(TestUser): ('project', None), ('enable', True), ('disable', False), - ('user', identity_fakes.user_name), + ('user', self.user.name), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -976,7 +906,7 @@ class TestUserSet(TestUser): # UserManager.update(user, name=, domain=, project=, password=, # email=, description=, enabled=, default_project=) self.users_mock.update.assert_called_with( - identity_fakes.user_id, + self.user.id, **kwargs ) self.assertIsNone(result) @@ -984,7 +914,7 @@ class TestUserSet(TestUser): def test_user_set_disable(self): arglist = [ '--disable', - identity_fakes.user_name, + self.user.name, ] verifylist = [ ('name', None), @@ -993,7 +923,7 @@ class TestUserSet(TestUser): ('project', None), ('enable', False), ('disable', True), - ('user', identity_fakes.user_name), + ('user', self.user.name), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -1006,7 +936,7 @@ class TestUserSet(TestUser): # UserManager.update(user, name=, domain=, project=, password=, # email=, description=, enabled=, default_project=) self.users_mock.update.assert_called_with( - identity_fakes.user_id, + self.user.id, **kwargs ) self.assertIsNone(result) @@ -1082,35 +1012,33 @@ class TestUserSetPassword(TestUser): class TestUserShow(TestUser): + user = identity_fakes.FakeUser.create_one_user() + 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.user # Get the command object to test self.cmd = user.ShowUser(self.app, None) 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 = \ {'token': {'user': {'domain': {}, - 'id': 'bbbbbbb-aaaa-aaaa-aaaa-bbbbbbbaaaa', - 'name': 'bbbbbbb-aaaa-aaaa-aaaa-bbbbbbbaaaa' + 'id': self.user.id, + 'name': self.user.name, } } } def test_user_show(self): arglist = [ - identity_fakes.user_id, + self.user.id, ] verifylist = [ - ('user', identity_fakes.user_id), + ('user', self.user.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -1119,17 +1047,17 @@ 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.user.id) collist = ('default_project_id', 'domain_id', 'email', 'enabled', 'id', 'name') self.assertEqual(collist, columns) datalist = ( - identity_fakes.project_id, - identity_fakes.domain_id, - identity_fakes.user_email, + self.user.default_project_id, + self.user.domain_id, + self.user.email, True, - identity_fakes.user_id, - identity_fakes.user_name, + self.user.id, + self.user.name, ) self.assertEqual(datalist, data)