|
1 | 1 | import collections |
2 | 2 | import datetime |
3 | | -import importlib.metadata |
4 | 3 | import typing |
5 | 4 | from unittest import mock |
6 | 5 |
|
|
16 | 15 | pre_load, |
17 | 16 | validates_schema, |
18 | 17 | ) |
19 | | -from packaging.version import Version |
20 | 18 | from werkzeug.datastructures import MultiDict as WerkMultiDict |
21 | 19 |
|
22 | 20 | from webargs import ValidationError, fields |
23 | 21 | from webargs.core import Parser, get_mimetype, is_json |
24 | 22 | from webargs.multidictproxy import MultiDictProxy |
25 | 23 |
|
26 | | -MARSHMALLOW_VERSION = Version(importlib.metadata.version("marshmallow")) |
27 | | - |
28 | 24 |
|
29 | 25 | class MockHTTPError(Exception): |
30 | 26 | def __init__(self, status_code, headers): |
@@ -557,27 +553,6 @@ def test_required_with_custom_error(parser, web_request): |
557 | 553 | assert "We need foo" in excinfo.value.messages["json"]["foo"] |
558 | 554 |
|
559 | 555 |
|
560 | | -@pytest.mark.filterwarnings("ignore:Returning `False` from a validator is deprecated") |
561 | | -@pytest.mark.skipif( |
562 | | - MARSHMALLOW_VERSION.major >= 4, |
563 | | - reason="marshmallow 4+ does not support validators returning False", |
564 | | -) |
565 | | -def test_required_with_custom_error_and_validation_error(parser, web_request): |
566 | | - web_request.json = {"foo": ""} |
567 | | - args = { |
568 | | - "foo": fields.Str( |
569 | | - required="We need foo", |
570 | | - validate=lambda s: len(s) > 1, |
571 | | - error_messages={"validator_failed": "foo required length is 3"}, |
572 | | - ) |
573 | | - } |
574 | | - with pytest.raises(ValidationError) as excinfo: |
575 | | - # Test that `validate` receives dictionary of args |
576 | | - parser.parse(args, web_request) |
577 | | - |
578 | | - assert "foo required length is 3" in excinfo.value.args[0]["foo"] |
579 | | - |
580 | | - |
581 | 556 | def test_full_input_validator_receives_nonascii_input(web_request): |
582 | 557 | def validate(val): |
583 | 558 | return False |
|
0 commit comments