Exemplo n.º 1
0
    def test_callable_with_messages_are_passed_on(self):
        def callable_message(v):
            assert False, "this is completely False"

        with raises(Invalid) as exc:
            engine.enforce(1, callable_message, ['1'], 'key')
        assert exc.value.reason == "this is completely False"
Exemplo n.º 2
0
    def test_callable_failure_raises_invalid(self):
        def bad_callable(v):
            assert False

        with raises(Invalid) as exc:
            engine.enforce('1', bad_callable, ['1'], 'key')
        error = exc.value.args[0]
        assert '-> 1 key did not pass validation against callable: bad_callable' in error
Exemplo n.º 3
0
 def __call__(self, value, *args):
     if isinstance(value, (dict, list)):
         from notario.validators.recursive import RecursiveValidator
         validator = RecursiveValidator(value, self.schema, *args)
         validator.validate()
     else:
         try:
             tree = args[0]
         except IndexError:
             tree = []
         from notario.engine import enforce
         enforce(value, self.validator, tree, pair='value')
Exemplo n.º 4
0
 def __call__(self, value, *args):
     if isinstance(value, (dict, list)):
         from notario.validators.recursive import RecursiveValidator
         validator = RecursiveValidator(value, self.schema, *args)
         validator.validate()
     else:
         try:
             tree = args[0]
         except IndexError:
             tree = []
         from notario.engine import enforce
         enforce(value, self.validator, tree, pair='value')
Exemplo n.º 5
0
 def test_callable_failure_raises_invalid(self):
     def bad_callable(v): assert False
     with raises(Invalid) as exc:
         engine.enforce('1', bad_callable, ['1'], 'key')
     assert exc.value.args[0] == '-> 1 key did not pass validation against callable: bad_callable'
Exemplo n.º 6
0
 def test_callable_with_messages_are_passed_on(self):
     def callable_message(v): assert False, "this is completely False"
     with raises(Invalid) as exc:
         engine.enforce(1, callable_message, ['1'], 'key')
     assert exc.value.reason == "this is completely False"
Exemplo n.º 7
0
 def test_unequal_params_raise_invalid(self):
     with raises(Invalid) as exc:
         engine.enforce(1, 2, ['1'], 'key')
     assert exc.value.args[0] == '-> 1 key did not match 2'
Exemplo n.º 8
0
 def test_equal_params_pass_with_flying_colors(self):
     result = engine.enforce('1', '1', ['1'], 'key')
     assert result is None
Exemplo n.º 9
0
 def test_callable_passes_with_flying_colors(self):
     def cool_callable(v): pass
     result = engine.enforce('1', cool_callable, ['1'], 'key')
     assert result is None
Exemplo n.º 10
0
 def test_unequal_params_raise_invalid(self):
     with raises(Invalid) as exc:
         engine.enforce(1, 2, ['1'], 'key')
     error = exc.value.args[0]
     assert '-> 1 key did not match 2' in error
Exemplo n.º 11
0
 def test_equal_params_pass_with_flying_colors(self):
     result = engine.enforce('1', '1', ['1'], 'key')
     assert result is None
Exemplo n.º 12
0
    def test_callable_passes_with_flying_colors(self):
        def cool_callable(v):
            pass

        result = engine.enforce('1', cool_callable, ['1'], 'key')
        assert result is None