Best Python code snippet using tempest_python
test_policy_association.py
Source:test_policy_association.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 IdentityV3RbacPolicyAssociationTests(rbac_base.IdentityV3RbacBaseTests,20 metaclass=abc.ABCMeta):21 @classmethod22 def setup_clients(cls):23 super(IdentityV3RbacPolicyAssociationTests, cls).setup_clients()24 cls.persona = getattr(cls, 'os_%s' % cls.credentials[0])25 cls.client = cls.persona.policies_client26 cls.admin_client = cls.os_system_admin27 cls.admin_policies_client = cls.admin_client.policies_client28 @classmethod29 def resource_setup(cls):30 super(IdentityV3RbacPolicyAssociationTests, cls).resource_setup()31 cls.policy_id = cls.admin_policies_client.create_policy(32 blob=data_utils.rand_uuid_hex(),33 type=data_utils.rand_uuid_hex())['policy']['id']34 cls.addClassResourceCleanup(35 cls.admin_policies_client.delete_policy,36 policy_id=cls.policy_id)37 cls.region_id = cls.admin_client.regions_client.create_region(38 region_id=data_utils.rand_name())['region']['id']39 cls.addClassResourceCleanup(40 cls.admin_client.regions_client.delete_region,41 cls.region_id)42 svc_client = cls.admin_client.identity_services_v3_client43 cls.service_id = svc_client.create_service(44 type=data_utils.rand_name())['service']['id']45 cls.addClassResourceCleanup(svc_client.delete_service, cls.service_id)46 cls.endpoint_id = cls.admin_client.endpoints_v3_client.create_endpoint(47 interface='public',48 url='http://localhost/foo',49 service_id=cls.service_id)['endpoint']['id']50 cls.addClassResourceCleanup(51 cls.admin_client.endpoints_v3_client.delete_endpoint,52 endpoint_id=cls.endpoint_id)53 @abc.abstractmethod54 def test_identity_create_policy_association_for_endpoint(self):55 """Test identity:create_policy_association_for_endpoint policy.56 This test must check:57 * whether the persona can associate a policy with an endpoint58 """59 pass60 @abc.abstractmethod61 def test_identity_create_policy_association_for_service(self):62 """Test identity:create_policy_association_for_service policy.63 This test must check:64 * whether the persona can associate a policy with a service65 """66 pass67 @abc.abstractmethod68 def test_identity_create_policy_association_for_region_and_service(self):69 """Test identity:create_policy_association_for_region_and_service.70 This test must check:71 * whether the persona can associate a policy with a region and72 service73 """74 pass75 @abc.abstractmethod76 def test_identity_check_policy_association_for_endpoint(self):77 """Test identity:check_policy_association_for_endpoint policy.78 This test must check:79 * whether the persona can check a policy association for an endpoint80 """81 pass82 @abc.abstractmethod83 def test_identity_check_policy_association_for_service(self):84 """Test identity:check_policy_association_for_service policy.85 This test must check:86 * whether the persona can check a policy association for a service87 """88 pass89 @abc.abstractmethod90 def test_identity_check_policy_association_for_region_and_service(self):91 """Test identity:check_policy_association_for_region_and_service.92 This test must check:93 * whether the persona can check a policy association for a region and94 service95 """96 pass97 @abc.abstractmethod98 def test_identity_get_policy_for_endpoint(self):99 """Test identity:get_policy_for_endpoint policy.100 This test must check:101 * whether the persona can get a policy for an endpoint102 """103 pass104 @abc.abstractmethod105 def test_identity_list_endpoints_for_policy(self):106 """Test identity:list_endpoints_for_policy policy.107 This test must check:108 * whether the persona can list endpoints for a policy109 """110 pass111 @abc.abstractmethod112 def test_identity_delete_policy_association_for_endpoint(self):113 """Test identity:delete_policy_association_for_endpoint policy.114 This test must check115 * whether the persona can delete a policy association for an endpoint116 """117 pass118 @abc.abstractmethod119 def test_identity_delete_policy_association_for_service(self):120 """Test identity:delete_policy_association_for_service policy.121 This test must check122 * whether the persona can delete a policy association for a service123 """124 pass125 @abc.abstractmethod126 def test_identity_delete_policy_association_for_region_and_service(self):127 """Test identity:delete_policy_association_for_region_and_service policy.128 This test must check129 * whether the persona can delete a policy association for a region130 and service131 """132 pass133class SystemAdminTests(134 IdentityV3RbacPolicyAssociationTests, base.BaseIdentityTest):135 credentials = ['system_admin']136 def test_identity_create_policy_association_for_endpoint(self):137 self.do_request(138 'update_policy_association_for_endpoint',139 expected_status=204,140 policy_id=self.policy_id, endpoint_id=self.endpoint_id)141 self.addCleanup(142 self.admin_policies_client.delete_policy_association_for_endpoint,143 policy_id=self.policy_id, endpoint_id=self.endpoint_id)144 def test_identity_create_policy_association_for_service(self):145 self.do_request(146 'update_policy_association_for_service',147 expected_status=204,148 policy_id=self.policy_id, service_id=self.service_id)149 self.addCleanup(150 self.admin_policies_client.delete_policy_association_for_service,151 policy_id=self.policy_id, service_id=self.service_id)152 def test_identity_create_policy_association_for_region_and_service(self):153 self.do_request(154 'update_policy_association_for_region_and_service',155 expected_status=204,156 policy_id=self.policy_id, service_id=self.service_id,157 region_id=self.region_id)158 delete_fn = getattr(159 self.admin_policies_client,160 'delete_policy_association_for_region_and_service'161 )162 self.addCleanup(delete_fn,163 policy_id=self.policy_id,164 service_id=self.service_id,165 region_id=self.region_id)166 def test_identity_check_policy_association_for_endpoint(self):167 self.admin_policies_client.update_policy_association_for_endpoint(168 policy_id=self.policy_id, endpoint_id=self.endpoint_id)169 self.addCleanup(170 self.admin_policies_client.delete_policy_association_for_endpoint,171 policy_id=self.policy_id, endpoint_id=self.endpoint_id)172 self.do_request(173 'show_policy_association_for_endpoint',174 expected_status=204,175 policy_id=self.policy_id, endpoint_id=self.endpoint_id)176 def test_identity_check_policy_association_for_service(self):177 self.admin_policies_client.update_policy_association_for_service(178 policy_id=self.policy_id, service_id=self.service_id)179 self.addCleanup(180 self.admin_policies_client.delete_policy_association_for_service,181 policy_id=self.policy_id, service_id=self.service_id)182 self.do_request(183 'show_policy_association_for_service',184 expected_status=204,185 policy_id=self.policy_id, service_id=self.service_id)186 def test_identity_check_policy_association_for_region_and_service(self):187 update_fn = getattr(188 self.admin_policies_client,189 'update_policy_association_for_region_and_service'190 )191 update_fn(policy_id=self.policy_id,192 service_id=self.service_id,193 region_id=self.region_id)194 delete_fn = getattr(195 self.admin_policies_client,196 'delete_policy_association_for_region_and_service'197 )198 self.addCleanup(delete_fn,199 policy_id=self.policy_id,200 service_id=self.service_id,201 region_id=self.region_id)202 self.do_request(203 'show_policy_association_for_region_and_service',204 expected_status=204,205 policy_id=self.policy_id,206 service_id=self.service_id,207 region_id=self.region_id)208 def test_identity_get_policy_for_endpoint(self):209 self.admin_policies_client.update_policy_association_for_endpoint(210 policy_id=self.policy_id, endpoint_id=self.endpoint_id)211 self.addCleanup(212 self.admin_policies_client.delete_policy_association_for_endpoint,213 policy_id=self.policy_id, endpoint_id=self.endpoint_id)214 self.do_request(215 'show_policy_for_endpoint',216 expected_status=200,217 endpoint_id=self.endpoint_id)218 def test_identity_list_endpoints_for_policy(self):219 self.admin_policies_client.update_policy_association_for_endpoint(220 policy_id=self.policy_id, endpoint_id=self.endpoint_id)221 self.addCleanup(222 self.admin_policies_client.delete_policy_association_for_endpoint,223 policy_id=self.policy_id, endpoint_id=self.endpoint_id)224 self.do_request(225 'list_endpoints_for_policy',226 expected_status=200,227 policy_id=self.policy_id)228 def test_identity_delete_policy_association_for_endpoint(self):229 self.admin_policies_client.update_policy_association_for_endpoint(230 policy_id=self.policy_id, endpoint_id=self.endpoint_id)231 self.do_request(232 'delete_policy_association_for_endpoint',233 expected_status=204,234 policy_id=self.policy_id, endpoint_id=self.endpoint_id)235 def test_identity_delete_policy_association_for_service(self):236 self.admin_policies_client.update_policy_association_for_service(237 policy_id=self.policy_id, service_id=self.service_id)238 self.do_request(239 'delete_policy_association_for_service',240 expected_status=204,241 policy_id=self.policy_id, service_id=self.service_id)242 def test_identity_delete_policy_association_for_region_and_service(self):243 update_fn = getattr(244 self.admin_policies_client,245 'update_policy_association_for_region_and_service'246 )247 update_fn(policy_id=self.policy_id,248 service_id=self.service_id,249 region_id=self.region_id)250 self.do_request(251 'delete_policy_association_for_region_and_service',252 expected_status=204,253 policy_id=self.policy_id,254 service_id=self.service_id,255 region_id=self.region_id)256class SystemMemberTests(SystemAdminTests, base.BaseIdentityTest):257 credentials = ['system_member', 'system_admin']258 def test_identity_create_policy_association_for_endpoint(self):259 self.do_request(260 'update_policy_association_for_endpoint',261 expected_status=exceptions.Forbidden,262 policy_id=self.policy_id, endpoint_id=self.endpoint_id)263 def test_identity_create_policy_association_for_service(self):264 self.do_request(265 'update_policy_association_for_service',266 expected_status=exceptions.Forbidden,267 policy_id=self.policy_id, service_id=self.service_id)268 def test_identity_create_policy_association_for_region_and_service(self):269 self.do_request(270 'update_policy_association_for_region_and_service',271 expected_status=exceptions.Forbidden,272 policy_id=self.policy_id, service_id=self.service_id,273 region_id=self.region_id)274 def test_identity_delete_policy_association_for_endpoint(self):275 self.admin_policies_client.update_policy_association_for_endpoint(276 policy_id=self.policy_id, endpoint_id=self.endpoint_id)277 self.addCleanup(278 self.admin_policies_client.delete_policy_association_for_endpoint,279 policy_id=self.policy_id, endpoint_id=self.endpoint_id)280 self.do_request(281 'delete_policy_association_for_endpoint',282 expected_status=exceptions.Forbidden,283 policy_id=self.policy_id, endpoint_id=self.endpoint_id)284 def test_identity_delete_policy_association_for_service(self):285 self.admin_policies_client.update_policy_association_for_service(286 policy_id=self.policy_id, service_id=self.service_id)287 self.addCleanup(288 self.admin_policies_client.delete_policy_association_for_service,289 policy_id=self.policy_id, service_id=self.service_id)290 self.do_request(291 'delete_policy_association_for_service',292 expected_status=exceptions.Forbidden,293 policy_id=self.policy_id, service_id=self.service_id)294 def test_identity_delete_policy_association_for_region_and_service(self):295 update_fn = getattr(296 self.admin_policies_client,297 'update_policy_association_for_region_and_service'298 )299 update_fn(policy_id=self.policy_id,300 service_id=self.service_id,301 region_id=self.region_id)302 delete_fn = getattr(303 self.admin_policies_client,304 'delete_policy_association_for_region_and_service'305 )306 self.addCleanup(delete_fn,307 policy_id=self.policy_id,308 service_id=self.service_id,309 region_id=self.region_id)310 self.do_request(311 'delete_policy_association_for_region_and_service',312 expected_status=exceptions.Forbidden,313 policy_id=self.policy_id,314 service_id=self.service_id,315 region_id=self.region_id)316class SystemReaderTests(SystemMemberTests):317 credentials = ['system_reader', 'system_admin']318class DomainAdminTests(SystemReaderTests, base.BaseIdentityTest):319 credentials = ['domain_admin', 'system_admin']320 def test_identity_check_policy_association_for_endpoint(self):321 self.admin_policies_client.update_policy_association_for_endpoint(322 policy_id=self.policy_id, endpoint_id=self.endpoint_id)323 self.addCleanup(324 self.admin_policies_client.delete_policy_association_for_endpoint,325 policy_id=self.policy_id, endpoint_id=self.endpoint_id)326 self.do_request(327 'show_policy_association_for_endpoint',328 expected_status=exceptions.Forbidden,329 policy_id=self.policy_id, endpoint_id=self.endpoint_id)330 def test_identity_check_policy_association_for_service(self):331 self.admin_policies_client.update_policy_association_for_service(332 policy_id=self.policy_id, service_id=self.service_id)333 self.addCleanup(334 self.admin_policies_client.delete_policy_association_for_service,335 policy_id=self.policy_id, service_id=self.service_id)336 self.do_request(337 'show_policy_association_for_service',338 expected_status=exceptions.Forbidden,339 policy_id=self.policy_id, service_id=self.service_id)340 def test_identity_check_policy_association_for_region_and_service(self):341 update_fn = getattr(342 self.admin_policies_client,343 'update_policy_association_for_region_and_service'344 )345 update_fn(policy_id=self.policy_id,346 service_id=self.service_id,347 region_id=self.region_id)348 delete_fn = getattr(349 self.admin_policies_client,350 'delete_policy_association_for_region_and_service'351 )352 self.addCleanup(delete_fn,353 policy_id=self.policy_id,354 service_id=self.service_id,355 region_id=self.region_id)356 self.do_request(357 'show_policy_association_for_region_and_service',358 expected_status=exceptions.Forbidden,359 policy_id=self.policy_id,360 service_id=self.service_id,361 region_id=self.region_id)362 def test_identity_get_policy_for_endpoint(self):363 self.admin_policies_client.update_policy_association_for_endpoint(364 policy_id=self.policy_id, endpoint_id=self.endpoint_id)365 self.addCleanup(366 self.admin_policies_client.delete_policy_association_for_endpoint,367 policy_id=self.policy_id, endpoint_id=self.endpoint_id)368 self.do_request(369 'show_policy_for_endpoint',370 expected_status=exceptions.Forbidden,371 endpoint_id=self.endpoint_id)372 def test_identity_list_endpoints_for_policy(self):373 self.admin_policies_client.update_policy_association_for_endpoint(374 policy_id=self.policy_id, endpoint_id=self.endpoint_id)375 self.addCleanup(376 self.admin_policies_client.delete_policy_association_for_endpoint,377 policy_id=self.policy_id, endpoint_id=self.endpoint_id)378 self.do_request(379 'list_endpoints_for_policy',380 expected_status=exceptions.Forbidden,381 policy_id=self.policy_id)382class DomainMemberTests(DomainAdminTests, base.BaseIdentityTest):383 credentials = ['domain_member', 'system_admin']384class DomainReaderTests(DomainMemberTests):385 credentials = ['domain_reader', 'system_admin']386class ProjectAdminTests(DomainReaderTests, base.BaseIdentityTest):387 credentials = ['project_admin', 'system_admin']388class ProjectMemberTests(ProjectAdminTests):389 credentials = ['project_member', 'system_admin']390class ProjectReaderTests(ProjectAdminTests):...
test_policy_association_rbac.py
Source:test_policy_association_rbac.py
...58 @rbac_rule_validation.action(59 service="keystone",60 rules=["identity:check_policy_association_for_endpoint"])61 @decorators.idempotent_id('25ce8c89-e751-465c-8d35-52bacd774beb')62 def test_show_policy_association_for_endpoint(self):63 self._update_policy_association_for_endpoint(64 self.policy_id, self.endpoint_id)65 with self.override_role():66 self.policies_client.show_policy_association_for_endpoint(67 self.policy_id, self.endpoint_id)68 @rbac_rule_validation.action(69 service="keystone",70 rules=["identity:delete_policy_association_for_endpoint"])71 @decorators.idempotent_id('95cad2d8-bcd0-4c4e-a8f7-cc80601e43a1')72 def test_delete_policy_association_for_endpoint(self):73 self._update_policy_association_for_endpoint(74 self.policy_id, self.endpoint_id)75 with self.override_role():76 self.policies_client.delete_policy_association_for_endpoint(77 self.policy_id, self.endpoint_id)78 @rbac_rule_validation.action(79 service="keystone",80 rules=["identity:create_policy_association_for_service"])...
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!!