summaryrefslogtreecommitdiff
path: root/tests/check_framework
diff options
context:
space:
mode:
authorAndrew Nester <andrew.nester.dev@gmail.com>2016-12-22 00:54:15 +0300
committerTim Graham <timograham@gmail.com>2016-12-21 16:54:15 -0500
commit24fa728a476a6da3e565dbe33959ea62c02c250b (patch)
treebc60bd30f9426d267533c9b5d024858e97dc6d84 /tests/check_framework
parent3188b49ee29bb8c7183b55bda784e642a6ec3011 (diff)
Fixed #27612 -- Added a check for duplicate URL instance namespaces.
Diffstat (limited to 'tests/check_framework')
-rw-r--r--tests/check_framework/test_urls.py23
-rw-r--r--tests/check_framework/urls/non_unique_namespaces.py13
-rw-r--r--tests/check_framework/urls/unique_namespaces.py11
3 files changed, 46 insertions, 1 deletions
diff --git a/tests/check_framework/test_urls.py b/tests/check_framework/test_urls.py
index 159c41e7a9..5e7c952587 100644
--- a/tests/check_framework/test_urls.py
+++ b/tests/check_framework/test_urls.py
@@ -1,6 +1,7 @@
from django.conf import settings
+from django.core.checks.messages import Warning
from django.core.checks.urls import (
- check_url_config, get_warning_for_invalid_pattern,
+ check_url_config, check_url_namespaces_unique, get_warning_for_invalid_pattern,
)
from django.test import SimpleTestCase
from django.test.utils import override_settings
@@ -94,3 +95,23 @@ class CheckUrlsTest(SimpleTestCase):
def test_get_warning_for_invalid_pattern_other(self):
warning = get_warning_for_invalid_pattern(object())[0]
self.assertIsNone(warning.hint)
+
+ @override_settings(ROOT_URLCONF='check_framework.urls.non_unique_namespaces')
+ def test_check_non_unique_namespaces(self):
+ result = check_url_namespaces_unique(None)
+ self.assertEqual(len(result), 2)
+ non_unique_namespaces = ['app-ns1', 'app-1']
+ warning_messages = [
+ "URL namespace '{}' isn't unique. You may not be able to reverse "
+ "all URLs in this namespace".format(namespace)
+ for namespace in non_unique_namespaces
+ ]
+ for warning in result:
+ self.assertIsInstance(warning, Warning)
+ self.assertEqual('urls.W005', warning.id)
+ self.assertIn(warning.msg, warning_messages)
+
+ @override_settings(ROOT_URLCONF='check_framework.urls.unique_namespaces')
+ def test_check_unique_namespaces(self):
+ result = check_url_namespaces_unique(None)
+ self.assertEqual(result, [])
diff --git a/tests/check_framework/urls/non_unique_namespaces.py b/tests/check_framework/urls/non_unique_namespaces.py
new file mode 100644
index 0000000000..781be4c6d0
--- /dev/null
+++ b/tests/check_framework/urls/non_unique_namespaces.py
@@ -0,0 +1,13 @@
+from django.conf.urls import include, url
+
+common_url_patterns = ([
+ url(r'^app-ns1/', include([])),
+ url(r'^app-url/', include([])),
+], 'app-ns1')
+
+urlpatterns = [
+ url(r'^app-ns1-0/', include(common_url_patterns)),
+ url(r'^app-ns1-1/', include(common_url_patterns)),
+ url(r'^app-some-url/', include(([], 'app'), namespace='app-1')),
+ url(r'^app-some-url-2/', include(([], 'app'), namespace='app-1'))
+]
diff --git a/tests/check_framework/urls/unique_namespaces.py b/tests/check_framework/urls/unique_namespaces.py
new file mode 100644
index 0000000000..897f27757e
--- /dev/null
+++ b/tests/check_framework/urls/unique_namespaces.py
@@ -0,0 +1,11 @@
+from django.conf.urls import include, url
+
+common_url_patterns = ([
+ url(r'^app-ns1/', include([])),
+ url(r'^app-url/', include([])),
+], 'common')
+
+urlpatterns = [
+ url(r'^app-ns1-0/', include(common_url_patterns, namespace='app-include-1')),
+ url(r'^app-ns1-1/', include(common_url_patterns, namespace='app-include-2'))
+]