Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jan 7, 2025
1 parent 2c63ff2 commit fb9d5d1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
6 changes: 3 additions & 3 deletions tests/apps/flask_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ def echo_json_or_form():
def echo_use_args(args):
return J(args)


def validator(args):
if args["value"] <= 42:
raise ma.ValidationError("invalid")


@app.route("/echo_use_args_validated", methods=["POST"])
@use_args(
{"value": fields.Int()}, validate=validator, location="form"
)
@use_args({"value": fields.Int()}, validate=validator, location="form")
def echo_use_args_validated(args):
return J(args)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_aiohttpparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def test_use_args_multiple(self, testapp):
def test_validation_error_returns_422_response(self, testapp):
res = testapp.post_json("/echo_json", {"name": "b"}, expect_errors=True)
assert res.status_code == 422
assert res.json == {"json": {"name": ['Shorter than minimum length 3.']}}
assert res.json == {"json": {"name": ["Shorter than minimum length 3."]}}


@pytest.mark.asyncio
Expand Down
18 changes: 11 additions & 7 deletions tests/test_core.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import importlib.metadata
import collections
import datetime
import importlib.metadata
import typing
from unittest import mock

import pytest
from packaging.version import Version
from bottle import MultiDict as BotMultiDict
from django.utils.datastructures import MultiValueDict as DjMultiDict
from marshmallow import (
Expand All @@ -17,9 +16,10 @@
pre_load,
validates_schema,
)
from packaging.version import Version
from werkzeug.datastructures import MultiDict as WerkMultiDict

from webargs import ValidationError, fields, validate
from webargs import ValidationError, fields
from webargs.core import Parser, get_mimetype, is_json
from webargs.multidictproxy import MultiDictProxy

Expand Down Expand Up @@ -514,6 +514,7 @@ def load_data(req, schema):

def test_full_input_validation(parser, web_request):
web_request.json = {"foo": 41, "bar": 42}

def validator(args):
if args["foo"] <= args["bar"]:
raise ValidationError("foo must be > bar")
Expand Down Expand Up @@ -555,8 +556,12 @@ def test_required_with_custom_error(parser, web_request):

assert "We need foo" in excinfo.value.messages["json"]["foo"]


@pytest.mark.filterwarnings("ignore:Returning `False` from a validator is deprecated")
@pytest.mark.skipif(MARSHMALLOW_VERSION.major >= 4, reason="marshmallow 4+ does not support validators returning False")
@pytest.mark.skipif(
MARSHMALLOW_VERSION.major >= 4,
reason="marshmallow 4+ does not support validators returning False",
)
def test_required_with_custom_error_and_validation_error(parser, web_request):
web_request.json = {"foo": ""}
args = {
Expand Down Expand Up @@ -1322,6 +1327,7 @@ def handle_error(self, error, req, schema, *, error_status_code, error_headers):
def test_parse_with_error_status_code_and_headers(web_request):
def always_fail(_):
raise ValidationError("oops")

parser = MockRequestParserWithErrorHandler()
web_request.json = {"foo": 42}
args = {"foo": fields.Raw(validate=always_fail)}
Expand Down Expand Up @@ -1557,9 +1563,7 @@ class MyParser(MockRequestParser):
web_request.query = {"bar": "baz"}

@parser.use_args({"foo": fields.Raw()}, web_request, arg_name="j")
@parser.use_args(
{"bar": fields.Raw()}, web_request, location="query", arg_name="q"
)
@parser.use_args({"bar": fields.Raw()}, web_request, location="query", arg_name="q")
def viewfunc(*, j, q):
return (j, q)

Expand Down

0 comments on commit fb9d5d1

Please sign in to comment.