mirror of https://github.com/django/django.git
Cleaned up urlpatterns_reverse tests.
This commit is contained in:
parent
c9f1a12925
commit
a23ea398e8
|
@ -173,11 +173,13 @@ class NoURLPatternsTests(TestCase):
|
|||
"""
|
||||
resolver = RegexURLResolver(r'^$', settings.ROOT_URLCONF)
|
||||
|
||||
self.assertRaisesMessage(ImproperlyConfigured,
|
||||
self.assertRaisesMessage(
|
||||
ImproperlyConfigured,
|
||||
"The included urlconf 'urlpatterns_reverse.no_urls' does not "
|
||||
"appear to have any patterns in it. If you see valid patterns in "
|
||||
"the file then the issue is probably caused by a circular import.",
|
||||
getattr, resolver, 'url_patterns')
|
||||
getattr, resolver, 'url_patterns'
|
||||
)
|
||||
|
||||
|
||||
@override_settings(ROOT_URLCONF='urlpatterns_reverse.urls')
|
||||
|
@ -198,8 +200,10 @@ class URLPatternReverse(TestCase):
|
|||
self.assertRaises(NoReverseMatch, reverse, None)
|
||||
|
||||
def test_prefix_braces(self):
|
||||
self.assertEqual('/%7B%7Binvalid%7D%7D/includes/non_path_include/',
|
||||
reverse('non_path_include', prefix='/{{invalid}}/'))
|
||||
self.assertEqual(
|
||||
'/%7B%7Binvalid%7D%7D/includes/non_path_include/',
|
||||
reverse('non_path_include', prefix='/{{invalid}}/')
|
||||
)
|
||||
|
||||
def test_prefix_parenthesis(self):
|
||||
# Parentheses are allowed and should not cause errors or be escaped
|
||||
|
@ -213,8 +217,10 @@ class URLPatternReverse(TestCase):
|
|||
)
|
||||
|
||||
def test_prefix_format_char(self):
|
||||
self.assertEqual('/bump%2520map/includes/non_path_include/',
|
||||
reverse('non_path_include', prefix='/bump%20map/'))
|
||||
self.assertEqual(
|
||||
'/bump%2520map/includes/non_path_include/',
|
||||
reverse('non_path_include', prefix='/bump%20map/')
|
||||
)
|
||||
|
||||
def test_non_urlsafe_prefix_with_args(self):
|
||||
# Regression for #20022, adjusted for #24013 because ~ is an unreserved
|
||||
|
@ -550,8 +556,7 @@ class RequestURLconfTests(TestCase):
|
|||
def test_urlconf(self):
|
||||
response = self.client.get('/test/me/')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.content, b'outer:/test/me/,'
|
||||
b'inner:/inner_urlconf/second_test/')
|
||||
self.assertEqual(response.content, b'outer:/test/me/,inner:/inner_urlconf/second_test/')
|
||||
response = self.client.get('/inner_urlconf/second_test/')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
response = self.client.get('/second_test/')
|
||||
|
@ -741,8 +746,7 @@ class ErroneousViewTests(TestCase):
|
|||
def test_erroneous_reverse(self):
|
||||
"""
|
||||
Ensure that a useful exception is raised when a regex is invalid in the
|
||||
URLConf.
|
||||
Refs #6170.
|
||||
URLConf (#6170).
|
||||
"""
|
||||
# The regex error will be hit before NoReverseMatch can be raised
|
||||
self.assertRaises(ImproperlyConfigured, reverse, 'whatever blah blah')
|
||||
|
@ -750,8 +754,7 @@ class ErroneousViewTests(TestCase):
|
|||
|
||||
class ViewLoadingTests(TestCase):
|
||||
def test_view_loading(self):
|
||||
self.assertEqual(get_callable('urlpatterns_reverse.views.empty_view'),
|
||||
empty_view)
|
||||
self.assertEqual(get_callable('urlpatterns_reverse.views.empty_view'), empty_view)
|
||||
|
||||
# passing a callable should return the callable
|
||||
self.assertEqual(get_callable(empty_view), empty_view)
|
||||
|
@ -759,14 +762,12 @@ class ViewLoadingTests(TestCase):
|
|||
def test_exceptions(self):
|
||||
# A missing view (identified by an AttributeError) should raise
|
||||
# ViewDoesNotExist, ...
|
||||
six.assertRaisesRegex(self, ViewDoesNotExist,
|
||||
".*View does not exist in.*",
|
||||
get_callable,
|
||||
'urlpatterns_reverse.views.i_should_not_exist')
|
||||
with six.assertRaisesRegex(self, ViewDoesNotExist, ".*View does not exist in.*"):
|
||||
get_callable('urlpatterns_reverse.views.i_should_not_exist')
|
||||
# ... but if the AttributeError is caused by something else don't
|
||||
# swallow it.
|
||||
self.assertRaises(AttributeError, get_callable,
|
||||
'urlpatterns_reverse.views_broken.i_am_broken')
|
||||
with self.assertRaises(AttributeError):
|
||||
get_callable('urlpatterns_reverse.views_broken.i_am_broken')
|
||||
|
||||
|
||||
class IncludeTests(SimpleTestCase):
|
||||
|
|
Loading…
Reference in New Issue