Best Python code snippet using tempest_python
test_policies.py
Source:test_policies.py
...15from tempest.api.identity import base16from tempest.common.utils import data_utils17from tempest import test18class PoliciesTestJSON(base.BaseIdentityV3AdminTest):19 def _delete_policy(self, policy_id):20 self.policies_client.delete_policy(policy_id)21 @test.idempotent_id('1a0ad286-2d06-4123-ab0d-728893a76201')22 def test_list_policies(self):23 # Test to list policies24 policy_ids = list()25 fetched_ids = list()26 for _ in range(3):27 blob = data_utils.rand_name('BlobName')28 policy_type = data_utils.rand_name('PolicyType')29 policy = self.policies_client.create_policy(30 blob=blob, type=policy_type)['policy']31 # Delete the Policy at the end of this method32 self.addCleanup(self._delete_policy, policy['id'])33 policy_ids.append(policy['id'])34 # List and Verify Policies35 body = self.policies_client.list_policies()['policies']36 for p in body:37 fetched_ids.append(p['id'])38 missing_pols = [p for p in policy_ids if p not in fetched_ids]39 self.assertEqual(0, len(missing_pols))40 @test.attr(type='smoke')41 @test.idempotent_id('e544703a-2f03-4cf2-9b0f-350782fdb0d3')42 def test_create_update_delete_policy(self):43 # Test to update policy44 blob = data_utils.rand_name('BlobName')45 policy_type = data_utils.rand_name('PolicyType')46 policy = self.policies_client.create_policy(blob=blob,47 type=policy_type)['policy']48 self.addCleanup(self._delete_policy, policy['id'])49 self.assertIn('id', policy)50 self.assertIn('type', policy)51 self.assertIn('blob', policy)52 self.assertIsNotNone(policy['id'])53 self.assertEqual(blob, policy['blob'])54 self.assertEqual(policy_type, policy['type'])55 # Update policy56 update_type = data_utils.rand_name('UpdatedPolicyType')...
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!!