summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Finucane <stephen@that.guru>2020-04-15 16:44:32 +0100
committerStephen Finucane <stephen@that.guru>2020-04-18 11:57:28 +0100
commit90380ad719ecac62dd38acd553f62fdd1b465832 (patch)
tree7d7cc0d8f6ad659088449de12320c84c2e15fc69
parentc3d73a00536ff92e65639b912eaeddd462b7cbc3 (diff)
downloadpatchwork-90380ad719ecac62dd38acd553f62fdd1b465832.tar
patchwork-90380ad719ecac62dd38acd553f62fdd1b465832.tar.gz
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 <stephen@that.guru>
-rw-r--r--patchwork/tests/api/validator.py52
1 files changed, 3 insertions, 49 deletions
diff --git a/patchwork/tests/api/validator.py b/patchwork/tests/api/validator.py
index 6700639..b046f4e 100644
--- a/patchwork/tests/api/validator.py
+++ b/patchwork/tests/api/validator.py
@@ -6,7 +6,6 @@
import os
import re
-import django
from django.urls import resolve
from django.urls.resolvers import get_resolver
import openapi_core
@@ -72,52 +71,13 @@ def _extract_headers(request):
return request_headers
-def _resolve_django1x(path, resolver=None):
- """Resolve a given path to its matching regex (Django 1.x).
-
- This is essentially a re-implementation of ``RegexURLResolver.resolve``
- that builds and returns the matched regex instead of the view itself.
-
- >>> _resolve_django1x('/api/1.0/patches/1/checks/')
- "^api/(?:(?P<version>(1.0|1.1))/)patches/(?P<patch_id>[^/]+)/checks/$"
- """
- from django.urls.resolvers import RegexURLResolver # noqa
-
- resolver = resolver or get_resolver()
- match = resolver.regex.search(path)
-
- if not match:
- return
-
- if isinstance(resolver, RegexURLResolver):
- sub_path = path[match.end():]
- for sub_resolver in resolver.url_patterns:
- sub_match = _resolve_django1x(sub_path, sub_resolver)
- if not sub_match:
- continue
-
- kwargs = dict(match.groupdict())
- kwargs.update(sub_match[2])
- args = sub_match[1]
- if not kwargs:
- args = match.groups() + args
-
- regex = resolver.regex.pattern + sub_match[0].lstrip('^')
-
- return regex, args, kwargs
- else: # RegexURLPattern
- kwargs = match.groupdict()
- args = () if kwargs else match.groups()
- return resolver.regex.pattern, args, kwargs
-
-
-def _resolve_django2x(path, resolver=None):
+def _resolve(path, resolver=None):
"""Resolve a given path to its matching regex (Django 2.x).
This is essentially a re-implementation of ``URLResolver.resolve`` that
builds and returns the matched regex instead of the view itself.
- >>> _resolve_django2x('/api/1.0/patches/1/checks/')
+ >>> _resolve('/api/1.0/patches/1/checks/')
"^api/(?:(?P<version>(1.0|1.1))/)patches/(?P<patch_id>[^/]+)/checks/$"
"""
from django.urls.resolvers import URLResolver # noqa
@@ -135,7 +95,7 @@ def _resolve_django2x(path, resolver=None):
if isinstance(resolver, URLResolver):
sub_path, args, kwargs = match
for sub_resolver in resolver.url_patterns:
- sub_match = _resolve_django2x(sub_path, sub_resolver)
+ sub_match = _resolve(sub_path, sub_resolver)
if not sub_match:
continue
@@ -150,12 +110,6 @@ def _resolve_django2x(path, resolver=None):
return resolver.pattern._regex, args, kwargs
-if django.VERSION < (2, 0):
- _resolve = _resolve_django1x
-else:
- _resolve = _resolve_django2x
-
-
def _resolve_path_to_kwargs(path):
"""Convert a path to the kwargs used to resolve it.