Beispiel #1
0
import six

from apscheduler.triggers.cron import CronTrigger

from st2common.exceptions.apivalidation import ValueValidationException
from st2common.constants.triggers import SYSTEM_TRIGGER_TYPES
from st2common.constants.triggers import CRON_TIMER_TRIGGER_REF
from st2common.util import schema as util_schema
import st2common.operators as criteria_operators

__all__ = [
    'validate_criteria',
    'validate_trigger_parameters'
]

allowed_operators = criteria_operators.get_allowed_operators()


def validate_criteria(criteria):
    if not isinstance(criteria, dict):
        raise ValueValidationException('Criteria should be a dict.')

    for key, value in six.iteritems(criteria):
        operator = value.get('type', None)
        if operator is None:
            raise ValueValidationException('Operator not specified for field: ' + key)
        if operator not in allowed_operators:
            raise ValueValidationException('For field: ' + key + ', operator ' + operator +
                                           ' not in list of allowed operators: ' +
                                           str(allowed_operators.keys()))
        pattern = value.get('pattern', None)
Beispiel #2
0
 def test_get_allowed_operators(self):
     # This test will need to change as operators are deprecated
     self.assertGreater(len(operators.get_allowed_operators()), 0)
Beispiel #3
0
 def test_get_allowed_operators(self):
     # This test will need to change as operators are deprecated
     self.assertGreater(len(operators.get_allowed_operators()), 0)