aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Finucane <stephen@that.guru>2021-02-20 13:27:08 +0000
committerStephen Finucane <stephen@that.guru>2021-02-20 14:08:10 +0000
commitd11ac34e9f0f2a86901ed74da27fa7a2df109728 (patch)
treee176abd3b8f5446b88c8e185b8aafe5d72136999
parentb0a2d7df929fc1c71db6da09438a7a84d10d659d (diff)
downloadpatchwork-d11ac34e9f0f2a86901ed74da27fa7a2df109728.tar
patchwork-d11ac34e9f0f2a86901ed74da27fa7a2df109728.tar.gz
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 <stephen@that.guru> Closes: #395
-rw-r--r--patchwork/tests/api/validator.py40
1 files changed, 24 insertions, 16 deletions
diff --git a/patchwork/tests/api/validator.py b/patchwork/tests/api/validator.py
index 8ae8918..2b1921a 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,
+ ),
}