Skip to content

Commit 90380ad

Browse files
committed
tests: Drop Django 1.x support
openapi-core 0.13.x has added support for Django validation. Before we migrate to that version and presumably remove most of this code, remove the stuff that is *definitely* dead. Signed-off-by: Stephen Finucane <[email protected]>
1 parent c3d73a0 commit 90380ad

File tree

1 file changed

+3
-49
lines changed

1 file changed

+3
-49
lines changed

patchwork/tests/api/validator.py

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import os
77
import re
88

9-
import django
109
from django.urls import resolve
1110
from django.urls.resolvers import get_resolver
1211
import openapi_core
@@ -72,52 +71,13 @@ def _extract_headers(request):
7271
return request_headers
7372

7473

75-
def _resolve_django1x(path, resolver=None):
76-
"""Resolve a given path to its matching regex (Django 1.x).
77-
78-
This is essentially a re-implementation of ``RegexURLResolver.resolve``
79-
that builds and returns the matched regex instead of the view itself.
80-
81-
>>> _resolve_django1x('/api/1.0/patches/1/checks/')
82-
"^api/(?:(?P<version>(1.0|1.1))/)patches/(?P<patch_id>[^/]+)/checks/$"
83-
"""
84-
from django.urls.resolvers import RegexURLResolver # noqa
85-
86-
resolver = resolver or get_resolver()
87-
match = resolver.regex.search(path)
88-
89-
if not match:
90-
return
91-
92-
if isinstance(resolver, RegexURLResolver):
93-
sub_path = path[match.end():]
94-
for sub_resolver in resolver.url_patterns:
95-
sub_match = _resolve_django1x(sub_path, sub_resolver)
96-
if not sub_match:
97-
continue
98-
99-
kwargs = dict(match.groupdict())
100-
kwargs.update(sub_match[2])
101-
args = sub_match[1]
102-
if not kwargs:
103-
args = match.groups() + args
104-
105-
regex = resolver.regex.pattern + sub_match[0].lstrip('^')
106-
107-
return regex, args, kwargs
108-
else: # RegexURLPattern
109-
kwargs = match.groupdict()
110-
args = () if kwargs else match.groups()
111-
return resolver.regex.pattern, args, kwargs
112-
113-
114-
def _resolve_django2x(path, resolver=None):
74+
def _resolve(path, resolver=None):
11575
"""Resolve a given path to its matching regex (Django 2.x).
11676
11777
This is essentially a re-implementation of ``URLResolver.resolve`` that
11878
builds and returns the matched regex instead of the view itself.
11979
120-
>>> _resolve_django2x('/api/1.0/patches/1/checks/')
80+
>>> _resolve('/api/1.0/patches/1/checks/')
12181
"^api/(?:(?P<version>(1.0|1.1))/)patches/(?P<patch_id>[^/]+)/checks/$"
12282
"""
12383
from django.urls.resolvers import URLResolver # noqa
@@ -135,7 +95,7 @@ def _resolve_django2x(path, resolver=None):
13595
if isinstance(resolver, URLResolver):
13696
sub_path, args, kwargs = match
13797
for sub_resolver in resolver.url_patterns:
138-
sub_match = _resolve_django2x(sub_path, sub_resolver)
98+
sub_match = _resolve(sub_path, sub_resolver)
13999
if not sub_match:
140100
continue
141101

@@ -150,12 +110,6 @@ def _resolve_django2x(path, resolver=None):
150110
return resolver.pattern._regex, args, kwargs
151111

152112

153-
if django.VERSION < (2, 0):
154-
_resolve = _resolve_django1x
155-
else:
156-
_resolve = _resolve_django2x
157-
158-
159113
def _resolve_path_to_kwargs(path):
160114
"""Convert a path to the kwargs used to resolve it.
161115

0 commit comments

Comments
 (0)