]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
tests: Drop Django 1.x support
authorStephen Finucane <stephen@that.guru>
Wed, 15 Apr 2020 15:44:32 +0000 (16:44 +0100)
committerStephen Finucane <stephen@that.guru>
Sat, 18 Apr 2020 10:57:28 +0000 (11:57 +0100)
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>
patchwork/tests/api/validator.py

index 670063926cc40be7aeecf7a8c57651854bf507c4..b046f4ec216e8ab8359935601d3526aa828ee3b2 100644 (file)
@@ -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.