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"
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
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')
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'
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'
def test_equal_params_pass_with_flying_colors(self): result = engine.enforce('1', '1', ['1'], 'key') assert result is None
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
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