From: Stephen Finucane Date: Sat, 20 Feb 2021 13:27:08 +0000 (+0000) Subject: tests: Fix compatibility with openapi_core 0.13.7 X-Git-Tag: v3.0.1~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=efd9ab09baca8e018004dc0efb74ca009d46c5a3;p=thirdparty%2Fpatchwork.git tests: Fix compatibility with openapi_core 0.13.7 It seems the 'openapi_core.schema.schemas.models.Format' mechanism of defining custom formatters was deprecated in openapi_core 0.12.0 but we never noticed. They've finally broken it in 0.13.7. Switch to the new thing, 'openapi_core.unmarshalling.schemas.formatters.Formatter', which expects a slightly different format. Signed-off-by: Stephen Finucane Closes: #395 (cherry picked from commit d11ac34e9f0f2a86901ed74da27fa7a2df109728) --- diff --git a/patchwork/tests/api/validator.py b/patchwork/tests/api/validator.py index 8ae89182..2b1921a3 100644 --- a/patchwork/tests/api/validator.py +++ b/patchwork/tests/api/validator.py @@ -8,14 +8,14 @@ import re from django.urls import resolve import openapi_core -from openapi_core.contrib.django import DjangoOpenAPIResponseFactory from openapi_core.contrib.django import DjangoOpenAPIRequestFactory -from openapi_core.schema.schemas.models import Format -from openapi_core.validation.request.validators import RequestValidator -from openapi_core.validation.response.validators import ResponseValidator -from openapi_core.schema.parameters.exceptions import OpenAPIParameterError +from openapi_core.contrib.django import DjangoOpenAPIResponseFactory from openapi_core.schema.media_types.exceptions import OpenAPIMediaTypeError +from openapi_core.schema.parameters.exceptions import OpenAPIParameterError from openapi_core.templating import util +from openapi_core.unmarshalling.schemas.formatters import Formatter +from openapi_core.validation.request.validators import RequestValidator +from openapi_core.validation.response.validators import ResponseValidator from rest_framework import status import yaml @@ -57,17 +57,25 @@ class RegexValidator(object): CUSTOM_FORMATTERS = { - 'uri': Format(str, RegexValidator( - r'^(?:http|ftp)s?://' - r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' # noqa - r'localhost|' - r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' - r'(?::\d+)?' - r'(?:/?|[/?]\S+)$')), - 'iso8601': Format(str, RegexValidator( - r'^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\.\d{6}$')), - 'email': Format(str, RegexValidator( - r'[^@]+@[^@]+\.[^@]+')), + 'uri': Formatter.from_callables( + RegexValidator( + r'^(?:http|ftp)s?://' + r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' # noqa: E501 + r'localhost|' + r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' + r'(?::\d+)?' + r'(?:/?|[/?]\S+)$', + ), + str, + ), + 'iso8601': Formatter.from_callables( + RegexValidator(r'^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\.\d{6}$'), + str, + ), + 'email': Formatter.from_callables( + RegexValidator(r'[^@]+@[^@]+\.[^@]+'), + str, + ), }