summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAdam Johnson <me@adamj.eu>2020-04-13 09:07:28 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-04-15 11:29:35 +0200
commit4bb33bb07450ea9b623877417c28e6489246f51c (patch)
treefa793b35e2e19ff79cd01803deb8e0487587df46 /tests
parent578c03b276e435bcd3ce9eb17b81e85135c2d3f3 (diff)
Fixed #31459 -- Fixed handling invalid indentifiers in URL path conversion.
This patch adjusted existing tests that used invalid identifiers.
Diffstat (limited to 'tests')
-rw-r--r--tests/check_framework/test_urls.py2
-rw-r--r--tests/check_framework/urls/path_compatibility/contains_re_named_group.py2
-rw-r--r--tests/gis_tests/geoapp/urls.py2
-rw-r--r--tests/urlpatterns/tests.py10
4 files changed, 12 insertions, 4 deletions
diff --git a/tests/check_framework/test_urls.py b/tests/check_framework/test_urls.py
index 217b5e7bad..f0c257bc77 100644
--- a/tests/check_framework/test_urls.py
+++ b/tests/check_framework/test_urls.py
@@ -143,7 +143,7 @@ class UpdatedToPathTests(SimpleTestCase):
self.assertEqual(len(result), 1)
warning = result[0]
self.assertEqual(warning.id, '2_0.W001')
- expected_msg = "Your URL pattern '(?P<named-group>\\d+)' has a route"
+ expected_msg = "Your URL pattern '(?P<named_group>\\d+)' has a route"
self.assertIn(expected_msg, warning.msg)
@override_settings(ROOT_URLCONF='check_framework.urls.path_compatibility.beginning_with_caret')
diff --git a/tests/check_framework/urls/path_compatibility/contains_re_named_group.py b/tests/check_framework/urls/path_compatibility/contains_re_named_group.py
index a99c79354e..bd849509f5 100644
--- a/tests/check_framework/urls/path_compatibility/contains_re_named_group.py
+++ b/tests/check_framework/urls/path_compatibility/contains_re_named_group.py
@@ -1,5 +1,5 @@
from django.urls import path
urlpatterns = [
- path(r'(?P<named-group>\d+)', lambda x: x),
+ path(r'(?P<named_group>\d+)', lambda x: x),
]
diff --git a/tests/gis_tests/geoapp/urls.py b/tests/gis_tests/geoapp/urls.py
index 9635d8ddbf..8597387f82 100644
--- a/tests/gis_tests/geoapp/urls.py
+++ b/tests/gis_tests/geoapp/urls.py
@@ -20,7 +20,7 @@ urlpatterns += [
gis_sitemap_views.kml,
name='django.contrib.gis.sitemaps.views.kml'),
path(
- 'sitemaps/kml/<label>/<<model>/<field_name>.kmz',
+ 'sitemaps/kml/<label>/<model>/<field_name>.kmz',
gis_sitemap_views.kmz,
name='django.contrib.gis.sitemaps.views.kmz'),
]
diff --git a/tests/urlpatterns/tests.py b/tests/urlpatterns/tests.py
index 0de0f6f05d..b6353873ae 100644
--- a/tests/urlpatterns/tests.py
+++ b/tests/urlpatterns/tests.py
@@ -249,7 +249,7 @@ class SameNameTests(SimpleTestCase):
class ParameterRestrictionTests(SimpleTestCase):
- def test_non_identifier_parameter_name_causes_exception(self):
+ def test_integer_parameter_name_causes_exception(self):
msg = (
"URL route 'hello/<int:1>/' uses parameter name '1' which isn't "
"a valid Python identifier."
@@ -257,6 +257,14 @@ class ParameterRestrictionTests(SimpleTestCase):
with self.assertRaisesMessage(ImproperlyConfigured, msg):
path(r'hello/<int:1>/', lambda r: None)
+ def test_non_identifier_parameter_name_causes_exception(self):
+ msg = (
+ "URL route 'b/<int:book.id>/' uses parameter name 'book.id' which "
+ "isn't a valid Python identifier."
+ )
+ with self.assertRaisesMessage(ImproperlyConfigured, msg):
+ path(r'b/<int:book.id>/', lambda r: None)
+
def test_allows_non_ascii_but_valid_identifiers(self):
# \u0394 is "GREEK CAPITAL LETTER DELTA", a valid identifier.
p = path('hello/<str:\u0394>/', lambda r: None)