How to use test_check_credentials_missing_attribute method in tempest

Best Python code snippet using tempest_python

test_auth.py

Source:test_auth.py Github

copy

Full Screen

...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':307 return token['project']['id']308 elif attr == 'user_domain_id':309 return token['user']['domain']['id']310 elif attr == 'project_domain_id':311 return token['project']['domain']['id']312 def test_check_credentials_missing_attribute(self):313 # reset credentials to fresh ones314 self.credentials.reset()315 for attr in ['username', 'password', 'user_domain_name',316 'project_domain_name']:317 cred = copy.copy(self.credentials)318 del cred[attr]319 self.assertFalse(self.auth_provider.check_credentials(cred),320 "Credentials should be invalid without %s" % attr)321 def test_check_domain_credentials_missing_attribute(self):322 # reset credentials to fresh ones323 self.credentials.reset()324 domain_creds = fake_credentials.FakeKeystoneV3DomainCredentials()325 for attr in ['username', 'password', 'user_domain_name']:326 cred = copy.copy(domain_creds)...

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