Skip to content

Commit 304713c

Browse files
committed
Python: Handle django v4 as well in tests
1 parent bdadf2b commit 304713c

File tree

1 file changed

+17
-4
lines changed
  • python/ql/test/library-tests/frameworks/django-v2-v3/testapp

1 file changed

+17
-4
lines changed
Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
from django.urls import path, re_path
22

3-
# This version 1.x way of defining urls is deprecated in Django 3.1, but still works
4-
from django.conf.urls import url
5-
63
from . import views
74

85
urlpatterns = [
@@ -11,11 +8,27 @@
118
# inline expectation tests (which thinks the `$` would mark the beginning of a new
129
# line)
1310
re_path(r"^ba[rz]/", views.bar_baz), # $routeSetup="^ba[rz]/"
14-
url(r"^deprecated/", views.deprecated), # $routeSetup="^deprecated/"
1511

1612
path("basic-view-handler/", views.MyBasicViewHandler.as_view()), # $routeSetup="basic-view-handler/"
1713
path("custom-inheritance-view-handler/", views.MyViewHandlerWithCustomInheritance.as_view()), # $routeSetup="custom-inheritance-view-handler/"
1814

1915
path("CustomRedirectView/<foo>", views.CustomRedirectView.as_view()), # $routeSetup="CustomRedirectView/<foo>"
2016
path("CustomRedirectView2/<foo>", views.CustomRedirectView2.as_view()), # $routeSetup="CustomRedirectView2/<foo>"
2117
]
18+
19+
from django import __version__ as django_version
20+
21+
if django_version[0] == "3":
22+
# This version 1.x way of defining urls is deprecated in Django 3.1, but still works.
23+
# However, it is removed in Django 4.0, so we need this guard to make our code runnable
24+
from django.conf.urls import url
25+
26+
old_urlpatterns = urlpatterns
27+
28+
# we need this assignment to get our logic working... maybe it should be more
29+
# sophisticated?
30+
urlpatterns = [
31+
url(r"^deprecated/", views.deprecated), # $routeSetup="^deprecated/"
32+
]
33+
34+
urlpatterns += old_urlpatterns

0 commit comments

Comments
 (0)