diff options
| author | Jose Castro Leon <jose.castro.leon@cern.ch> | 2017-10-25 15:39:44 +0200 |
|---|---|---|
| committer | Jose Castro Leon <jose.castro.leon@cern.ch> | 2017-11-21 07:58:48 +0100 |
| commit | 12ee1861085144f43e6e535f82ba5d9b5d9a5632 (patch) | |
| tree | 9b8a68d904ce43c41503752f8727bbd2eb80251b /openstackclient/tests/unit/identity/v3/test_endpoint.py | |
| parent | 4742d4df7089cd10d03635a1b3dbca9e7e80b1cc (diff) | |
| download | python-openstackclient-12ee1861085144f43e6e535f82ba5d9b5d9a5632.tar.gz | |
Add support for endpoing filter commands
Implements the commands that allow to link and endpoint to
a project for endpoint filter management.
Implements: blueprint keystone-endpoint-filter
Change-Id: Iecf61495664fb8413d35ef69f07ea929d190d002
Diffstat (limited to 'openstackclient/tests/unit/identity/v3/test_endpoint.py')
| -rw-r--r-- | openstackclient/tests/unit/identity/v3/test_endpoint.py | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/openstackclient/tests/unit/identity/v3/test_endpoint.py b/openstackclient/tests/unit/identity/v3/test_endpoint.py index fad53fcb..bfe930d6 100644 --- a/openstackclient/tests/unit/identity/v3/test_endpoint.py +++ b/openstackclient/tests/unit/identity/v3/test_endpoint.py @@ -22,11 +22,23 @@ class TestEndpoint(identity_fakes.TestIdentityv3): # Get a shortcut to the EndpointManager Mock self.endpoints_mock = self.app.client_manager.identity.endpoints self.endpoints_mock.reset_mock() + self.ep_filter_mock = ( + self.app.client_manager.identity.endpoint_filter + ) + self.ep_filter_mock.reset_mock() # Get a shortcut to the ServiceManager Mock self.services_mock = self.app.client_manager.identity.services self.services_mock.reset_mock() + # Get a shortcut to the DomainManager Mock + self.domains_mock = self.app.client_manager.identity.domains + self.domains_mock.reset_mock() + + # Get a shortcut to the ProjectManager Mock + self.projects_mock = self.app.client_manager.identity.projects + self.projects_mock.reset_mock() + class TestEndpointCreate(TestEndpoint): @@ -750,3 +762,130 @@ class TestEndpointShowServiceWithoutName(TestEndpointShow): # Get the command object to test self.cmd = endpoint.ShowEndpoint(self.app, None) + + +class TestAddProjectToEndpoint(TestEndpoint): + + project = identity_fakes.FakeProject.create_one_project() + domain = identity_fakes.FakeDomain.create_one_domain() + service = identity_fakes.FakeService.create_one_service() + endpoint = identity_fakes.FakeEndpoint.create_one_endpoint( + attrs={'service_id': service.id}) + + new_ep_filter = identity_fakes.FakeEndpoint.create_one_endpoint_filter( + attrs={'endpoint': endpoint.id, + 'project': project.id} + ) + + def setUp(self): + super(TestAddProjectToEndpoint, self).setUp() + + # This is the return value for utils.find_resource() + self.endpoints_mock.get.return_value = self.endpoint + + # Update the image_id in the MEMBER dict + self.ep_filter_mock.create.return_value = self.new_ep_filter + self.projects_mock.get.return_value = self.project + self.domains_mock.get.return_value = self.domain + # Get the command object to test + self.cmd = endpoint.AddProjectToEndpoint(self.app, None) + + def test_add_project_to_endpoint_no_option(self): + arglist = [ + self.endpoint.id, + self.project.id, + ] + verifylist = [ + ('endpoint', self.endpoint.id), + ('project', self.project.id), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + result = self.cmd.take_action(parsed_args) + self.ep_filter_mock.add_endpoint_to_project.assert_called_with( + project=self.project.id, + endpoint=self.endpoint.id + ) + self.assertIsNone(result) + + def test_add_project_to_endpoint_with_option(self): + arglist = [ + self.endpoint.id, + self.project.id, + '--project-domain', self.domain.id, + ] + verifylist = [ + ('endpoint', self.endpoint.id), + ('project', self.project.id), + ('project_domain', self.domain.id), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + result = self.cmd.take_action(parsed_args) + self.ep_filter_mock.add_endpoint_to_project.assert_called_with( + project=self.project.id, + endpoint=self.endpoint.id + ) + self.assertIsNone(result) + + +class TestRemoveProjectEndpoint(TestEndpoint): + + project = identity_fakes.FakeProject.create_one_project() + domain = identity_fakes.FakeDomain.create_one_domain() + service = identity_fakes.FakeService.create_one_service() + endpoint = identity_fakes.FakeEndpoint.create_one_endpoint( + attrs={'service_id': service.id}) + + def setUp(self): + super(TestRemoveProjectEndpoint, self).setUp() + + # This is the return value for utils.find_resource() + self.endpoints_mock.get.return_value = self.endpoint + + self.projects_mock.get.return_value = self.project + self.domains_mock.get.return_value = self.domain + self.ep_filter_mock.delete.return_value = None + + # Get the command object to test + self.cmd = endpoint.RemoveProjectFromEndpoint(self.app, None) + + def test_remove_project_endpoint_no_options(self): + arglist = [ + self.endpoint.id, + self.project.id, + ] + verifylist = [ + ('endpoint', self.endpoint.id), + ('project', self.project.id), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + result = self.cmd.take_action(parsed_args) + + self.ep_filter_mock.delete_endpoint_from_project.assert_called_with( + project=self.project.id, + endpoint=self.endpoint.id, + ) + self.assertIsNone(result) + + def test_remove_project_endpoint_with_options(self): + arglist = [ + self.endpoint.id, + self.project.id, + '--project-domain', self.domain.id, + ] + verifylist = [ + ('endpoint', self.endpoint.id), + ('project', self.project.id), + ('project_domain', self.domain.id), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + result = self.cmd.take_action(parsed_args) + + self.ep_filter_mock.delete_endpoint_from_project.assert_called_with( + project=self.project.id, + endpoint=self.endpoint.id, + ) + self.assertIsNone(result) |
