本文整理汇总了Python中st2common.models.api.auth.TokenAPI.to_model方法的典型用法代码示例。如果您正苦于以下问题:Python TokenAPI.to_model方法的具体用法?Python TokenAPI.to_model怎么用?Python TokenAPI.to_model使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类st2common.models.api.auth.TokenAPI
的用法示例。
在下文中一共展示了TokenAPI.to_model方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_token_model
# 需要导入模块: from st2common.models.api.auth import TokenAPI [as 别名]
# 或者: from st2common.models.api.auth.TokenAPI import to_model [as 别名]
def test_token_model(self):
dt = isotime.add_utc_tz(datetime.datetime.utcnow())
tk1 = TokenAPI(user='stanley', token=uuid.uuid4().hex,
expiry=isotime.format(dt, offset=False))
tkdb1 = TokenAPI.to_model(tk1)
self.assertIsNotNone(tkdb1)
self.assertIsInstance(tkdb1, TokenDB)
self.assertEqual(tkdb1.user, tk1.user)
self.assertEqual(tkdb1.token, tk1.token)
self.assertEqual(tkdb1.expiry, isotime.parse(tk1.expiry))
tkdb2 = Token.add_or_update(tkdb1)
self.assertEqual(tkdb1, tkdb2)
self.assertIsNotNone(tkdb2.id)
tk2 = TokenAPI.from_model(tkdb2)
self.assertEqual(tk2.user, tk1.user)
self.assertEqual(tk2.token, tk1.token)
self.assertEqual(tk2.expiry, tk1.expiry)
示例2: TokenAPI
# 需要导入模块: from st2common.models.api.auth import TokenAPI [as 别名]
# 或者: from st2common.models.api.auth.TokenAPI import to_model [as 别名]
WF2_SPEC = FIXTURES['workflows'][WF2_YAML_FILE_NAME]
WF2_YAML = yaml.safe_dump(WF2_SPEC, default_flow_style=False)
WF2_NAME = '%s.%s' % (PACK, WF2_YAML_FILE_NAME.replace('.yaml', ''))
WF2 = workflows.Workflow(None, {'name': WF2_NAME, 'definition': WF2_YAML})
WF2_EXEC = copy.deepcopy(MISTRAL_EXECUTION)
WF2_EXEC['workflow_name'] = WF2_NAME
# Action executions requirements
ACTION_CONTEXT = {'user': 'stanley'}
ACTION_PARAMS = {'friend': 'Rocky'}
# Token for auth test cases
TOKEN_API = TokenAPI(
user=ACTION_CONTEXT['user'], token=uuid.uuid4().hex,
expiry=isotime.format(date_utils.get_datetime_utc_now(), offset=False))
TOKEN_DB = TokenAPI.to_model(TOKEN_API)
NON_EMPTY_RESULT = 'non-empty'
@mock.patch.object(LocalShellRunner, 'run', mock.
MagicMock(return_value=(action_constants.LIVEACTION_STATUS_SUCCEEDED,
NON_EMPTY_RESULT, None)))
@mock.patch.object(CUDPublisher, 'publish_update', mock.MagicMock(return_value=None))
@mock.patch.object(CUDPublisher, 'publish_create',
mock.MagicMock(side_effect=MockLiveActionPublisher.publish_create))
@mock.patch.object(LiveActionPublisher, 'publish_state',
mock.MagicMock(side_effect=MockLiveActionPublisher.publish_state))
class TestMistralRunner(DbTestCase):
@classmethod
示例3: test_token_model_null_expiry
# 需要导入模块: from st2common.models.api.auth import TokenAPI [as 别名]
# 或者: from st2common.models.api.auth.TokenAPI import to_model [as 别名]
def test_token_model_null_expiry(self):
tk = TokenAPI(user='stanley', token=uuid.uuid4().hex, expiry=None)
self.assertRaises(ValueError, Token.add_or_update, TokenAPI.to_model(tk))
示例4: test_token_model_null_user
# 需要导入模块: from st2common.models.api.auth import TokenAPI [as 别名]
# 或者: from st2common.models.api.auth.TokenAPI import to_model [as 别名]
def test_token_model_null_user(self):
dt = isotime.add_utc_tz(datetime.datetime.utcnow())
tk = TokenAPI(user=None, token=uuid.uuid4().hex, expiry=isotime.format(dt))
self.assertRaises(ValueError, Token.add_or_update, TokenAPI.to_model(tk))
示例5: test_token_model_null_token
# 需要导入模块: from st2common.models.api.auth import TokenAPI [as 别名]
# 或者: from st2common.models.api.auth.TokenAPI import to_model [as 别名]
def test_token_model_null_token(self):
dt = date_utils.get_datetime_utc_now()
tk = TokenAPI(user='stanley', token=None, expiry=isotime.format(dt))
self.assertRaises(ValueError, Token.add_or_update, TokenAPI.to_model(tk))