Skip to content

Commit 02191d1

Browse files
committed
Use proper test app path for custom urlconf
1 parent 08ef429 commit 02191d1

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
from __future__ import absolute_import
22

3-
import django
4-
5-
if django.VERSION >= (2, 0):
6-
# TODO: once we stop supporting django < 2, use the real name of this
7-
# function (re_path)
8-
from django.urls import re_path as url
9-
else:
3+
try:
4+
from django.urls import path
5+
except ImportError:
106
from django.conf.urls import url
117

8+
def path(path, *args, **kwargs):
9+
return url("^{}$".format(path), *args, **kwargs)
10+
11+
12+
from . import views
1213

1314
urlpatterns = [
14-
url(r"^foo/bar/baz/(?P<param>[\d]+)", lambda x: ""),
15+
path("foo/bar/baz/<int:param>/", views.postgres_select_custom, name="postgres_select_custom"),
1516
]

tests/integrations/django/myapp/views.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,15 @@ def postgres_select(request, *args, **kwargs):
136136
return HttpResponse("ok")
137137

138138

139+
@csrf_exempt
140+
def postgres_select_custom(request, *args, **kwargs):
141+
from django.db import connections
142+
143+
cursor = connections["postgres"].cursor()
144+
cursor.execute("SELECT 1;")
145+
return HttpResponse("ok")
146+
147+
139148
@csrf_exempt
140149
def permission_denied_exc(*args, **kwargs):
141150
raise PermissionDenied("bye")

tests/integrations/django/test_transactions.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,15 @@ def test_legacy_resolver_newstyle_django20_urlconf():
6666
def test_legacy_resolver_custom_urlconf_module_name():
6767
resolver = RavenResolver()
6868
custom_urlconf_module = "tests.integrations.django.myapp.custom_urls"
69-
result = resolver.resolve("/foo/bar/baz/1234", custom_urlconf_module)
70-
assert result == "/foo/bar/baz/{param}"
69+
result = resolver.resolve("/foo/bar/baz/1234/", custom_urlconf_module)
70+
assert result == "/foo/bar/baz/{param}/"
7171

7272

73+
@pytest.mark.only
7374
def test_legacy_resolver_custom_urlconf_callback():
7475
def custom_urlconf_callback():
7576
return "tests.integrations.django.myapp.custom_urls"
7677

7778
resolver = RavenResolver()
78-
result = resolver.resolve("/foo/bar/baz/1234", custom_urlconf_callback)
79-
assert result == "/foo/bar/baz/{param}"
79+
result = resolver.resolve("/foo/bar/baz/1234/", custom_urlconf_callback)
80+
assert result == "/foo/bar/baz/{param}/"

0 commit comments

Comments
 (0)