本文整理汇总了Python中st2common.persistence.rule.Rule.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Rule.get_by_id方法的具体用法?Python Rule.get_by_id怎么用?Python Rule.get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类st2common.persistence.rule.Rule
的用法示例。
在下文中一共展示了Rule.get_by_id方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_rule_crud
# 需要导入模块: from st2common.persistence.rule import Rule [as 别名]
# 或者: from st2common.persistence.rule.Rule import get_by_id [as 别名]
def test_rule_crud(self):
triggertype = ReactorModelTest._create_save_triggertype()
trigger = ReactorModelTest._create_save_trigger(triggertype)
runnertype = ActionModelTest._create_save_runnertype()
action = ActionModelTest._create_save_action(runnertype)
saved = ReactorModelTest._create_save_rule(trigger, action)
retrieved = Rule.get_by_id(saved.id)
self.assertEqual(saved.name, retrieved.name, 'Same rule was not returned.')
# test update
self.assertEqual(retrieved.enabled, True)
retrieved.enabled = False
saved = Rule.add_or_update(retrieved)
retrieved = Rule.get_by_id(saved.id)
self.assertEqual(retrieved.enabled, False, 'Update to rule failed.')
# cleanup
ReactorModelTest._delete([retrieved, trigger, action, runnertype, triggertype])
try:
retrieved = Rule.get_by_id(saved.id)
except ValueError:
retrieved = None
self.assertIsNone(retrieved, 'managed to retrieve after failure.')