Best Python code snippet using tempest_python
test_trusts.py
Source:test_trusts.py  
...119        self.assertEqual(self.trustor_project_id, trust['project_id'])120        if not summary:121            self.assertEqual(self.delegated_role, trust['roles'][0]['name'])122            self.assertEqual(1, len(trust['roles']))123    def show_trust(self):124        trust_get = self.trustor_client.show_trust(self.trust_id)['trust']125        return trust_get126    def validate_role(self, role):127        self.assertEqual(self.delegated_role_id, role['id'])128        self.assertEqual(self.delegated_role, role['name'])129        self.assertIn('v3/roles/%s' % self.delegated_role_id,130                      role['links']['self'])131        self.assertNotEqual(self.not_delegated_role_id, role['id'])132        self.assertNotEqual(self.not_delegated_role, role['name'])133        self.assertNotIn('v3/roles/%s' % self.not_delegated_role_id,134                         role['links']['self'])135    def check_trust_roles(self):136        # Check we find the delegated role137        roles_get = self.trustor_client.list_trust_roles(138            self.trust_id)['roles']139        self.assertEqual(1, len(roles_get))140        self.validate_role(roles_get[0])141        role_get = self.trustor_client.show_trust_role(142            self.trust_id, self.delegated_role_id)['role']143        self.validate_role(role_get)144        role_get = self.trustor_client.check_trust_role(145            self.trust_id, self.delegated_role_id)146        # And that we don't find not_delegated_role147        self.assertRaises(lib_exc.NotFound,148                          self.trustor_client.show_trust_role,149                          self.trust_id,150                          self.not_delegated_role_id)151        self.assertRaises(lib_exc.NotFound,152                          self.trustor_client.check_trust_role,153                          self.trust_id,154                          self.not_delegated_role_id)155    def delete_trust(self):156        self.trustor_client.delete_trust(self.trust_id)157        self.assertRaises(lib_exc.NotFound,158                          self.trustor_client.show_trust,159                          self.trust_id)160        self.trust_id = None161class TrustsV3TestJSON(BaseTrustsV3Test):162    def setUp(self):163        super(TrustsV3TestJSON, self).setUp()164        self.create_trustor_and_roles()165        self.addCleanup(self.cleanup_user_and_roles)166    @test.idempotent_id('5a0a91a4-baef-4a14-baba-59bf4d7fcace')167    def test_trust_impersonate(self):168        # Test case to check we can create, get and delete a trust169        # updates are not supported for trusts170        trust = self.create_trust()171        self.validate_trust(trust)172        trust_get = self.show_trust()173        self.validate_trust(trust_get)174        self.check_trust_roles()175    @test.idempotent_id('ed2a8779-a7ac-49dc-afd7-30f32f936ed2')176    def test_trust_noimpersonate(self):177        # Test case to check we can create, get and delete a trust178        # with impersonation=False179        trust = self.create_trust(impersonate=False)180        self.validate_trust(trust, impersonate=False)181        trust_get = self.show_trust()182        self.validate_trust(trust_get, impersonate=False)183        self.check_trust_roles()184    @test.idempotent_id('0ed14b66-cefd-4b5c-a964-65759453e292')185    def test_trust_expire(self):186        # Test case to check we can create, get and delete a trust187        # with an expiry specified188        expires_at = timeutils.utcnow() + datetime.timedelta(hours=1)189        # NOTE(ylobankov) In some cases the expiry time may be rounded up190        # because of microseconds. In fact, it depends on database and its191        # version. At least MySQL 5.6.16 does this.192        # For example, when creating a trust, we will set the expiry time of193        # the trust to 2015-02-17T17:34:01.907051Z. However, if we make a GET194        # request on the trust, the response will contain the time rounded up195        # to 2015-02-17T17:34:02.000000Z. That is why we shouldn't set flag196        # "subsecond" to True when we invoke timeutils.isotime(...) to avoid197        # problems with rounding.198        expires_str = timeutils.isotime(at=expires_at)199        trust = self.create_trust(expires=expires_str)200        self.validate_trust(trust, expires=expires_str)201        trust_get = self.show_trust()202        self.validate_trust(trust_get, expires=expires_str)203        self.check_trust_roles()204    @test.idempotent_id('3e48f95d-e660-4fa9-85e0-5a3d85594384')205    def test_trust_expire_invalid(self):206        # Test case to check we can check an invalid expiry time207        # is rejected with the correct error208        # with an expiry specified209        expires_str = 'bad.123Z'210        self.assertRaises(lib_exc.BadRequest,211                          self.create_trust,212                          expires=expires_str)213    @test.idempotent_id('6268b345-87ca-47c0-9ce3-37792b43403a')214    def test_get_trusts_query(self):215        self.create_trust()...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!!
