Best Python code snippet using tempest_python
test_trusts.py
Source:test_trusts.py
...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=False176 trust = self.create_trust(impersonate=False)177 self.validate_trust(trust, impersonate=False)178 trust_get = self.get_trust()179 self.validate_trust(trust_get, impersonate=False)180 self.check_trust_roles()181 @test.attr(type='smoke')182 def test_trust_expire(self):183 # Test case to check we can create, get and delete a trust184 # with an expiry specified185 expires_at = timeutils.utcnow() + datetime.timedelta(hours=1)186 expires_str = timeutils.isotime(at=expires_at, subsecond=True)187 trust = self.create_trust(expires=expires_str)188 self.validate_trust(trust, expires=expires_str)189 trust_get = self.get_trust()190 self.validate_trust(trust_get, expires=expires_str)191 self.check_trust_roles()192 @test.attr(type='smoke')193 def test_trust_expire_invalid(self):194 # Test case to check we can check an invlaid expiry time195 # is rejected with the correct error196 # with an expiry specified197 expires_str = 'bad.123Z'198 self.assertRaises(exceptions.BadRequest,199 self.create_trust,200 expires=expires_str)201 @test.attr(type='smoke')202 def test_get_trusts_query(self):203 self.create_trust()204 _, trusts_get = self.trustor_client.get_trusts(205 trustor_user_id=self.trustor_user_id)206 self.assertEqual(1, len(trusts_get))207 self.validate_trust(trusts_get[0], summary=True)208 @test.attr(type='smoke')209 def test_get_trusts_all(self):210 self.create_trust()211 _, trusts_get = self.client.get_trusts()212 trusts = [t for t in trusts_get213 if t['id'] == self.trust_id]214 self.assertEqual(1, len(trusts))...
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!!