Skip to content

Commit efd9ab0

Browse files
committed
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 <[email protected]> Closes: #395 (cherry picked from commit d11ac34)
1 parent 2253147 commit efd9ab0

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

patchwork/tests/api/validator.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88

99
from django.urls import resolve
1010
import openapi_core
11-
from openapi_core.contrib.django import DjangoOpenAPIResponseFactory
1211
from openapi_core.contrib.django import DjangoOpenAPIRequestFactory
13-
from openapi_core.schema.schemas.models import Format
14-
from openapi_core.validation.request.validators import RequestValidator
15-
from openapi_core.validation.response.validators import ResponseValidator
16-
from openapi_core.schema.parameters.exceptions import OpenAPIParameterError
12+
from openapi_core.contrib.django import DjangoOpenAPIResponseFactory
1713
from openapi_core.schema.media_types.exceptions import OpenAPIMediaTypeError
14+
from openapi_core.schema.parameters.exceptions import OpenAPIParameterError
1815
from openapi_core.templating import util
16+
from openapi_core.unmarshalling.schemas.formatters import Formatter
17+
from openapi_core.validation.request.validators import RequestValidator
18+
from openapi_core.validation.response.validators import ResponseValidator
1919
from rest_framework import status
2020
import yaml
2121

@@ -57,17 +57,25 @@ def __call__(self, value):
5757

5858

5959
CUSTOM_FORMATTERS = {
60-
'uri': Format(str, RegexValidator(
61-
r'^(?:http|ftp)s?://'
62-
r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' # noqa
63-
r'localhost|'
64-
r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})'
65-
r'(?::\d+)?'
66-
r'(?:/?|[/?]\S+)$')),
67-
'iso8601': Format(str, RegexValidator(
68-
r'^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\.\d{6}$')),
69-
'email': Format(str, RegexValidator(
70-
r'[^@]+@[^@]+\.[^@]+')),
60+
'uri': Formatter.from_callables(
61+
RegexValidator(
62+
r'^(?:http|ftp)s?://'
63+
r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' # noqa: E501
64+
r'localhost|'
65+
r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})'
66+
r'(?::\d+)?'
67+
r'(?:/?|[/?]\S+)$',
68+
),
69+
str,
70+
),
71+
'iso8601': Formatter.from_callables(
72+
RegexValidator(r'^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\.\d{6}$'),
73+
str,
74+
),
75+
'email': Formatter.from_callables(
76+
RegexValidator(r'[^@]+@[^@]+\.[^@]+'),
77+
str,
78+
),
7179
}
7280

7381

0 commit comments

Comments
 (0)