How to use _get_fake_alt_identity method in tempest

Best Python code snippet using tempest_python

test_auth.py

Source:test_auth.py Github

copy

Full Screen

...101 super(TestKeystoneV2AuthProvider, self).setUp()102 self.stubs.Set(http.ClosingHttp, 'request',103 fake_identity._fake_v2_response)104 self.target_url = 'test_api'105 def _get_fake_alt_identity(self):106 return fake_identity.ALT_IDENTITY_V2_RESPONSE['access']107 def _get_result_url_from_endpoint(self, ep, endpoint_type='publicURL',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,183 'endpoint_type': 'publicURL',184 'region': 'fakeRegion'185 }186 self.assertRaises(exceptions.EndpointNotFound,187 self.auth_provider.auth_request, 'GET',188 self.target_url, filters=filters)189 def test_check_credentials_missing_attribute(self):190 for attr in ['username', 'password']:191 cred = copy.copy(self.credentials)192 del cred[attr]193 self.assertFalse(self.auth_provider.check_credentials(cred))194 def test_fill_credentials(self):195 self.auth_provider.fill_credentials()196 creds = self.auth_provider.credentials197 for attr in ['user_id', 'tenant_id']:198 self.assertEqual(self._get_from_fake_identity(attr),199 getattr(creds, attr))200 def _test_base_url_helper(self, expected_url, filters,201 auth_data=None):202 url = self.auth_provider.base_url(filters, auth_data)203 self.assertEqual(url, expected_url)204 def test_base_url(self):205 self.filters = {206 'service': 'compute',207 'endpoint_type': 'publicURL',208 'region': 'FakeRegion'209 }210 expected = self._get_result_url_from_endpoint(211 self._endpoints[0]['endpoints'][1])212 self._test_base_url_helper(expected, self.filters)213 def test_base_url_to_get_admin_endpoint(self):214 self.filters = {215 'service': 'compute',216 'endpoint_type': 'adminURL',217 'region': 'FakeRegion'218 }219 expected = self._get_result_url_from_endpoint(220 self._endpoints[0]['endpoints'][1], endpoint_type='adminURL')221 self._test_base_url_helper(expected, self.filters)222 def test_base_url_unknown_region(self):223 """224 Assure that if the region is unknow the first endpoint is returned.225 """226 self.filters = {227 'service': 'compute',228 'endpoint_type': 'publicURL',229 'region': 'AintNoBodyKnowThisRegion'230 }231 expected = self._get_result_url_from_endpoint(232 self._endpoints[0]['endpoints'][0])233 self._test_base_url_helper(expected, self.filters)234 def test_base_url_with_non_existent_service(self):235 self.filters = {236 'service': 'BAD_SERVICE',237 'endpoint_type': 'publicURL',238 'region': 'FakeRegion'239 }240 self.assertRaises(exceptions.EndpointNotFound,241 self._test_base_url_helper, None, self.filters)242 def test_base_url_without_service(self):243 self.filters = {244 'endpoint_type': 'publicURL',245 'region': 'FakeRegion'246 }247 self.assertRaises(exceptions.EndpointNotFound,248 self._test_base_url_helper, None, self.filters)249 def test_base_url_with_api_version_filter(self):250 self.filters = {251 'service': 'compute',252 'endpoint_type': 'publicURL',253 'region': 'FakeRegion',254 'api_version': 'v12'255 }256 expected = self._get_result_url_from_endpoint(257 self._endpoints[0]['endpoints'][1], replacement='v12')258 self._test_base_url_helper(expected, self.filters)259 def test_base_url_with_skip_path_filter(self):260 self.filters = {261 'service': 'compute',262 'endpoint_type': 'publicURL',263 'region': 'FakeRegion',264 'skip_path': True265 }266 expected = 'http://fake_url/'267 self._test_base_url_helper(expected, self.filters)268 def test_token_not_expired(self):269 expiry_data = datetime.datetime.utcnow() + datetime.timedelta(days=1)270 auth_data = self._auth_data_with_expiry(271 expiry_data.strftime(self.auth_provider.EXPIRY_DATE_FORMAT))272 self.assertFalse(self.auth_provider.is_expired(auth_data))273 def test_token_expired(self):274 expiry_data = datetime.datetime.utcnow() - datetime.timedelta(hours=1)275 auth_data = self._auth_data_with_expiry(276 expiry_data.strftime(self.auth_provider.EXPIRY_DATE_FORMAT))277 self.assertTrue(self.auth_provider.is_expired(auth_data))278 def test_token_not_expired_to_be_renewed(self):279 expiry_data = datetime.datetime.utcnow() + \280 self.auth_provider.token_expiry_threshold / 2281 auth_data = self._auth_data_with_expiry(282 expiry_data.strftime(self.auth_provider.EXPIRY_DATE_FORMAT))283 self.assertTrue(self.auth_provider.is_expired(auth_data))284class TestKeystoneV3AuthProvider(TestKeystoneV2AuthProvider):285 _endpoints = fake_identity.IDENTITY_V3_RESPONSE['token']['catalog']286 _auth_provider_class = auth.KeystoneV3AuthProvider287 credentials = fake_credentials.FakeKeystoneV3Credentials()288 def setUp(self):289 super(TestKeystoneV3AuthProvider, self).setUp()290 self.stubs.Set(http.ClosingHttp, 'request',291 fake_identity._fake_v3_response)292 def _get_fake_alt_identity(self):293 return fake_identity.ALT_IDENTITY_V3['token']294 def _get_result_url_from_endpoint(self, ep, replacement=None):295 if replacement:296 return ep['url'].replace('v3', replacement)297 return ep['url']298 def _auth_data_with_expiry(self, date_as_string):299 token, access = self.auth_provider.auth_data300 access['expires_at'] = date_as_string301 return token, access302 def _get_from_fake_identity(self, attr):303 token = fake_identity.IDENTITY_V3_RESPONSE['token']304 if attr == 'user_id':305 return token['user']['id']306 elif attr == 'project_id':...

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