]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
tests: Fix compatibility with openapi_core 0.13.7
authorStephen Finucane <stephen@that.guru>
Sat, 20 Feb 2021 13:27:08 +0000 (13:27 +0000)
committerStephen Finucane <stephen@that.guru>
Sat, 20 Feb 2021 14:08:10 +0000 (14:08 +0000)
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 <stephen@that.guru>
Closes: #395
patchwork/tests/api/validator.py

index 8ae8918260e6c5d35d95c8a956a7b767a0e4028f..2b1921a35887b983dede39971bee6554d3567317 100644 (file)
@@ -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,
+    ),
 }