Best Python code snippet using tempest_python
test_subnet.py
Source:test_subnet.py  
...70                           'get_subnet:segment_id', self.target))71        self.assertTrue(72            policy.enforce(self.context,73                           'get_subnet:segment_id', self.alt_target))74    def test_update_subnet(self):75        self.assertTrue(76            policy.enforce(self.context, 'update_subnet', self.target))77        self.assertTrue(78            policy.enforce(self.context, 'update_subnet', self.alt_target))79    def test_update_subnet_segment_id(self):80        self.assertTrue(81            policy.enforce(self.context,82                           'update_subnet:segment_id', self.target))83        self.assertTrue(84            policy.enforce(self.context,85                           'update_subnet:segment_id', self.alt_target))86    def test_update_subnet_service_types(self):87        self.assertTrue(88            policy.enforce(self.context,89                           'update_subnet:service_types', self.target))90        self.assertTrue(91            policy.enforce(self.context,92                           'update_subnet:service_types', self.alt_target))93    def test_delete_subnet(self):94        self.assertTrue(95            policy.enforce(self.context, 'delete_subnet', self.target))96        self.assertTrue(97            policy.enforce(self.context, 'delete_subnet', self.alt_target))98class SystemMemberTests(SystemAdminTests):99    def setUp(self):100        super(SystemMemberTests, self).setUp()101        self.context = self.system_member_ctx102    def test_create_subnet(self):103        self.assertRaises(104            base_policy.PolicyNotAuthorized,105            policy.enforce,106            self.context, 'create_subnet', self.target)107        self.assertRaises(108            base_policy.PolicyNotAuthorized,109            policy.enforce,110            self.context, 'create_subnet', self.alt_target)111    def test_create_subnet_segment_id(self):112        self.assertRaises(113            base_policy.PolicyNotAuthorized,114            policy.enforce,115            self.context, 'create_subnet:segment_id', self.target)116        self.assertRaises(117            base_policy.PolicyNotAuthorized,118            policy.enforce,119            self.context, 'create_subnet:segment_id', self.alt_target)120    def test_create_subnet_service_types(self):121        self.assertRaises(122            base_policy.PolicyNotAuthorized,123            policy.enforce,124            self.context, 'create_subnet:service_types', self.target)125        self.assertRaises(126            base_policy.PolicyNotAuthorized,127            policy.enforce,128            self.context, 'create_subnet:service_types', self.alt_target)129    def test_update_subnet(self):130        self.assertRaises(131            base_policy.PolicyNotAuthorized,132            policy.enforce,133            self.context, 'update_subnet', self.target)134        self.assertRaises(135            base_policy.PolicyNotAuthorized,136            policy.enforce,137            self.context, 'update_subnet', self.alt_target)138    def test_update_subnet_segment_id(self):139        self.assertRaises(140            base_policy.PolicyNotAuthorized,141            policy.enforce,142            self.context, 'update_subnet:segment_id', self.target)143        self.assertRaises(144            base_policy.PolicyNotAuthorized,145            policy.enforce,146            self.context, 'update_subnet:segment_id', self.alt_target)147    def test_update_subnet_service_types(self):148        self.assertRaises(149            base_policy.PolicyNotAuthorized,150            policy.enforce,151            self.context, 'update_subnet:service_types', self.target)152        self.assertRaises(153            base_policy.PolicyNotAuthorized,154            policy.enforce,155            self.context, 'update_subnet:service_types', self.alt_target)156    def test_delete_subnet(self):157        self.assertRaises(158            base_policy.PolicyNotAuthorized,159            policy.enforce,160            self.context, 'delete_subnet', self.target)161        self.assertRaises(162            base_policy.PolicyNotAuthorized,163            policy.enforce,164            self.context, 'delete_subnet', self.alt_target)165class SystemReaderTests(SystemMemberTests):166    def setUp(self):167        super(SystemReaderTests, self).setUp()168        self.context = self.system_reader_ctx169class ProjectAdminTests(SubnetAPITestCase):170    def setUp(self):171        super(ProjectAdminTests, self).setUp()172        self.context = self.project_admin_ctx173    def test_create_subnet(self):174        self.assertTrue(175            policy.enforce(self.context, 'create_subnet', self.target))176        self.assertRaises(177            base_policy.PolicyNotAuthorized,178            policy.enforce,179            self.context, 'create_subnet', self.alt_target)180    def test_create_subnet_segment_id(self):181        self.assertRaises(182            base_policy.PolicyNotAuthorized,183            policy.enforce,184            self.context, 'create_subnet:segment_id', self.target)185        self.assertRaises(186            base_policy.PolicyNotAuthorized,187            policy.enforce,188            self.context, 'create_subnet:segment_id', self.alt_target)189    def test_create_subnet_service_types(self):190        self.assertRaises(191            base_policy.PolicyNotAuthorized,192            policy.enforce,193            self.context, 'create_subnet:service_types', self.target)194        self.assertRaises(195            base_policy.PolicyNotAuthorized,196            policy.enforce,197            self.context, 'create_subnet:service_types', self.alt_target)198    def test_get_subnet(self):199        self.assertTrue(200            policy.enforce(self.context, 'get_subnet', self.target))201        self.assertRaises(202            base_policy.PolicyNotAuthorized,203            policy.enforce,204            self.context, 'get_subnet', self.alt_target)205    def test_get_subnet_segment_id(self):206        self.assertRaises(207            base_policy.PolicyNotAuthorized,208            policy.enforce,209            self.context, 'get_subnet:segment_id', self.target)210        self.assertRaises(211            base_policy.PolicyNotAuthorized,212            policy.enforce,213            self.context, 'get_subnet:segment_id', self.alt_target)214    def test_update_subnet(self):215        self.assertTrue(216            policy.enforce(self.context, 'update_subnet', self.target))217        self.assertRaises(218            base_policy.PolicyNotAuthorized,219            policy.enforce,220            self.context, 'update_subnet', self.alt_target)221    def test_update_subnet_segment_id(self):222        self.assertRaises(223            base_policy.PolicyNotAuthorized,224            policy.enforce,225            self.context, 'update_subnet:segment_id', self.target)226        self.assertRaises(227            base_policy.PolicyNotAuthorized,228            policy.enforce,229            self.context, 'update_subnet:segment_id', self.alt_target)230    def test_update_subnet_service_types(self):231        self.assertRaises(232            base_policy.PolicyNotAuthorized,233            policy.enforce,234            self.context, 'update_subnet:service_types', self.target)235        self.assertRaises(236            base_policy.PolicyNotAuthorized,237            policy.enforce,238            self.context, 'update_subnet:service_types', self.alt_target)239    def test_delete_subnet(self):240        self.assertTrue(241            policy.enforce(self.context, 'delete_subnet', self.target))242        self.assertRaises(243            base_policy.PolicyNotAuthorized,244            policy.enforce,245            self.context, 'delete_subnet', self.alt_target)246class ProjectMemberTests(ProjectAdminTests):247    def setUp(self):248        super(ProjectMemberTests, self).setUp()249        self.context = self.project_member_ctx250class ProjectReaderTests(ProjectMemberTests):251    def setUp(self):252        super(ProjectReaderTests, self).setUp()253        self.context = self.project_reader_ctx254    def test_create_subnet(self):255        self.assertRaises(256            base_policy.PolicyNotAuthorized,257            policy.enforce,258            self.context, 'create_subnet', self.target)259        self.assertRaises(260            base_policy.PolicyNotAuthorized,261            policy.enforce,262            self.context, 'create_subnet', self.alt_target)263    def test_update_subnet(self):264        self.assertRaises(265            base_policy.PolicyNotAuthorized,266            policy.enforce,267            self.context, 'update_subnet', self.target)268        self.assertRaises(269            base_policy.PolicyNotAuthorized,270            policy.enforce,271            self.context, 'update_subnet', self.alt_target)272    def test_delete_subnet(self):273        self.assertRaises(274            base_policy.PolicyNotAuthorized,275            policy.enforce,276            self.context, 'delete_subnet', self.target)277        self.assertRaises(...test_subnets_rbac.py
Source:test_subnets_rbac.py  
...58        self.subnets_client.list_subnets()59    @decorators.idempotent_id('f36cd821-dd22-4bd0-b43d-110fc4b553eb')60    @rbac_rule_validation.action(service="neutron",61                                 rule="update_subnet")62    def test_update_subnet(self):63        """Update subnet.64        RBAC test for the neutron "update_subnet" policy65        """66        update_name = data_utils.rand_name(self.__class__.__name__ + '-Subnet')67        self.rbac_utils.switch_role(self, toggle_rbac_role=True)68        self.subnets_client.update_subnet(self.subnet['id'], name=update_name)69    @decorators.idempotent_id('bcfc7153-bbd1-43a4-a908-b3e1b0cde0dc')70    @rbac_rule_validation.action(service="neutron",71                                 rule="delete_subnet")72    def test_delete_subnet(self):73        """Delete subnet.74        RBAC test for the neutron "delete_subnet" policy75        """76        subnet = self.create_subnet(self.network)77        self.rbac_utils.switch_role(self, toggle_rbac_role=True)...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!!
