Esempio n. 1
0
 def test_validate_args_successful(self):
     validation_funcs_mock = {'some_type': lambda _: True}
     with patch.dict('dsl_parser.constraints.VALIDATION_FUNCTIONS',
                     validation_funcs_mock):
         constraint_cls_mock = MagicMock()
         constraint_cls_mock.constraint_data_type = 'some_type'
         constraints.validate_args(constraint_cls_mock, None, None)
Esempio n. 2
0
 def validate(self, **kwargs):
     constraint_op_keys = list(self.initial_value)
     if not constraint_op_keys:
         raise exceptions.DSLParsingLogicException(
             exceptions.ERROR_UNKNOWN_TYPE,
             "Empty constraint operator name given. Allowed operators: "
             "{0}".format(constraints.CONSTRAINTS))
     if len(constraint_op_keys) > 1:
         raise exceptions.DSLParsingLogicException(
             exceptions.ERROR_UNKNOWN_TYPE,
             "Each constraint operator dict must be in it's own list item.")
     constraint_name = constraint_op_keys[0]
     if constraint_name not in constraints.CONSTRAINTS:
         raise exceptions.DSLParsingLogicException(
             exceptions.ERROR_UNKNOWN_TYPE,
             "No such constraint operator '{0}'. Allowed operators: "
             "{1}".format(constraint_name, constraints.CONSTRAINTS))
     ancestor = self.ancestor(SchemaProperty).name
     constraints.validate_args(constraints.CONSTRAINTS[constraint_name],
                               self.initial_value[constraint_name],
                               ancestor)