當前位置: 首頁>>代碼示例>>Python>>正文


Python filter.RuleFilter類代碼示例

本文整理匯總了Python中st2reactor.rules.filter.RuleFilter的典型用法代碼示例。如果您正苦於以下問題:Python RuleFilter類的具體用法?Python RuleFilter怎麽用?Python RuleFilter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了RuleFilter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的st2reactor.rules.filter.RuleFilter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。