本文整理汇总了Python中st2reactor.rules.filter.RuleFilter.filter方法的典型用法代码示例。如果您正苦于以下问题:Python RuleFilter.filter方法的具体用法?Python RuleFilter.filter怎么用?Python RuleFilter.filter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类st2reactor.rules.filter.RuleFilter
的用法示例。
在下文中一共展示了RuleFilter.filter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_equals_operator_fail_criteria
# 需要导入模块: from st2reactor.rules.filter import RuleFilter [as 别名]
# 或者: from st2reactor.rules.filter.RuleFilter import filter [as 别名]
def test_equals_operator_fail_criteria(self):
rule = MOCK_RULE_1
rule.criteria = {'trigger.p1': {'type': 'equals', 'pattern': 'v'}}
f = RuleFilter(MOCK_TRIGGER_INSTANCE, MOCK_TRIGGER, rule)
self.assertFalse(f.filter(), 'equals check should have failed.')
rule = MOCK_RULE_1
rule.criteria = {'trigger.p1': {'type': 'equals', 'pattern': '{{trigger.p2}}'}}
f = RuleFilter(MOCK_TRIGGER_INSTANCE, MOCK_TRIGGER, rule)
self.assertFalse(f.filter(), 'equals check should have failed.')
rule = MOCK_RULE_1
rule.criteria = {
'trigger.list': {
'type': 'equals',
'pattern': """
[
{% for item in trigger.list %}
{{item}}
{% endfor %}
]
"""
}
}
f = RuleFilter(MOCK_TRIGGER_INSTANCE, MOCK_TRIGGER, rule)
self.assertFalse(f.filter(), 'equals check should have failed.')
示例2: test_nexists
# 需要导入模块: from st2reactor.rules.filter import RuleFilter [as 别名]
# 或者: from st2reactor.rules.filter.RuleFilter import filter [as 别名]
def test_nexists(self):
rule = MOCK_RULE_1
rule.criteria = {'trigger.float': {'type': 'nexists'}}
f = RuleFilter(MOCK_TRIGGER_INSTANCE, MOCK_TRIGGER, rule)
self.assertFalse(f.filter(), '"float" key exists in trigger. Should return false.')
rule.criteria = {'trigger.floattt': {'type': 'nexists'}}
f = RuleFilter(MOCK_TRIGGER_INSTANCE, MOCK_TRIGGER, rule)
self.assertTrue(f.filter(), '"floattt" key ain\'t exist in trigger. Should return true.')
示例3: test_equals_float_value
# 需要导入模块: from st2reactor.rules.filter import RuleFilter [as 别名]
# 或者: from st2reactor.rules.filter.RuleFilter import filter [as 别名]
def test_equals_float_value(self):
rule = MOCK_RULE_1
rule.criteria = {'trigger.float': {'type': 'equals', 'pattern': 0.8}}
f = RuleFilter(MOCK_TRIGGER_INSTANCE, MOCK_TRIGGER, rule)
self.assertTrue(f.filter(), 'equals check should have passed.')
rule = MOCK_RULE_1
rule.criteria = {'trigger.float': {'type': 'equals', 'pattern': '{{trigger.float}}'}}
f = RuleFilter(MOCK_TRIGGER_INSTANCE, MOCK_TRIGGER, rule)
self.assertTrue(f.filter(), 'equals check should have passed.')
示例4: test_criteria_pattern_references_a_datastore_item
# 需要导入模块: from st2reactor.rules.filter import RuleFilter [as 别名]
# 或者: from st2reactor.rules.filter.RuleFilter import filter [as 别名]
def test_criteria_pattern_references_a_datastore_item(self, mock_KeyValueLookup):
class MockResultLookup(object):
pass
class MockSystemLookup(object):
system = MockResultLookup()
rule = MOCK_RULE_2
# Using a variable in pattern, referencing an inexistent datastore value
rule.criteria = {'trigger.p1': {
'type': 'equals',
'pattern': '{{ system.inexistent_value }}'}
}
f = RuleFilter(MOCK_TRIGGER_INSTANCE, MOCK_TRIGGER, rule)
self.assertFalse(f.filter())
# Using a variable in pattern, referencing an existing value which doesn't match
mock_result = MockSystemLookup()
mock_result.test_value_1 = 'non matching'
mock_KeyValueLookup.return_value = mock_result
rule.criteria = {'trigger.p1': {'type': 'equals', 'pattern': '{{ system.test_value_1 }}'}}
f = RuleFilter(MOCK_TRIGGER_INSTANCE, MOCK_TRIGGER, rule)
self.assertFalse(f.filter())
# Using a variable in pattern, referencing an existing value which does match
mock_result = MockSystemLookup()
mock_result.test_value_2 = 'v1'
mock_KeyValueLookup.return_value = mock_result
rule.criteria = {'trigger.p1': {'type': 'equals', 'pattern': '{{ system.test_value_2 }}'}}
f = RuleFilter(MOCK_TRIGGER_INSTANCE, MOCK_TRIGGER, rule)
self.assertTrue(f.filter())
# Using a variable in pattern, referencing an existing value which matches partially
mock_result = MockSystemLookup()
mock_result.test_value_3 = 'YYY'
mock_KeyValueLookup.return_value = mock_result
rule.criteria = {'trigger.p2': {'type': 'equals', 'pattern': '{{ system.test_value_3 }}'}}
f = RuleFilter(MOCK_TRIGGER_INSTANCE, MOCK_TRIGGER, rule)
self.assertFalse(f.filter())
# Using a variable in pattern, referencing an existing value which matches partially
mock_result = MockSystemLookup()
mock_result.test_value_3 = 'YYY'
mock_KeyValueLookup.return_value = mock_result
rule.criteria = {'trigger.p2': {
'type': 'equals',
'pattern': 'pre{{ system.test_value_3 }}post'}
}
f = RuleFilter(MOCK_TRIGGER_INSTANCE, MOCK_TRIGGER, rule)
self.assertTrue(f.filter())
示例5: test_gt_lt_falsy_pattern
# 需要导入模块: from st2reactor.rules.filter import RuleFilter [as 别名]
# 或者: from st2reactor.rules.filter.RuleFilter import filter [as 别名]
def test_gt_lt_falsy_pattern(self):
# Make sure that the falsy value (number 0) is handled correctly
rule = MOCK_RULE_1
rule.criteria = {'trigger.int': {'type': 'gt', 'pattern': 0}}
f = RuleFilter(MOCK_TRIGGER_INSTANCE, MOCK_TRIGGER, rule)
self.assertTrue(f.filter(), 'trigger value is gt than 0 but didn\'t match')
rule.criteria = {'trigger.int': {'type': 'lt', 'pattern': 0}}
f = RuleFilter(MOCK_TRIGGER_INSTANCE, MOCK_TRIGGER, rule)
self.assertFalse(f.filter(), 'trigger value is gt than 0 but didn\'t fail')
示例6: test_criteria_pattern_references_a_datastore_item
# 需要导入模块: from st2reactor.rules.filter import RuleFilter [as 别名]
# 或者: from st2reactor.rules.filter.RuleFilter import filter [as 别名]
def test_criteria_pattern_references_a_datastore_item(self, mock_KeyValueLookup):
class MockResultLookup(object):
pass
class MockSystemLookup(object):
system = MockResultLookup()
rule = MOCK_RULE_2
# Using a variable in pattern, referencing an inexistent datastore value
rule.criteria = {"trigger.p1": {"type": "equals", "pattern": "{{ system.inexistent_value }}"}}
f = RuleFilter(MOCK_TRIGGER_INSTANCE, MOCK_TRIGGER, rule)
self.assertFalse(f.filter())
# Using a variable in pattern, referencing an existing value which doesn't match
mock_result = MockSystemLookup()
mock_result.test_value_1 = "non matching"
mock_KeyValueLookup.return_value = mock_result
rule.criteria = {"trigger.p1": {"type": "equals", "pattern": "{{ system.test_value_1 }}"}}
f = RuleFilter(MOCK_TRIGGER_INSTANCE, MOCK_TRIGGER, rule)
self.assertFalse(f.filter())
# Using a variable in pattern, referencing an existing value which does match
mock_result = MockSystemLookup()
mock_result.test_value_2 = "v1"
mock_KeyValueLookup.return_value = mock_result
rule.criteria = {"trigger.p1": {"type": "equals", "pattern": "{{ system.test_value_2 }}"}}
f = RuleFilter(MOCK_TRIGGER_INSTANCE, MOCK_TRIGGER, rule)
self.assertTrue(f.filter())
# Using a variable in pattern, referencing an existing value which matches partially
mock_result = MockSystemLookup()
mock_result.test_value_3 = "YYY"
mock_KeyValueLookup.return_value = mock_result
rule.criteria = {"trigger.p2": {"type": "equals", "pattern": "{{ system.test_value_3 }}"}}
f = RuleFilter(MOCK_TRIGGER_INSTANCE, MOCK_TRIGGER, rule)
self.assertFalse(f.filter())
# Using a variable in pattern, referencing an existing value which matches partially
mock_result = MockSystemLookup()
mock_result.test_value_3 = "YYY"
mock_KeyValueLookup.return_value = mock_result
rule.criteria = {"trigger.p2": {"type": "equals", "pattern": "pre{{ system.test_value_3 }}post"}}
f = RuleFilter(MOCK_TRIGGER_INSTANCE, MOCK_TRIGGER, rule)
self.assertTrue(f.filter())
示例7: test_empty_criteria_and_empty_payload
# 需要导入模块: from st2reactor.rules.filter import RuleFilter [as 别名]
# 或者: from st2reactor.rules.filter.RuleFilter import filter [as 别名]
def test_empty_criteria_and_empty_payload(self):
rule = MOCK_RULE_1
rule.criteria = {}
trigger_instance = copy.deepcopy(MOCK_TRIGGER_INSTANCE)
trigger_instance.payload = None
f = RuleFilter(trigger_instance, MOCK_TRIGGER, rule)
self.assertTrue(f.filter(), 'equals check should have failed.')
示例8: test_empty_payload
# 需要导入模块: from st2reactor.rules.filter import RuleFilter [as 别名]
# 或者: from st2reactor.rules.filter.RuleFilter import filter [as 别名]
def test_empty_payload(self):
rule = MOCK_RULE_1
rule.criteria = {'trigger.p1': {'type': 'equals', 'pattern': 'v1'}}
trigger_instance = copy.deepcopy(MOCK_TRIGGER_INSTANCE)
trigger_instance.payload = None
f = RuleFilter(trigger_instance, MOCK_TRIGGER, rule)
self.assertFalse(f.filter(), 'equals check should have failed.')
示例9: test_equals_operator_pass_criteria
# 需要导入模块: from st2reactor.rules.filter import RuleFilter [as 别名]
# 或者: from st2reactor.rules.filter.RuleFilter import filter [as 别名]
def test_equals_operator_pass_criteria(self):
rule = MOCK_RULE_1
rule.criteria = {'trigger.p1': {'type': 'equals', 'pattern': 'v1'}}
f = RuleFilter(MOCK_TRIGGER_INSTANCE, MOCK_TRIGGER, rule)
self.assertTrue(f.filter(), 'equals check should have passed.')
rule = MOCK_RULE_1
rule.criteria = {'trigger.p1': {'type': 'equals', 'pattern': '{{trigger.p1}}'}}
f = RuleFilter(MOCK_TRIGGER_INSTANCE, MOCK_TRIGGER, rule)
self.assertTrue(f.filter(), 'equals check should have passed.')
rule = MOCK_RULE_1
rule.criteria = {
'trigger.p1': {
'type': 'equals',
'pattern': "{{'%s' % trigger.p1 if trigger.int}}"
}
}
f = RuleFilter(MOCK_TRIGGER_INSTANCE, MOCK_TRIGGER, rule)
self.assertTrue(f.filter(), 'equals check should have passed.')
# Test our filter works if proper JSON is returned from user pattern
rule = MOCK_RULE_1
rule.criteria = {
'trigger.list': {
'type': 'equals',
'pattern': """
[
{% for item in trigger.list %}
{{item}}{% if not loop.last %},{% endif %}
{% endfor %}
]
"""
}
}
f = RuleFilter(MOCK_TRIGGER_INSTANCE, MOCK_TRIGGER, rule)
self.assertTrue(f.filter(), 'equals check should have passed.')
示例10: test_search_operator_pass_all_criteria
# 需要导入模块: from st2reactor.rules.filter import RuleFilter [as 别名]
# 或者: from st2reactor.rules.filter.RuleFilter import filter [as 别名]
def test_search_operator_pass_all_criteria(self):
rule = MOCK_RULE_1
rule.criteria = {
'trigger.recursive_list': {
'type': 'search',
'condition': 'all',
'pattern': {
'item.field_name': {
'type': 'startswith',
'pattern': 'S',
}
}
}
}
f = RuleFilter(MOCK_TRIGGER_INSTANCE, MOCK_TRIGGER, rule)
self.assertTrue(f.filter(), 'Failed evaluation')
示例11: test_search_operator_pass_any_criteria
# 需要导入模块: from st2reactor.rules.filter import RuleFilter [as 别名]
# 或者: from st2reactor.rules.filter.RuleFilter import filter [as 别名]
def test_search_operator_pass_any_criteria(self):
rule = MOCK_RULE_1
rule.criteria = {
'trigger.recursive_list': {
'type': 'search',
'condition': 'any',
'pattern': {
'item.field_name': {
'type': 'equals',
'pattern': 'Status',
},
'item.to_value': {
'type': 'equals',
'pattern': 'Approved'
}
}
}
}
f = RuleFilter(MOCK_TRIGGER_INSTANCE, MOCK_TRIGGER, rule)
self.assertTrue(f.filter(), 'Failed evaluation')
示例12: test_search_operator_fail_all_criteria
# 需要导入模块: from st2reactor.rules.filter import RuleFilter [as 别名]
# 或者: from st2reactor.rules.filter.RuleFilter import filter [as 别名]
def test_search_operator_fail_all_criteria(self):
rule = MOCK_RULE_1
rule.criteria = {
'trigger.recursive_list': {
'type': 'search',
'condition': 'all',
'pattern': {
'item.field_name': {
'type': 'equals',
'pattern': 'Status',
},
'item.to_value': {
'type': 'equals',
'pattern': 'Denied',
}
}
}
}
f = RuleFilter(MOCK_TRIGGER_INSTANCE, MOCK_TRIGGER, rule)
self.assertFalse(f.filter(), 'Passed evaluation')
示例13: test_matchregex_operator_pass_criteria
# 需要导入模块: from st2reactor.rules.filter import RuleFilter [as 别名]
# 或者: from st2reactor.rules.filter.RuleFilter import filter [as 别名]
def test_matchregex_operator_pass_criteria(self):
rule = MOCK_RULE_1
rule.criteria = {'trigger.p1': {'type': 'matchregex', 'pattern': 'v1$'}}
f = RuleFilter(MOCK_TRIGGER_INSTANCE, MOCK_TRIGGER, rule)
self.assertTrue(f.filter(), 'Failed to pass evaluation.')
示例14: test_empty_criteria
# 需要导入模块: from st2reactor.rules.filter import RuleFilter [as 别名]
# 或者: from st2reactor.rules.filter.RuleFilter import filter [as 别名]
def test_empty_criteria(self):
rule = MOCK_RULE_1
rule.criteria = {}
f = RuleFilter(MOCK_TRIGGER_INSTANCE, MOCK_TRIGGER, rule)
self.assertTrue(f.filter(), 'equals check should have failed.')
示例15: test_equals_operator_fail_criteria
# 需要导入模块: from st2reactor.rules.filter import RuleFilter [as 别名]
# 或者: from st2reactor.rules.filter.RuleFilter import filter [as 别名]
def test_equals_operator_fail_criteria(self):
rule = MOCK_RULE_1
rule.criteria = {'trigger.p1': {'type': 'equals', 'pattern': 'v'}}
f = RuleFilter(MOCK_TRIGGER_INSTANCE, MOCK_TRIGGER, rule)
self.assertFalse(f.filter(), 'equals check should have failed.')