summaryrefslogtreecommitdiff
path: root/tests/check_framework
diff options
context:
space:
mode:
authorChris Lamb <chris@chris-lamb.co.uk>2017-11-07 16:39:59 +0000
committerTim Graham <timograham@gmail.com>2017-11-07 11:40:17 -0500
commit518c11352c3adad20b8d4a255369d2b8bd6f61fb (patch)
tree21b07b65a2aac0c2a04af43567f6e0df8de84070 /tests/check_framework
parent72f875541a0ad5a7d317ae1f842963c6c878ff5f (diff)
[2.0.x] Fixed #28663 -- Add a check for likely incorrectly migrated django.urls.path() routes.
Backport of 998c9dd599cd907bb38f440fff13a808571589f8 from master
Diffstat (limited to 'tests/check_framework')
-rw-r--r--tests/check_framework/test_urls.py30
-rw-r--r--tests/check_framework/urls/path_compatibility/__init__.py0
-rw-r--r--tests/check_framework/urls/path_compatibility/beginning_with_caret.py5
-rw-r--r--tests/check_framework/urls/path_compatibility/contains_re_named_group.py5
-rw-r--r--tests/check_framework/urls/path_compatibility/ending_with_dollar.py5
5 files changed, 45 insertions, 0 deletions
diff --git a/tests/check_framework/test_urls.py b/tests/check_framework/test_urls.py
index 5a0d811433..aa53af930e 100644
--- a/tests/check_framework/test_urls.py
+++ b/tests/check_framework/test_urls.py
@@ -135,6 +135,36 @@ class CheckUrlConfigTests(SimpleTestCase):
self.assertEqual(result, [])
+class UpdatedToPathTests(SimpleTestCase):
+
+ @override_settings(ROOT_URLCONF='check_framework.urls.path_compatibility.contains_re_named_group')
+ def test_contains_re_named_group(self):
+ result = check_url_config(None)
+ 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"
+ self.assertIn(expected_msg, warning.msg)
+
+ @override_settings(ROOT_URLCONF='check_framework.urls.path_compatibility.beginning_with_caret')
+ def test_beginning_with_caret(self):
+ result = check_url_config(None)
+ self.assertEqual(len(result), 1)
+ warning = result[0]
+ self.assertEqual(warning.id, '2_0.W001')
+ expected_msg = "Your URL pattern '^beginning-with-caret' has a route"
+ self.assertIn(expected_msg, warning.msg)
+
+ @override_settings(ROOT_URLCONF='check_framework.urls.path_compatibility.ending_with_dollar')
+ def test_ending_with_dollar(self):
+ result = check_url_config(None)
+ self.assertEqual(len(result), 1)
+ warning = result[0]
+ self.assertEqual(warning.id, '2_0.W001')
+ expected_msg = "Your URL pattern 'ending-with-dollar$' has a route"
+ self.assertIn(expected_msg, warning.msg)
+
+
class CheckURLSettingsTests(SimpleTestCase):
@override_settings(STATIC_URL='a/', MEDIA_URL='b/')
diff --git a/tests/check_framework/urls/path_compatibility/__init__.py b/tests/check_framework/urls/path_compatibility/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/check_framework/urls/path_compatibility/__init__.py
diff --git a/tests/check_framework/urls/path_compatibility/beginning_with_caret.py b/tests/check_framework/urls/path_compatibility/beginning_with_caret.py
new file mode 100644
index 0000000000..7e3e9c8707
--- /dev/null
+++ b/tests/check_framework/urls/path_compatibility/beginning_with_caret.py
@@ -0,0 +1,5 @@
+from django.urls import path
+
+urlpatterns = [
+ path('^beginning-with-caret', lambda x: x),
+]
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
new file mode 100644
index 0000000000..76c4939f3f
--- /dev/null
+++ b/tests/check_framework/urls/path_compatibility/contains_re_named_group.py
@@ -0,0 +1,5 @@
+from django.urls import path
+
+urlpatterns = [
+ path('(?P<named-group>\d+)', lambda x: x),
+]
diff --git a/tests/check_framework/urls/path_compatibility/ending_with_dollar.py b/tests/check_framework/urls/path_compatibility/ending_with_dollar.py
new file mode 100644
index 0000000000..0ea82a1ba6
--- /dev/null
+++ b/tests/check_framework/urls/path_compatibility/ending_with_dollar.py
@@ -0,0 +1,5 @@
+from django.urls import path
+
+urlpatterns = [
+ path('ending-with-dollar$', lambda x: x),
+]