Best Python code snippet using tempest_python
test_endpoint_group.py
Source:test_endpoint_group.py  
1# Copyright 2020 SUSE LLC2#3# Licensed under the Apache License, Version 2.0 (the "License"); you may4# not use this file except in compliance with the License. You may obtain5# a copy of the License at6#7#      http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the12# License for the specific language governing permissions and limitations13# under the License.14import abc15from tempest.api.identity import base16from tempest.lib.common.utils import data_utils17from tempest.lib import exceptions18from keystone_tempest_plugin.tests.rbac.v3 import base as rbac_base19class IdentityV3RbacEndpointGroupTests(rbac_base.IdentityV3RbacBaseTests,20                                       metaclass=abc.ABCMeta):21    @classmethod22    def setup_clients(cls):23        super(IdentityV3RbacEndpointGroupTests, cls).setup_clients()24        cls.persona = getattr(cls, 'os_%s' % cls.credentials[0])25        cls.eg_client = cls.persona.endpoint_groups_client26        cls.ef_client = cls.persona.endpoint_filter_client27        cls.admin_client = cls.os_system_admin28        cls.admin_eg_client = cls.admin_client.endpoint_groups_client29        cls.admin_ef_client = cls.admin_client.endpoint_filter_client30    def endpoint_group(self):31        return {32            'name': data_utils.rand_name('endpoint_group'),33            'filters': {'interface': 'public'},34        }35    @abc.abstractmethod36    def test_identity_create_endpoint_group(self):37        """Test identity:create_endpoint_group policy.38        This test must check:39          * whether the persona can create an endpoint group40        """41        pass42    @abc.abstractmethod43    def test_identity_get_endpoint_group(self):44        """Test identity:get_endpoint_group policy.45        This test must check:46          * whether the persona can get an endpoint group47          * whether the persona can get an endpoint group that does not exist48        """49        pass50    @abc.abstractmethod51    def test_identity_list_endpoint_groups(self):52        """Test identity:list_endpoint_groups policy.53        This test must check:54          * whether the persona can list all endpoint groups55        """56        pass57    @abc.abstractmethod58    def test_identity_update_endpoint_group(self):59        """Test identity:update_endpoint_group policy.60        This test must check:61          * whether the persona can update an endpoint group62          * whether the persona can update an endpoint group that does not63            exist64        """65        pass66    @abc.abstractmethod67    def test_identity_delete_endpoint_group(self):68        """Test identity:delete_endpoint_group policy.69        This test must check70          * whether the persona can delete an endpoint group71          * whether the persona can delete an endpoint group that does not72            exist73        """74        pass75    @abc.abstractmethod76    def test_identity_list_projects_associated_with_endpoint_group(self):77        """Test identity:list_projects_associated_with_endpoint_group policy.78        This test must check79          * whether the persona can list projects associated with an endpoint80            group81        """82        pass83    @abc.abstractmethod84    def test_identity_list_endpoints_associated_with_endpoint_group(self):85        """Test identity:list_endpoints_associated_with_endpoint_group86        This test must check87          * whether the persona can list endpoints associated with an endpoint88            group89        """90        pass91    @abc.abstractmethod92    def test_identity_get_endpoint_group_in_project(self):93        """Test identity:get_endpoint_group_in_project94        This test must check95          * whether the persona can check if an endpoint group is associated96            with a project97        """98        pass99    @abc.abstractmethod100    def test_identity_list_endpoint_groups_for_project(self):101        """Test identity:list_endpoint_groups_for_project102        This test must check103          * whether the persona can list endpoint groups associated with a104            project105        """106        pass107    @abc.abstractmethod108    def test_identity_add_endpoint_group_to_project(self):109        """Test identity:add_endpoint_group_to_project110        This test must check111          * whether the persona can allow a project to access an endpoint group112        """113        pass114    @abc.abstractmethod115    def test_identity_remove_endpoint_group_from_project(self):116        """Test identity:remove_endpoint_group_from_project117        This test must check118          * whether the persona can remove an endpoint group from a project119        """120        pass121class SystemAdminTests(122    IdentityV3RbacEndpointGroupTests, base.BaseIdentityTest):123    credentials = ['system_admin']124    def test_identity_create_endpoint_group(self):125        eg = self.do_request('create_endpoint_group', expected_status=201,126                             client=self.eg_client,127                             **self.endpoint_group())['endpoint_group']['id']128        self.addCleanup(self.admin_eg_client.delete_endpoint_group, eg)129    def test_identity_get_endpoint_group(self):130        eg = self.admin_eg_client.create_endpoint_group(131            **self.endpoint_group())['endpoint_group']['id']132        self.addCleanup(self.admin_eg_client.delete_endpoint_group, eg)133        # user can get an endpoint group134        self.do_request('show_endpoint_group', client=self.eg_client,135                        endpoint_group_id=eg)136        # nonexistent endpoint group gives a 404137        self.do_request('show_endpoint_group',138                        expected_status=exceptions.NotFound,139                        client=self.eg_client,140                        endpoint_group_id=data_utils.rand_uuid_hex())141    def test_identity_list_endpoint_groups(self):142        eg = self.admin_eg_client.create_endpoint_group(143            **self.endpoint_group())['endpoint_group']['id']144        self.addCleanup(self.admin_eg_client.delete_endpoint_group, eg)145        resp = self.do_request('list_endpoint_groups',146                               client=self.eg_client)['endpoint_groups']147        self.assertIn(eg, [e['id'] for e in resp])148    def test_identity_update_endpoint_group(self):149        eg = self.admin_eg_client.create_endpoint_group(150            **self.endpoint_group())['endpoint_group']['id']151        self.addCleanup(self.admin_eg_client.delete_endpoint_group, eg)152        # user can update an endpoint group153        self.do_request('update_endpoint_group', client=self.eg_client,154                        endpoint_group_id=eg,155                        description=data_utils.arbitrary_string())156        # nonexistent endpoint group gives a 404157        self.do_request('update_endpoint_group', client=self.eg_client,158                        expected_status=exceptions.NotFound,159                        endpoint_group_id=data_utils.rand_uuid_hex(),160                        description=data_utils.arbitrary_string())161    def test_identity_delete_endpoint_group(self):162        eg = self.admin_eg_client.create_endpoint_group(163            **self.endpoint_group())['endpoint_group']['id']164        # user can delete an endpoint group165        self.do_request('delete_endpoint_group',166                        expected_status=204,167                        client=self.eg_client,168                        endpoint_group_id=eg)169        # nonexistent endpoint group gives a 404170        self.do_request('delete_endpoint_group',171                        expected_status=exceptions.NotFound,172                        client=self.eg_client,173                        endpoint_group_id=data_utils.rand_uuid_hex())174    def test_identity_list_projects_associated_with_endpoint_group(self):175        eg = self.admin_eg_client.create_endpoint_group(176            **self.endpoint_group())['endpoint_group']['id']177        self.addCleanup(self.admin_eg_client.delete_endpoint_group, eg)178        project = self.admin_client.projects_client.create_project(179            name=data_utils.rand_name('project'))['project']['id']180        self.addCleanup(self.admin_client.projects_client.delete_project,181                        project)182        self.admin_ef_client.add_endpoint_group_to_project(183            endpoint_group_id=eg, project_id=project)184        self.addCleanup(185            self.admin_ef_client.delete_endpoint_group_from_project,186            endpoint_group_id=eg, project_id=project)187        resp = self.do_request('list_projects_for_endpoint_group',188                               client=self.ef_client,189                               endpoint_group_id=eg)['projects']190        self.assertIn(project, [p['id'] for p in resp])191    def test_identity_list_endpoints_associated_with_endpoint_group(self):192        service = self.admin_client.identity_services_v3_client.create_service(193            type=data_utils.rand_name('service'))['service']['id']194        self.addCleanup(195            self.admin_client.identity_services_v3_client.delete_service,196            service)197        endpoint = self.admin_client.endpoints_v3_client.create_endpoint(198            interface='public',199            url='http://localhost/foo',200            service_id=service)['endpoint']['id']201        self.addCleanup(self.admin_client.endpoints_v3_client.delete_endpoint,202                        endpoint)203        eg = self.admin_eg_client.create_endpoint_group(204            **self.endpoint_group())['endpoint_group']['id']205        self.addCleanup(self.admin_eg_client.delete_endpoint_group, eg)206        resp = self.do_request('list_endpoints_for_endpoint_group',207                               client=self.ef_client,208                               endpoint_group_id=eg)['endpoints']209        self.assertIn(endpoint, [e['id'] for e in resp])210    def test_identity_get_endpoint_group_in_project(self):211        eg = self.admin_eg_client.create_endpoint_group(212            **self.endpoint_group())['endpoint_group']['id']213        self.addCleanup(self.admin_eg_client.delete_endpoint_group, eg)214        project = self.admin_client.projects_client.create_project(215            name=data_utils.rand_name('project'))['project']['id']216        self.addCleanup(self.admin_client.projects_client.delete_project,217                        project)218        self.admin_ef_client.add_endpoint_group_to_project(219            endpoint_group_id=eg, project_id=project)220        self.addCleanup(221            self.admin_ef_client.delete_endpoint_group_from_project,222            endpoint_group_id=eg, project_id=project)223        self.do_request('show_endpoint_group_for_project',224                        client=self.ef_client,225                        endpoint_group_id=eg,226                        project_id=project)227    def test_identity_list_endpoint_groups_for_project(self):228        eg = self.admin_eg_client.create_endpoint_group(229            **self.endpoint_group())['endpoint_group']['id']230        self.addCleanup(self.admin_eg_client.delete_endpoint_group, eg)231        project = self.admin_client.projects_client.create_project(232            name=data_utils.rand_name('project'))['project']['id']233        self.addCleanup(self.admin_client.projects_client.delete_project,234                        project)235        self.admin_ef_client.add_endpoint_group_to_project(236            endpoint_group_id=eg, project_id=project)237        self.addCleanup(238            self.admin_ef_client.delete_endpoint_group_from_project,239            endpoint_group_id=eg, project_id=project)240        resp = self.do_request('list_endpoint_groups_for_project',241                               client=self.ef_client,242                               project_id=project)243        self.assertIn(eg, [e['id'] for e in resp['endpoint_groups']])244    def test_identity_add_endpoint_group_to_project(self):245        eg = self.admin_eg_client.create_endpoint_group(246            **self.endpoint_group())['endpoint_group']['id']247        self.addCleanup(self.admin_eg_client.delete_endpoint_group, eg)248        project = self.admin_client.projects_client.create_project(249            name=data_utils.rand_name('project'))['project']['id']250        self.addCleanup(self.admin_client.projects_client.delete_project,251                        project)252        self.do_request('add_endpoint_group_to_project',253                        client=self.ef_client,254                        expected_status=204,255                        endpoint_group_id=eg,256                        project_id=project)257        self.addCleanup(258            self.admin_ef_client.delete_endpoint_group_from_project,259            endpoint_group_id=eg, project_id=project)260    def test_identity_remove_endpoint_group_from_project(self):261        eg = self.admin_eg_client.create_endpoint_group(262            **self.endpoint_group())['endpoint_group']['id']263        self.addCleanup(self.admin_eg_client.delete_endpoint_group, eg)264        project = self.admin_client.projects_client.create_project(265            name=data_utils.rand_name('project'))['project']['id']266        self.addCleanup(self.admin_client.projects_client.delete_project,267                        project)268        self.admin_ef_client.add_endpoint_group_to_project(269            endpoint_group_id=eg, project_id=project)270        self.do_request('delete_endpoint_group_from_project',271                        client=self.ef_client,272                        expected_status=204,273                        endpoint_group_id=eg, project_id=project)274class SystemMemberTests(SystemAdminTests, base.BaseIdentityTest):275    credentials = ['system_member', 'system_admin']276    def test_identity_create_endpoint_group(self):277        self.do_request('create_endpoint_group',278                        expected_status=exceptions.Forbidden,279                        client=self.eg_client,280                        **self.endpoint_group())281    def test_identity_update_endpoint_group(self):282        eg = self.admin_eg_client.create_endpoint_group(283            **self.endpoint_group())['endpoint_group']['id']284        self.addCleanup(self.admin_eg_client.delete_endpoint_group, eg)285        # user can update an endpoint group286        self.do_request('update_endpoint_group', client=self.eg_client,287                        expected_status=exceptions.Forbidden,288                        endpoint_group_id=eg,289                        description=data_utils.arbitrary_string())290        # nonexistent endpoint group gives a 403291        self.do_request('update_endpoint_group', client=self.eg_client,292                        expected_status=exceptions.Forbidden,293                        endpoint_group_id=data_utils.rand_uuid_hex(),294                        description=data_utils.arbitrary_string())295    def test_identity_delete_endpoint_group(self):296        eg = self.admin_eg_client.create_endpoint_group(297            **self.endpoint_group())['endpoint_group']['id']298        self.addCleanup(self.admin_eg_client.delete_endpoint_group, eg)299        # user cannot delete an endpoint group300        self.do_request('delete_endpoint_group',301                        expected_status=exceptions.Forbidden,302                        client=self.eg_client,303                        endpoint_group_id=eg)304        # nonexistent endpoint group gives a 403305        self.do_request('delete_endpoint_group',306                        expected_status=exceptions.Forbidden,307                        client=self.eg_client,308                        endpoint_group_id=data_utils.rand_uuid_hex())309    def test_identity_add_endpoint_group_to_project(self):310        eg = self.admin_eg_client.create_endpoint_group(311            **self.endpoint_group())['endpoint_group']['id']312        self.addCleanup(self.admin_eg_client.delete_endpoint_group, eg)313        project = self.admin_client.projects_client.create_project(314            name=data_utils.rand_name('project'))['project']['id']315        self.addCleanup(self.admin_client.projects_client.delete_project,316                        project)317        self.do_request('add_endpoint_group_to_project',318                        client=self.ef_client,319                        expected_status=exceptions.Forbidden,320                        endpoint_group_id=eg,321                        project_id=project)322    def test_identity_remove_endpoint_group_from_project(self):323        eg = self.admin_eg_client.create_endpoint_group(324            **self.endpoint_group())['endpoint_group']['id']325        self.addCleanup(self.admin_eg_client.delete_endpoint_group, eg)326        project = self.admin_client.projects_client.create_project(327            name=data_utils.rand_name('project'))['project']['id']328        self.addCleanup(self.admin_client.projects_client.delete_project,329                        project)330        self.admin_ef_client.add_endpoint_group_to_project(331            endpoint_group_id=eg, project_id=project)332        self.addCleanup(333            self.admin_ef_client.delete_endpoint_group_from_project,334            endpoint_group_id=eg, project_id=project)335        self.do_request('delete_endpoint_group_from_project',336                        client=self.ef_client,337                        expected_status=exceptions.Forbidden,338                        endpoint_group_id=eg, project_id=project)339class SystemReaderTests(SystemMemberTests):340    credentials = ['system_reader', 'system_admin']341class DomainAdminTests(SystemReaderTests, base.BaseIdentityTest):342    credentials = ['domain_admin', 'system_admin']343    def test_identity_get_endpoint_group(self):344        eg = self.admin_eg_client.create_endpoint_group(345            **self.endpoint_group())['endpoint_group']['id']346        self.addCleanup(self.admin_eg_client.delete_endpoint_group, eg)347        # user cannot get an endpoint group348        self.do_request('show_endpoint_group', client=self.eg_client,349                        expected_status=exceptions.Forbidden,350                        endpoint_group_id=eg)351        # nonexistent endpoint group gives a 403352        self.do_request('show_endpoint_group',353                        expected_status=exceptions.Forbidden,354                        client=self.eg_client,355                        endpoint_group_id=data_utils.rand_uuid_hex())356    def test_identity_list_endpoint_groups(self):357        eg = self.admin_eg_client.create_endpoint_group(358            **self.endpoint_group())['endpoint_group']['id']359        self.addCleanup(self.admin_eg_client.delete_endpoint_group, eg)360        self.do_request('list_endpoint_groups',361                        expected_status=exceptions.Forbidden,362                        client=self.eg_client)363    def test_identity_list_projects_associated_with_endpoint_group(self):364        eg = self.admin_eg_client.create_endpoint_group(365            **self.endpoint_group())['endpoint_group']['id']366        self.addCleanup(self.admin_eg_client.delete_endpoint_group, eg)367        project = self.admin_client.projects_client.create_project(368            name=data_utils.rand_name('project'))['project']['id']369        self.addCleanup(self.admin_client.projects_client.delete_project,370                        project)371        self.admin_ef_client.add_endpoint_group_to_project(372            endpoint_group_id=eg, project_id=project)373        self.addCleanup(374            self.admin_ef_client.delete_endpoint_group_from_project,375            endpoint_group_id=eg, project_id=project)376        self.do_request('list_projects_for_endpoint_group',377                        client=self.ef_client,378                        expected_status=exceptions.Forbidden,379                        endpoint_group_id=eg)380    def test_identity_list_endpoints_associated_with_endpoint_group(self):381        service = self.admin_client.identity_services_v3_client.create_service(382            type=data_utils.rand_name('service'))['service']['id']383        self.addCleanup(384            self.admin_client.identity_services_v3_client.delete_service,385            service)386        endpoint = self.admin_client.endpoints_v3_client.create_endpoint(387            interface='public',388            url='http://localhost/foo',389            service_id=service)['endpoint']['id']390        self.addCleanup(self.admin_client.endpoints_v3_client.delete_endpoint,391                        endpoint)392        eg = self.admin_eg_client.create_endpoint_group(393            **self.endpoint_group())['endpoint_group']['id']394        self.addCleanup(self.admin_eg_client.delete_endpoint_group, eg)395        self.do_request('list_endpoints_for_endpoint_group',396                        client=self.ef_client,397                        expected_status=exceptions.Forbidden,398                        endpoint_group_id=eg)399    def test_identity_get_endpoint_group_in_project(self):400        eg = self.admin_eg_client.create_endpoint_group(401            **self.endpoint_group())['endpoint_group']['id']402        self.addCleanup(self.admin_eg_client.delete_endpoint_group, eg)403        project = self.admin_client.projects_client.create_project(404            name=data_utils.rand_name('project'))['project']['id']405        self.addCleanup(self.admin_client.projects_client.delete_project,406                        project)407        self.admin_ef_client.add_endpoint_group_to_project(408            endpoint_group_id=eg, project_id=project)409        self.addCleanup(410            self.admin_ef_client.delete_endpoint_group_from_project,411            endpoint_group_id=eg, project_id=project)412        self.do_request('show_endpoint_group_for_project',413                        client=self.ef_client,414                        expected_status=exceptions.Forbidden,415                        endpoint_group_id=eg,416                        project_id=project)417    def test_identity_list_endpoint_groups_for_project(self):418        eg = self.admin_eg_client.create_endpoint_group(419            **self.endpoint_group())['endpoint_group']['id']420        self.addCleanup(self.admin_eg_client.delete_endpoint_group, eg)421        project = self.admin_client.projects_client.create_project(422            name=data_utils.rand_name('project'))['project']['id']423        self.addCleanup(self.admin_client.projects_client.delete_project,424                        project)425        self.admin_ef_client.add_endpoint_group_to_project(426            endpoint_group_id=eg, project_id=project)427        self.addCleanup(428            self.admin_ef_client.delete_endpoint_group_from_project,429            endpoint_group_id=eg, project_id=project)430        self.do_request('list_endpoint_groups_for_project',431                        client=self.ef_client,432                        expected_status=exceptions.Forbidden,433                        project_id=project)434class DomainMemberTests(DomainAdminTests, base.BaseIdentityTest):435    credentials = ['domain_member', 'system_admin']436class DomainReaderTests(DomainMemberTests):437    credentials = ['domain_reader', 'system_admin']438class ProjectAdminTests(DomainReaderTests, base.BaseIdentityTest):439    credentials = ['project_admin', 'system_admin']440class ProjectMemberTests(ProjectAdminTests):441    credentials = ['project_member', 'system_admin']442class ProjectReaderTests(ProjectAdminTests):...test_endpoint_filter.py
Source:test_endpoint_filter.py  
...216            self.assertRaises(ValueError,217                              self.manager.check_endpoint_group_in_project,218                              project=value,219                              endpoint_group=uuid.uuid4().hex)220    def test_delete_endpoint_group_from_project(self):221        endpoint_group_id = uuid.uuid4().hex222        project_id = uuid.uuid4().hex223        self.stub_url('DELETE',224                      [self.manager.OS_EP_FILTER_EXT, 'endpoint_groups',225                       endpoint_group_id, 'projects', project_id],226                      status_code=201)227        self.manager.delete_endpoint_group_from_project(228            project=project_id, endpoint_group=endpoint_group_id)229    def test_delete_endpoint_group_from_project_value_error(self):230        for value in ('', None):231            self.assertRaises(ValueError,232                              self.manager.delete_endpoint_group_from_project,233                              project=value,234                              endpoint_group=value)235            self.assertRaises(ValueError,236                              self.manager.delete_endpoint_group_from_project,237                              project=uuid.uuid4().hex,238                              endpoint_group=value)239            self.assertRaises(ValueError,240                              self.manager.delete_endpoint_group_from_project,241                              project=value,...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
