本文整理汇总了Python中st2client.shell.Shell._cache_auth_token方法的典型用法代码示例。如果您正苦于以下问题:Python Shell._cache_auth_token方法的具体用法?Python Shell._cache_auth_token怎么用?Python Shell._cache_auth_token使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类st2client.shell.Shell
的用法示例。
在下文中一共展示了Shell._cache_auth_token方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_cache_auth_token_success
# 需要导入模块: from st2client.shell import Shell [as 别名]
# 或者: from st2client.shell.Shell import _cache_auth_token [as 别名]
def test_cache_auth_token_success(self):
client = Client()
shell = Shell()
username = 'testu'
password = 'testp'
expiry = datetime.datetime.utcnow() + datetime.timedelta(seconds=30)
result = shell._get_cached_auth_token(client=client, username=username,
password=password)
self.assertEqual(result, None)
token_db = TokenDB(user=username, token='fyeah', expiry=expiry)
shell._cache_auth_token(token_obj=token_db)
result = shell._get_cached_auth_token(client=client, username=username,
password=password)
self.assertEqual(result, 'fyeah')
示例2: test_cache_auth_token_invalid_permissions
# 需要导入模块: from st2client.shell import Shell [as 别名]
# 或者: from st2client.shell.Shell import _cache_auth_token [as 别名]
def test_cache_auth_token_invalid_permissions(self):
shell = Shell()
username = 'testu'
cached_token_path = shell._get_cached_token_path_for_user(username=username)
expiry = datetime.datetime.utcnow() + datetime.timedelta(seconds=30)
token_db = TokenDB(user=username, token='fyeah', expiry=expiry)
cached_token_path = shell._get_cached_token_path_for_user(username=username)
data = {
'token': 'yayvalid',
'expire_timestamp': (int(time.time()) + 20)
}
with open(cached_token_path, 'w') as fp:
fp.write(json.dumps(data))
# 1. Current user has no write access to the parent directory
os.chmod(self._mock_config_directory_path, 0000)
shell.LOG = mock.Mock()
shell._cache_auth_token(token_obj=token_db)
self.assertEqual(shell.LOG.warn.call_count, 1)
log_message = shell.LOG.warn.call_args[0][0]
expected_msg = ('Unable to write token to .*? doesn\'t have write access to the parent '
'directory')
self.assertRegexpMatches(log_message, expected_msg)
# 2. Current user has no write access to the cached token file
os.chmod(self._mock_config_directory_path, 0777) # nosec
os.chmod(cached_token_path, 0000)
shell.LOG = mock.Mock()
shell._cache_auth_token(token_obj=token_db)
self.assertEqual(shell.LOG.warn.call_count, 1)
log_message = shell.LOG.warn.call_args[0][0]
expected_msg = ('Unable to write token to .*? doesn\'t have write access to this file')
self.assertRegexpMatches(log_message, expected_msg)