Best Python code snippet using tempest_python
test_qos.py
Source:test_qos.py
...774 def test_rule_create(self):775 policy = self.create_qos_policy(name='test-policy',776 description='test policy',777 shared=False)778 rule = self.admin_client.create_minimum_bandwidth_rule(779 policy_id=policy['id'],780 direction=self.DIRECTION_EGRESS,781 min_kbps=1138)[self.RULE_NAME]782 # Test 'show rule'783 retrieved_rule = self.admin_client.show_minimum_bandwidth_rule(784 policy['id'], rule['id'])785 retrieved_rule = retrieved_rule[self.RULE_NAME]786 self.assertEqual(rule['id'], retrieved_rule['id'])787 self.assertEqual(1138, retrieved_rule['min_kbps'])788 self.assertEqual(self.DIRECTION_EGRESS, retrieved_rule['direction'])789 # Test 'list rules'790 rules = self.admin_client.list_minimum_bandwidth_rules(policy['id'])791 rules = rules[self.RULES_NAME]792 rules_ids = [r['id'] for r in rules]793 self.assertIn(rule['id'], rules_ids)794 # Test 'show policy'795 retrieved_policy = self.admin_client.show_qos_policy(policy['id'])796 policy_rules = retrieved_policy['policy']['rules']797 self.assertEqual(1, len(policy_rules))798 self.assertEqual(rule['id'], policy_rules[0]['id'])799 self.assertEqual(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH,800 policy_rules[0]['type'])801 @test.idempotent_id('266d9b87-e51c-48bd-9aa7-8269573621be')802 def test_rule_create_fail_for_missing_min_kbps(self):803 policy = self.create_qos_policy(name='test-policy',804 description='test policy',805 shared=False)806 self.assertRaises(exceptions.BadRequest,807 self.admin_client.create_minimum_bandwidth_rule,808 policy_id=policy['id'],809 direction=self.DIRECTION_EGRESS)810 @test.idempotent_id('aa59b00b-ab01-4787-92f8-93a5cdf5e378')811 def test_rule_create_fail_for_the_same_type(self):812 policy = self.create_qos_policy(name='test-policy',813 description='test policy',814 shared=False)815 self.admin_client.create_minimum_bandwidth_rule(816 policy_id=policy['id'],817 direction=self.DIRECTION_EGRESS, min_kbps=200)818 self.assertRaises(exceptions.Conflict,819 self.admin_client.create_minimum_bandwidth_rule,820 policy_id=policy['id'],821 direction=self.DIRECTION_EGRESS, min_kbps=201)822 @test.idempotent_id('d6fce764-e511-4fa6-9f86-f4b41cf142cf')823 def test_rule_create_fail_for_direction_ingress(self):824 policy = self.create_qos_policy(name='test-policy',825 description='test policy',826 shared=False)827 self.assertRaises(exceptions.BadRequest,828 self.admin_client.create_minimum_bandwidth_rule,829 policy_id=policy['id'],830 direction=self.DIRECTION_INGRESS,831 min_kbps=201)832 @test.idempotent_id('a49a6988-2568-47d2-931e-2dbc858943b3')833 def test_rule_update(self):834 policy = self.create_qos_policy(name='test-policy',835 description='test policy',836 shared=False)837 rule = self.admin_client.create_minimum_bandwidth_rule(838 policy_id=policy['id'],839 direction=self.DIRECTION_EGRESS,840 min_kbps=300)[self.RULE_NAME]841 self.admin_client.update_minimum_bandwidth_rule(policy['id'],842 rule['id'], min_kbps=350, direction=self.DIRECTION_EGRESS)843 retrieved_policy = self.admin_client.show_minimum_bandwidth_rule(844 policy['id'], rule['id'])845 retrieved_policy = retrieved_policy[self.RULE_NAME]846 self.assertEqual(350, retrieved_policy['min_kbps'])847 self.assertEqual(self.DIRECTION_EGRESS, retrieved_policy['direction'])848 @test.idempotent_id('a7ee6efd-7b33-4a68-927d-275b4f8ba958')849 def test_rule_delete(self):850 policy = self.create_qos_policy(name='test-policy',851 description='test policy',852 shared=False)853 rule = self.admin_client.create_minimum_bandwidth_rule(854 policy['id'], self.DIRECTION_EGRESS, min_kbps=200)[self.RULE_NAME]855 retrieved_policy = self.admin_client.show_minimum_bandwidth_rule(856 policy['id'], rule['id'])857 retrieved_policy = retrieved_policy[self.RULE_NAME]858 self.assertEqual(rule['id'], retrieved_policy['id'])859 self.admin_client.delete_minimum_bandwidth_rule(policy['id'],860 rule['id'])861 self.assertRaises(exceptions.NotFound,862 self.admin_client.show_minimum_bandwidth_rule,863 policy['id'], rule['id'])864 @test.idempotent_id('a211222c-5808-46cb-a961-983bbab6b852')865 def test_rule_create_rule_nonexistent_policy(self):866 self.assertRaises(867 exceptions.NotFound,868 self.admin_client.create_minimum_bandwidth_rule,869 'policy', self.DIRECTION_EGRESS, min_kbps=200)870 @test.idempotent_id('b4a2e7ad-786f-4927-a85a-e545a93bd274')871 def test_rule_create_forbidden_for_regular_tenants(self):872 self.assertRaises(873 exceptions.Forbidden,874 self.client.create_minimum_bandwidth_rule,875 'policy', self.DIRECTION_EGRESS, min_kbps=300)876 @test.idempotent_id('de0bd0c2-54d9-4e29-85f1-cfb36ac3ebe2')877 def test_get_rules_by_policy(self):878 policy1 = self.create_qos_policy(name='test-policy1',879 description='test policy1',880 shared=False)881 rule1 = self.admin_client.create_minimum_bandwidth_rule(882 policy_id=policy1['id'],883 direction=self.DIRECTION_EGRESS,884 min_kbps=200)[self.RULE_NAME]885 policy2 = self.create_qos_policy(name='test-policy2',886 description='test policy2',887 shared=False)888 rule2 = self.admin_client.create_minimum_bandwidth_rule(889 policy_id=policy2['id'],890 direction=self.DIRECTION_EGRESS,891 min_kbps=5000)[self.RULE_NAME]892 # Test 'list rules'893 rules = self.admin_client.list_minimum_bandwidth_rules(policy1['id'])894 rules = rules[self.RULES_NAME]895 rules_ids = [r['id'] for r in rules]896 self.assertIn(rule1['id'], rules_ids)897 self.assertNotIn(rule2['id'], rules_ids)898class QosSearchCriteriaTest(base.BaseSearchCriteriaTest,899 base.BaseAdminNetworkTest):900 resource = 'policy'901 plural_name = 'policies'902 # Use unique description to isolate the tests from other QoS tests...
test_policy_minimum_bandwidth_rule_rbac.py
Source:test_policy_minimum_bandwidth_rule_rbac.py
...33 name=name)["policy"]["id"]34 cls.addClassResourceCleanup(test_utils.call_and_ignore_notfound_exc,35 cls.ntp_client.delete_qos_policy,36 cls.policy_id)37 def create_minimum_bandwidth_rule(self):38 rule = self.ntp_client.create_minimum_bandwidth_rule(39 self.policy_id, direction="egress", min_kbps=1000)40 rule_id = rule['minimum_bandwidth_rule']['id']41 self.addCleanup(test_utils.call_and_ignore_notfound_exc,42 self.ntp_client.delete_minimum_bandwidth_rule,43 self.policy_id, rule_id)44 return rule_id45 @decorators.idempotent_id('25B5EF3A-DF2A-4C80-A498-3BE14A321D97')46 @rbac_rule_validation.action(47 service="neutron", rules=["create_policy_minimum_bandwidth_rule"])48 def test_create_policy_minimum_bandwidth_rule(self):49 """Create policy_minimum_bandwidth_rule.50 RBAC test for the neutron "create_policy_minimum_bandwidth_rule" policy51 """52 with self.override_role():53 self.create_minimum_bandwidth_rule()54 @decorators.idempotent_id('01DD902C-47C5-45D2-9A0E-7AF05981DF21')55 @rbac_rule_validation.action(service="neutron",56 rules=["get_policy_minimum_bandwidth_rule"],57 expected_error_codes=[404])58 def test_show_policy_minimum_bandwidth_rule(self):59 """Show policy_minimum_bandwidth_rule.60 RBAC test for the neutron "get_policy_minimum_bandwidth_rule" policy61 """62 rule_id = self.create_minimum_bandwidth_rule()63 with self.override_role():64 self.ntp_client.show_minimum_bandwidth_rule(65 self.policy_id, rule_id)66 @decorators.idempotent_id('50AFE69B-455C-413A-BDC6-26B42DC8D55D')67 @rbac_rule_validation.action(68 service="neutron",69 rules=["get_policy_minimum_bandwidth_rule",70 "update_policy_minimum_bandwidth_rule"],71 expected_error_codes=[404, 403])72 def test_update_policy_minimum_bandwidth_rule(self):73 """Update policy_minimum_bandwidth_rule.74 RBAC test for the neutron "update_policy_minimum_bandwidth_rule" policy75 """76 rule_id = self.create_minimum_bandwidth_rule()77 with self.override_role():78 self.ntp_client.update_minimum_bandwidth_rule(79 self.policy_id, rule_id, min_kbps=2000)80 @decorators.idempotent_id('2112E325-C3B2-4071-8A93-B218F275A83B')81 @rbac_rule_validation.action(82 service="neutron",83 rules=["get_policy_minimum_bandwidth_rule",84 "delete_policy_minimum_bandwidth_rule"],85 expected_error_codes=[404, 403])86 def test_delete_policy_minimum_bandwidth_rule(self):87 """Delete policy_minimum_bandwidth_rule.88 RBAC test for the neutron "delete_policy_minimum_bandwidth_rule" policy89 """90 rule_id = self.create_minimum_bandwidth_rule()91 with self.override_role():92 self.ntp_client.delete_minimum_bandwidth_rule(...
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!!