本文整理汇总了Python中st2common.persistence.action.Action.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Action.get_by_id方法的具体用法?Python Action.get_by_id怎么用?Python Action.get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类st2common.persistence.action.Action
的用法示例。
在下文中一共展示了Action.get_by_id方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_parameter_schema
# 需要导入模块: from st2common.persistence.action import Action [as 别名]
# 或者: from st2common.persistence.action.Action import get_by_id [as 别名]
def test_parameter_schema(self):
runnertype = self._create_save_runnertype(metadata=True)
saved = self._create_save_action(runnertype, metadata=True)
retrieved = Action.get_by_id(saved.id)
# validate generated schema
schema = util_schema.get_schema_for_action_parameters(retrieved)
self.assertDictEqual(schema, PARAM_SCHEMA)
validator = util_schema.get_validator()
validator.check_schema(schema)
# use schema to validate parameters
jsonschema.validate({"r2": "abc", "p1": "def"}, schema, validator)
jsonschema.validate({"r2": "abc", "p1": "def", "r1": {"r1a": "ghi"}}, schema, validator)
self.assertRaises(jsonschema.ValidationError, jsonschema.validate,
'{"r2": "abc", "p1": "def"}', schema, validator)
self.assertRaises(jsonschema.ValidationError, jsonschema.validate,
{"r2": "abc"}, schema, validator)
self.assertRaises(jsonschema.ValidationError, jsonschema.validate,
{"r2": "abc", "p1": "def", "r1": 123}, schema, validator)
# cleanup
self._delete([retrieved])
try:
retrieved = Action.get_by_id(saved.id)
except ValueError:
retrieved = None
self.assertIsNone(retrieved, 'managed to retrieve after failure.')
示例2: test_action_with_notify_crud
# 需要导入模块: from st2common.persistence.action import Action [as 别名]
# 或者: from st2common.persistence.action.Action import get_by_id [as 别名]
def test_action_with_notify_crud(self):
runnertype = self._create_save_runnertype(metadata=False)
saved = self._create_save_action(runnertype, metadata=False)
# Update action with notification settings
on_complete = NotificationSubSchema(message='Action complete.')
saved.notify = NotificationSchema(on_complete=on_complete)
saved = Action.add_or_update(saved)
# Check if notification settings were set correctly.
retrieved = Action.get_by_id(saved.id)
self.assertEqual(retrieved.notify.on_complete.message, on_complete.message)
# Now reset notify in action to empty and validate it's gone.
retrieved.notify = NotificationSchema(on_complete=None)
saved = Action.add_or_update(retrieved)
retrieved = Action.get_by_id(saved.id)
self.assertEqual(retrieved.notify.on_complete, None)
# cleanup
self._delete([retrieved])
try:
retrieved = Action.get_by_id(saved.id)
except ValueError:
retrieved = None
self.assertIsNone(retrieved, 'managed to retrieve after failure.')
示例3: _get_action_by_id
# 需要导入模块: from st2common.persistence.action import Action [as 别名]
# 或者: from st2common.persistence.action.Action import get_by_id [as 别名]
def _get_action_by_id(id):
try:
return Action.get_by_id(id)
except Exception as e:
msg = 'Database lookup for id="%s" resulted in exception. %s' % (id, e)
LOG.exception(msg)
abort(http_client.NOT_FOUND, msg)
示例4: test_action_crud
# 需要导入模块: from st2common.persistence.action import Action [as 别名]
# 或者: from st2common.persistence.action.Action import get_by_id [as 别名]
def test_action_crud(self):
runnertype = self._create_save_runnertype(metadata=False)
saved = self._create_save_action(runnertype, metadata=False)
retrieved = Action.get_by_id(saved.id)
self.assertEqual(saved.name, retrieved.name, "Same Action was not returned.")
# test update
self.assertEqual(retrieved.description, "awesomeness")
retrieved.description = DUMMY_DESCRIPTION
saved = Action.add_or_update(retrieved)
retrieved = Action.get_by_id(saved.id)
self.assertEqual(retrieved.description, DUMMY_DESCRIPTION, "Update to action failed.")
# cleanup
self._delete([retrieved])
try:
retrieved = Action.get_by_id(saved.id)
except StackStormDBObjectNotFoundError:
retrieved = None
self.assertIsNone(retrieved, "managed to retrieve after failure.")
示例5: test_action_crud
# 需要导入模块: from st2common.persistence.action import Action [as 别名]
# 或者: from st2common.persistence.action.Action import get_by_id [as 别名]
def test_action_crud(self):
runnertype = self._create_save_runnertype(metadata=False)
saved = self._create_save_action(runnertype, metadata=False)
retrieved = Action.get_by_id(saved.id)
self.assertEqual(saved.name, retrieved.name,
'Same Action was not returned.')
# test update
self.assertEqual(retrieved.description, 'awesomeness')
retrieved.description = DUMMY_DESCRIPTION
saved = Action.add_or_update(retrieved)
retrieved = Action.get_by_id(saved.id)
self.assertEqual(retrieved.description, DUMMY_DESCRIPTION, 'Update to action failed.')
# cleanup
self._delete([retrieved])
try:
retrieved = Action.get_by_id(saved.id)
except ValueError:
retrieved = None
self.assertIsNone(retrieved, 'managed to retrieve after failure.')
示例6: get_action_by_id
# 需要导入模块: from st2common.persistence.action import Action [as 别名]
# 或者: from st2common.persistence.action.Action import get_by_id [as 别名]
def get_action_by_id(action_id):
"""
Get Action by id.
On error, raise StackStormDBObjectNotFoundError
"""
action = None
try:
action = Action.get_by_id(action_id)
except (ValueError, ValidationError) as e:
LOG.warning('Database lookup for action with id="%s" resulted in ' "exception: %s", action_id, e)
raise StackStormDBObjectNotFoundError("Unable to find action with " 'id="%s"' % action_id)
return action