mirror of
https://github.com/django/django.git
synced 2025-06-05 11:39:13 +00:00
Refs #23813 -- Moved URLconfs into module and tidied docstrings.
This commit is contained in:
parent
392f64842f
commit
f2975c021d
@ -12,7 +12,7 @@ def check_url_config(app_configs, **kwargs):
|
|||||||
|
|
||||||
def check_resolver(resolver):
|
def check_resolver(resolver):
|
||||||
"""
|
"""
|
||||||
Recursively check the resolver
|
Recursively check the resolver.
|
||||||
"""
|
"""
|
||||||
from django.core.urlresolvers import RegexURLPattern, RegexURLResolver
|
from django.core.urlresolvers import RegexURLPattern, RegexURLResolver
|
||||||
warnings = []
|
warnings = []
|
||||||
@ -31,7 +31,7 @@ def check_resolver(resolver):
|
|||||||
|
|
||||||
def describe_pattern(pattern):
|
def describe_pattern(pattern):
|
||||||
"""
|
"""
|
||||||
Formats the URL pattern for display in warning messages
|
Format the URL pattern for display in warning messages.
|
||||||
"""
|
"""
|
||||||
description = "'{}'".format(pattern.regex.pattern)
|
description = "'{}'".format(pattern.regex.pattern)
|
||||||
if getattr(pattern, 'name', False):
|
if getattr(pattern, 'name', False):
|
||||||
@ -41,7 +41,7 @@ def describe_pattern(pattern):
|
|||||||
|
|
||||||
def check_include_trailing_dollar(pattern):
|
def check_include_trailing_dollar(pattern):
|
||||||
"""
|
"""
|
||||||
Checks that include is not used with a regex ending with a dollar.
|
Check that include is not used with a regex ending with a dollar.
|
||||||
"""
|
"""
|
||||||
regex_pattern = pattern.regex.pattern
|
regex_pattern = pattern.regex.pattern
|
||||||
if regex_pattern.endswith('$') and not regex_pattern.endswith('\$'):
|
if regex_pattern.endswith('$') and not regex_pattern.endswith('\$'):
|
||||||
@ -58,7 +58,7 @@ def check_include_trailing_dollar(pattern):
|
|||||||
|
|
||||||
def check_pattern_startswith_slash(pattern):
|
def check_pattern_startswith_slash(pattern):
|
||||||
"""
|
"""
|
||||||
Checks that the pattern does not begin with a forward slash
|
Check that the pattern does not begin with a forward slash.
|
||||||
"""
|
"""
|
||||||
regex_pattern = pattern.regex.pattern
|
regex_pattern = pattern.regex.pattern
|
||||||
if regex_pattern.startswith('/') or regex_pattern.startswith('^/'):
|
if regex_pattern.startswith('/') or regex_pattern.startswith('^/'):
|
||||||
@ -74,7 +74,7 @@ def check_pattern_startswith_slash(pattern):
|
|||||||
|
|
||||||
def check_pattern_name(pattern):
|
def check_pattern_name(pattern):
|
||||||
"""
|
"""
|
||||||
Checks that the pattern name does not contain a colon
|
Check that the pattern name does not contain a colon.
|
||||||
"""
|
"""
|
||||||
if pattern.name is not None and ":" in pattern.name:
|
if pattern.name is not None and ":" in pattern.name:
|
||||||
warning = Warning(
|
warning = Warning(
|
||||||
|
@ -4,12 +4,12 @@ from django.test.utils import override_settings
|
|||||||
|
|
||||||
|
|
||||||
class CheckUrlsTest(SimpleTestCase):
|
class CheckUrlsTest(SimpleTestCase):
|
||||||
@override_settings(ROOT_URLCONF='check_framework.urls_no_warnings')
|
@override_settings(ROOT_URLCONF='check_framework.urls.no_warnings')
|
||||||
def test_include_no_warnings(self):
|
def test_no_warnings(self):
|
||||||
result = check_url_config(None)
|
result = check_url_config(None)
|
||||||
self.assertEqual(result, [])
|
self.assertEqual(result, [])
|
||||||
|
|
||||||
@override_settings(ROOT_URLCONF='check_framework.urls_include')
|
@override_settings(ROOT_URLCONF='check_framework.urls.include_with_dollar')
|
||||||
def test_include_with_dollar(self):
|
def test_include_with_dollar(self):
|
||||||
result = check_url_config(None)
|
result = check_url_config(None)
|
||||||
self.assertEqual(len(result), 1)
|
self.assertEqual(len(result), 1)
|
||||||
@ -18,8 +18,8 @@ class CheckUrlsTest(SimpleTestCase):
|
|||||||
expected_msg = "Your URL pattern '^include-with-dollar$' uses include with a regex ending with a '$'."
|
expected_msg = "Your URL pattern '^include-with-dollar$' uses include with a regex ending with a '$'."
|
||||||
self.assertIn(expected_msg, warning.msg)
|
self.assertIn(expected_msg, warning.msg)
|
||||||
|
|
||||||
@override_settings(ROOT_URLCONF='check_framework.urls_slash')
|
@override_settings(ROOT_URLCONF='check_framework.urls.beginning_with_slash')
|
||||||
def test_url_beginning_with_slash(self):
|
def test_beginning_with_slash(self):
|
||||||
result = check_url_config(None)
|
result = check_url_config(None)
|
||||||
self.assertEqual(len(result), 1)
|
self.assertEqual(len(result), 1)
|
||||||
warning = result[0]
|
warning = result[0]
|
||||||
@ -27,8 +27,8 @@ class CheckUrlsTest(SimpleTestCase):
|
|||||||
expected_msg = "Your URL pattern '/starting-with-slash/$' has a regex beginning with a '/'"
|
expected_msg = "Your URL pattern '/starting-with-slash/$' has a regex beginning with a '/'"
|
||||||
self.assertIn(expected_msg, warning.msg)
|
self.assertIn(expected_msg, warning.msg)
|
||||||
|
|
||||||
@override_settings(ROOT_URLCONF='check_framework.urls_name')
|
@override_settings(ROOT_URLCONF='check_framework.urls.name_with_colon')
|
||||||
def test_url_pattern_name_with_colon(self):
|
def test_name_with_colon(self):
|
||||||
result = check_url_config(None)
|
result = check_url_config(None)
|
||||||
self.assertEqual(len(result), 1)
|
self.assertEqual(len(result), 1)
|
||||||
warning = result[0]
|
warning = result[0]
|
||||||
|
0
tests/check_framework/urls/__init__.py
Normal file
0
tests/check_framework/urls/__init__.py
Normal file
7
tests/check_framework/urls/beginning_with_slash.py
Normal file
7
tests/check_framework/urls/beginning_with_slash.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
from django.conf.urls import include, url
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
url('^', include([
|
||||||
|
url(r'/starting-with-slash/$', lambda x: x),
|
||||||
|
])),
|
||||||
|
]
|
7
tests/check_framework/urls/name_with_colon.py
Normal file
7
tests/check_framework/urls/name_with_colon.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
from django.conf.urls import include, url
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
url('^', include([
|
||||||
|
url(r'^$', lambda x: x, name='name_with:colon'),
|
||||||
|
])),
|
||||||
|
]
|
9
tests/check_framework/urls/no_warnings.py
Normal file
9
tests/check_framework/urls/no_warnings.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
from django.conf.urls import include, url
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
url(r'^foo/', lambda x: x, name='foo'),
|
||||||
|
# This dollar is ok as it is escaped
|
||||||
|
url(r'^\$', include([
|
||||||
|
url(r'^bar/$', lambda x: x, name='bar'),
|
||||||
|
])),
|
||||||
|
]
|
@ -1,13 +0,0 @@
|
|||||||
from django.conf.urls import include, url
|
|
||||||
from django.http import HttpResponse
|
|
||||||
|
|
||||||
|
|
||||||
def view(request):
|
|
||||||
return HttpResponse('')
|
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
|
||||||
url('^', include([
|
|
||||||
url(r'^$', view, name='name_with:colon'),
|
|
||||||
])),
|
|
||||||
]
|
|
@ -1,15 +0,0 @@
|
|||||||
from django.conf.urls import include, url
|
|
||||||
from django.http import HttpResponse
|
|
||||||
|
|
||||||
|
|
||||||
def view(request):
|
|
||||||
return HttpResponse('')
|
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
|
||||||
url(r'^foo/', view, name='foo'),
|
|
||||||
# This dollar is ok as it is escaped
|
|
||||||
url(r'^\$', include([
|
|
||||||
url(r'^bar/$', view, name='bar'),
|
|
||||||
])),
|
|
||||||
]
|
|
@ -1,13 +0,0 @@
|
|||||||
from django.conf.urls import include, url
|
|
||||||
from django.http import HttpResponse
|
|
||||||
|
|
||||||
|
|
||||||
def view(request):
|
|
||||||
return HttpResponse('')
|
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
|
||||||
url('^', include([
|
|
||||||
url(r'/starting-with-slash/$', view),
|
|
||||||
])),
|
|
||||||
]
|
|
Loading…
x
Reference in New Issue
Block a user