def test_auth_settings_calls_get_api_key_with_prefix(self): expected_token = 'expected_token' def fake_get_api_key_with_prefix(identifier): self.assertEqual('authorization', identifier) return expected_token config = Configuration() config.get_api_key_with_prefix = fake_get_api_key_with_prefix self.assertEqual(expected_token, config.auth_settings()['BearerToken']['value'])
def test_refresh_token(self): loader = self.get_test_loader() loader._token_refresh_period = datetime.timedelta(seconds=5) loader.load_and_set() config = Configuration() self.assertEqual('bearer ' + _TEST_TOKEN, config.get_api_key_with_prefix('authorization')) self.assertEqual(_TEST_TOKEN, loader.token) self.assertIsNotNone(loader.token_expires_at) old_token = loader.token old_token_expires_at = loader.token_expires_at self._overwrite_file_with_content(loader._token_filename, _TEST_NEW_TOKEN) time.sleep(5) self.assertEqual('bearer ' + _TEST_NEW_TOKEN, config.get_api_key_with_prefix('authorization')) self.assertEqual(_TEST_NEW_TOKEN, loader.token) self.assertGreater(loader.token_expires_at, old_token_expires_at)
def test_refresh_token(self): loader = self.get_test_loader() config = Configuration() loader.load_and_set(config) self.assertEqual('bearer ' + _TEST_TOKEN, config.get_api_key_with_prefix('authorization')) self.assertEqual('bearer ' + _TEST_TOKEN, loader.token) self.assertIsNotNone(loader.token_expires_at) old_token = loader.token old_token_expires_at = loader.token_expires_at loader._token_filename = self._create_file_with_temp_content( _TEST_NEW_TOKEN) self.assertEqual('bearer ' + _TEST_TOKEN, config.get_api_key_with_prefix('authorization')) loader.token_expires_at = datetime.datetime.now() self.assertEqual('bearer ' + _TEST_NEW_TOKEN, config.get_api_key_with_prefix('authorization')) self.assertEqual('bearer ' + _TEST_NEW_TOKEN, loader.token) self.assertGreater(loader.token_expires_at, old_token_expires_at)
def test_get_api_key_with_prefix_returns_token(self): expected_token = 'expected_token' config = Configuration() config.api_key['authorization'] = expected_token self.assertEqual(expected_token, config.get_api_key_with_prefix('authorization'))
def get_api_key_with_prefix(self, identifier): if self.refresh_api_key: self.refresh_api_key(self) # pylint: disable=E1102 return Configuration.get_api_key_with_prefix(self, identifier)
def get_api_key_with_prefix(self, identifier): if self.refresh_api_key: self.refresh_api_key(self) return Configuration.get_api_key_with_prefix(self, identifier)