From ffb1c532ec3f01ce625d6e54fd1d63552693c895 Mon Sep 17 00:00:00 2001 From: Alasdair Nicol Date: Wed, 27 Apr 2016 22:38:00 +0100 Subject: [PATCH] Added an explicit test that URL checks are recursive. --- tests/check_framework/test_urls.py | 8 ++++++++ tests/check_framework/urls/beginning_with_slash.py | 6 ++---- tests/check_framework/urls/include_with_dollar.py | 4 +--- tests/check_framework/urls/name_with_colon.py | 6 ++---- tests/check_framework/urls/warning_in_include.py | 7 +++++++ 5 files changed, 20 insertions(+), 11 deletions(-) create mode 100644 tests/check_framework/urls/warning_in_include.py diff --git a/tests/check_framework/test_urls.py b/tests/check_framework/test_urls.py index 7fe13c9c40..a0c113aac3 100644 --- a/tests/check_framework/test_urls.py +++ b/tests/check_framework/test_urls.py @@ -10,6 +10,14 @@ class CheckUrlsTest(SimpleTestCase): result = check_url_config(None) self.assertEqual(result, []) + @override_settings(ROOT_URLCONF='check_framework.urls.warning_in_include') + def test_check_resolver_recursive(self): + # The resolver is checked recursively (examining url()s in include()). + result = check_url_config(None) + self.assertEqual(len(result), 1) + warning = result[0] + self.assertEqual(warning.id, 'urls.W001') + @override_settings(ROOT_URLCONF='check_framework.urls.include_with_dollar') def test_include_with_dollar(self): result = check_url_config(None) diff --git a/tests/check_framework/urls/beginning_with_slash.py b/tests/check_framework/urls/beginning_with_slash.py index 859f0987d6..736e91820e 100644 --- a/tests/check_framework/urls/beginning_with_slash.py +++ b/tests/check_framework/urls/beginning_with_slash.py @@ -1,7 +1,5 @@ -from django.conf.urls import include, url +from django.conf.urls import url urlpatterns = [ - url('^', include([ - url(r'/starting-with-slash/$', lambda x: x), - ])), + url(r'/starting-with-slash/$', lambda x: x), ] diff --git a/tests/check_framework/urls/include_with_dollar.py b/tests/check_framework/urls/include_with_dollar.py index 5bb94c9688..3d4a55b41f 100644 --- a/tests/check_framework/urls/include_with_dollar.py +++ b/tests/check_framework/urls/include_with_dollar.py @@ -1,7 +1,5 @@ from django.conf.urls import include, url urlpatterns = [ - url(r'^', include([ - url(r'^include-with-dollar$', include([])), - ])), + url(r'^include-with-dollar$', include([])), ] diff --git a/tests/check_framework/urls/name_with_colon.py b/tests/check_framework/urls/name_with_colon.py index e761035ee1..f7bc0c18b4 100644 --- a/tests/check_framework/urls/name_with_colon.py +++ b/tests/check_framework/urls/name_with_colon.py @@ -1,7 +1,5 @@ -from django.conf.urls import include, url +from django.conf.urls import url urlpatterns = [ - url('^', include([ - url(r'^$', lambda x: x, name='name_with:colon'), - ])), + url(r'^$', lambda x: x, name='name_with:colon'), ] diff --git a/tests/check_framework/urls/warning_in_include.py b/tests/check_framework/urls/warning_in_include.py new file mode 100644 index 0000000000..5bb94c9688 --- /dev/null +++ b/tests/check_framework/urls/warning_in_include.py @@ -0,0 +1,7 @@ +from django.conf.urls import include, url + +urlpatterns = [ + url(r'^', include([ + url(r'^include-with-dollar$', include([])), + ])), +]