How to use create_trustor_and_roles method in tempest

Best Python code snippet using tempest_python

test_trusts.py

Source:test_trusts.py Github

copy

Full Screen

...33 # Do the delete in tearDown not addCleanup - we want the test to34 # fail in the event there is a bug which causes undeletable trusts35 self.delete_trust()36 super(BaseTrustsV3Test, self).tearDown()37 def create_trustor_and_roles(self):38 # Get trustor project ID, use the admin project39 self.trustor_project_name = self.client.tenant_name40 self.trustor_project_id = self.get_tenant_by_name(41 self.trustor_project_name)['id']42 self.assertIsNotNone(self.trustor_project_id)43 # Create a trustor User44 self.trustor_username = data_utils.rand_name('user-')45 u_desc = self.trustor_username + 'description'46 u_email = self.trustor_username + '@testmail.xx'47 self.trustor_password = data_utils.rand_name('pass-')48 _, user = self.client.create_user(49 self.trustor_username,50 description=u_desc,51 password=self.trustor_password,52 email=u_email,53 project_id=self.trustor_project_id)54 self.trustor_user_id = user['id']55 # And two roles, one we'll delegate and one we won't56 self.delegated_role = data_utils.rand_name('DelegatedRole-')57 self.not_delegated_role = data_utils.rand_name('NotDelegatedRole-')58 _, role = self.client.create_role(self.delegated_role)59 self.delegated_role_id = role['id']60 _, role = self.client.create_role(self.not_delegated_role)61 self.not_delegated_role_id = role['id']62 # Assign roles to trustor63 self.client.assign_user_role(self.trustor_project_id,64 self.trustor_user_id,65 self.delegated_role_id)66 self.client.assign_user_role(self.trustor_project_id,67 self.trustor_user_id,68 self.not_delegated_role_id)69 # Get trustee user ID, use the demo user70 trustee_username = self.non_admin_client.user71 self.trustee_user_id = self.get_user_by_name(trustee_username)['id']72 self.assertIsNotNone(self.trustee_user_id)73 # Initialize a new client with the trustor credentials74 creds = auth.get_credentials(75 username=self.trustor_username,76 password=self.trustor_password,77 tenant_name=self.trustor_project_name)78 os = clients.Manager(79 credentials=creds,80 interface=self._interface)81 self.trustor_client = os.identity_v3_client82 def cleanup_user_and_roles(self):83 if self.trustor_user_id:84 self.client.delete_user(self.trustor_user_id)85 if self.delegated_role_id:86 self.client.delete_role(self.delegated_role_id)87 if self.not_delegated_role_id:88 self.client.delete_role(self.not_delegated_role_id)89 def create_trust(self, impersonate=True, expires=None):90 _, trust_create = self.trustor_client.create_trust(91 trustor_user_id=self.trustor_user_id,92 trustee_user_id=self.trustee_user_id,93 project_id=self.trustor_project_id,94 role_names=[self.delegated_role],95 impersonation=impersonate,96 expires_at=expires)97 self.trust_id = trust_create['id']98 return trust_create99 def validate_trust(self, trust, impersonate=True, expires=None,100 summary=False):101 self.assertIsNotNone(trust['id'])102 self.assertEqual(impersonate, trust['impersonation'])103 # FIXME(shardy): ref bug #1246383 we can't check the104 # microsecond component of the expiry time, because mysql105 # <5.6.4 doesn't support microseconds.106 # expected format 2013-12-20T16:08:36.036987Z107 if expires is not None:108 expires_nousec = re.sub(r'\.([0-9]){6}Z', '', expires)109 self.assertTrue(trust['expires_at'].startswith(expires_nousec))110 else:111 self.assertIsNone(trust['expires_at'])112 self.assertEqual(self.trustor_user_id, trust['trustor_user_id'])113 self.assertEqual(self.trustee_user_id, trust['trustee_user_id'])114 self.assertIn('v3/OS-TRUST/trusts', trust['links']['self'])115 self.assertEqual(self.trustor_project_id, trust['project_id'])116 if not summary:117 self.assertEqual(self.delegated_role, trust['roles'][0]['name'])118 self.assertEqual(1, len(trust['roles']))119 def get_trust(self):120 _, trust_get = self.trustor_client.get_trust(self.trust_id)121 return trust_get122 def validate_role(self, role):123 self.assertEqual(self.delegated_role_id, role['id'])124 self.assertEqual(self.delegated_role, role['name'])125 self.assertIn('v3/roles/%s' % self.delegated_role_id,126 role['links']['self'])127 self.assertNotEqual(self.not_delegated_role_id, role['id'])128 self.assertNotEqual(self.not_delegated_role, role['name'])129 self.assertNotIn('v3/roles/%s' % self.not_delegated_role_id,130 role['links']['self'])131 def check_trust_roles(self):132 # Check we find the delegated role133 _, roles_get = self.trustor_client.get_trust_roles(134 self.trust_id)135 self.assertEqual(1, len(roles_get))136 self.validate_role(roles_get[0])137 _, role_get = self.trustor_client.get_trust_role(138 self.trust_id, self.delegated_role_id)139 self.validate_role(role_get)140 _, role_get = self.trustor_client.check_trust_role(141 self.trust_id, self.delegated_role_id)142 # And that we don't find not_delegated_role143 self.assertRaises(exceptions.NotFound,144 self.trustor_client.get_trust_role,145 self.trust_id,146 self.not_delegated_role_id)147 self.assertRaises(exceptions.NotFound,148 self.trustor_client.check_trust_role,149 self.trust_id,150 self.not_delegated_role_id)151 def delete_trust(self):152 self.trustor_client.delete_trust(self.trust_id)153 self.assertRaises(exceptions.NotFound,154 self.trustor_client.get_trust,155 self.trust_id)156 self.trust_id = None157class TrustsV3TestJSON(BaseTrustsV3Test):158 _interface = 'json'159 def setUp(self):160 super(TrustsV3TestJSON, self).setUp()161 self.create_trustor_and_roles()162 self.addCleanup(self.cleanup_user_and_roles)163 @test.attr(type='smoke')164 def test_trust_impersonate(self):165 # Test case to check we can create, get and delete a trust166 # updates are not supported for trusts167 trust = self.create_trust()168 self.validate_trust(trust)169 trust_get = self.get_trust()170 self.validate_trust(trust_get)171 self.check_trust_roles()172 @test.attr(type='smoke')173 def test_trust_noimpersonate(self):174 # Test case to check we can create, get and delete a trust175 # with impersonation=False...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful