Best Python code snippet using tempest_python
test_auth.py
Source:test_auth.py  
...108                                      replacement=None):109        if replacement:110            return ep[endpoint_type].replace('v2', replacement)111        return ep[endpoint_type]112    def _get_token_from_fake_identity(self):113        return fake_identity.TOKEN114    def _get_from_fake_identity(self, attr):115        access = fake_identity.IDENTITY_V2_RESPONSE['access']116        if attr == 'user_id':117            return access['user']['id']118        elif attr == 'tenant_id':119            return access['token']['tenant']['id']120    def _test_request_helper(self, filters, expected):121        url, headers, body = self.auth_provider.auth_request('GET',122                                                             self.target_url,123                                                             filters=filters)124        self.assertEqual(expected['url'], url)125        self.assertEqual(expected['token'], headers['X-Auth-Token'])126        self.assertEqual(expected['body'], body)127    def _auth_data_with_expiry(self, date_as_string):128        token, access = self.auth_provider.auth_data129        access['token']['expires'] = date_as_string130        return token, access131    def test_request(self):132        filters = {133            'service': 'compute',134            'endpoint_type': 'publicURL',135            'region': 'FakeRegion'136        }137        url = self._get_result_url_from_endpoint(138            self._endpoints[0]['endpoints'][1]) + '/' + self.target_url139        expected = {140            'body': None,141            'url': url,142            'token': self._get_token_from_fake_identity(),143        }144        self._test_request_helper(filters, expected)145    def test_request_with_alt_auth_cleans_alt(self):146        self.auth_provider.set_alt_auth_data(147            'body',148            (fake_identity.ALT_TOKEN, self._get_fake_alt_identity()))149        self.test_request()150        # Assert alt auth data is clear after it151        self.assertIsNone(self.auth_provider.alt_part)152        self.assertIsNone(self.auth_provider.alt_auth_data)153    def test_request_with_alt_part_without_alt_data(self):154        """155        Assert that when alt_part is defined, the corresponding original156        request element is kept the same.157        """158        filters = {159            'service': 'compute',160            'endpoint_type': 'publicURL',161            'region': 'fakeRegion'162        }163        self.auth_provider.set_alt_auth_data('url', None)164        url, headers, body = self.auth_provider.auth_request('GET',165                                                             self.target_url,166                                                             filters=filters)167        self.assertEqual(url, self.target_url)168        self.assertEqual(self._get_token_from_fake_identity(),169                         headers['X-Auth-Token'])170        self.assertEqual(body, None)171    def test_request_with_bad_service(self):172        filters = {173            'service': 'BAD_SERVICE',174            'endpoint_type': 'publicURL',175            'region': 'fakeRegion'176        }177        self.assertRaises(exceptions.EndpointNotFound,178                          self.auth_provider.auth_request, 'GET',179                          self.target_url, filters=filters)180    def test_request_without_service(self):181        filters = {182            'service': None,...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!!
