本文整理汇总了Python中st2reactor.rules.filter.RuleFilter类的典型用法代码示例。如果您正苦于以下问题:Python RuleFilter类的具体用法?Python RuleFilter怎么用?Python RuleFilter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RuleFilter类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_empty_payload
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.')
开发者ID:AlexeyDeyneko,项目名称:st2,代码行数:7,代码来源:test_filter.py
示例2: test_empty_criteria_and_empty_payload
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.')
开发者ID:AlexeyDeyneko,项目名称:st2,代码行数:7,代码来源:test_filter.py
示例3: test_nexists
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.')
开发者ID:AlexeyDeyneko,项目名称:st2,代码行数:8,代码来源:test_filter.py
示例4: test_equals_float_value
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.')
开发者ID:StackStorm,项目名称:st2,代码行数:10,代码来源:test_filter.py
示例5: test_criteria_pattern_references_a_datastore_item
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())
开发者ID:AlexeyDeyneko,项目名称:st2,代码行数:55,代码来源:test_filter.py
示例6: test_gt_lt_falsy_pattern
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')
开发者ID:StackStorm,项目名称:st2,代码行数:11,代码来源:test_filter.py
示例7: test_criteria_pattern_references_a_datastore_item
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())
开发者ID:ipv1337,项目名称:st2,代码行数:49,代码来源:test_filter.py
示例8: test_search_operator_pass_all_criteria
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')
开发者ID:StackStorm,项目名称:st2,代码行数:16,代码来源:test_filter.py
示例9: test_search_operator_pass_any_criteria
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')
开发者ID:StackStorm,项目名称:st2,代码行数:20,代码来源:test_filter.py
示例10: test_search_operator_fail_all_criteria
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')
开发者ID:StackStorm,项目名称:st2,代码行数:20,代码来源:test_filter.py
示例11: test_equals_operator_fail_criteria
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.')
开发者ID:StackStorm,项目名称:st2,代码行数:26,代码来源:test_filter.py
示例12: test_equals_operator_pass_criteria
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.')
开发者ID:StackStorm,项目名称:st2,代码行数:37,代码来源:test_filter.py
示例13: test_matchregex_operator_pass_criteria
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.')
开发者ID:AlexeyDeyneko,项目名称:st2,代码行数:5,代码来源:test_filter.py
示例14: test_matchregex_operator_fail_criteria
def test_matchregex_operator_fail_criteria(self):
rule = MOCK_RULE_1
rule.criteria = {"trigger.p1": {"type": "matchregex", "pattern": "v$"}}
f = RuleFilter(MOCK_TRIGGER_INSTANCE, MOCK_TRIGGER, rule)
self.assertFalse(f.filter(), "regex check should have failed.")
开发者ID:ipv1337,项目名称:st2,代码行数:5,代码来源:test_filter.py
示例15: test_empty_criteria
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.')
开发者ID:AlexeyDeyneko,项目名称:st2,代码行数:5,代码来源:test_filter.py
示例16: test_equals_operator_pass_criteria
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(), "regex check should have failed.")
开发者ID:ipv1337,项目名称:st2,代码行数:5,代码来源:test_filter.py
示例17: test_equals_operator_fail_criteria
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.')
开发者ID:AlexeyDeyneko,项目名称:st2,代码行数:5,代码来源:test_filter.py
示例18: test_equals_bool_value
def test_equals_bool_value(self):
rule = MOCK_RULE_1
rule.criteria = {'trigger.bool': {'type': 'equals', 'pattern': True}}
f = RuleFilter(MOCK_TRIGGER_INSTANCE, MOCK_TRIGGER, rule)
self.assertTrue(f.filter(), 'equals check should have passed.')
开发者ID:AlexeyDeyneko,项目名称:st2,代码行数:5,代码来源:test_filter.py
示例19: test_equals_float_value
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.")
开发者ID:ipv1337,项目名称:st2,代码行数:5,代码来源:test_filter.py
注:本文中的st2reactor.rules.filter.RuleFilter类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论