[1.2.X] Migrated urlpatterns_reverse doctests. Thanks to Stephan Jaekel.

Backport of r13893 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@13914 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee 2010-09-27 15:36:30 +00:00
parent 8425cdef45
commit 2f480e0882
1 changed files with 21 additions and 13 deletions

View File

@ -1,19 +1,6 @@
"""
Unit tests for reverse URL lookups.
"""
__test__ = {'API_TESTS': """
RegexURLResolver should raise an exception when no urlpatterns exist.
>>> from django.core.urlresolvers import RegexURLResolver
>>> no_urls = 'regressiontests.urlpatterns_reverse.no_urls'
>>> resolver = RegexURLResolver(r'^$', no_urls)
>>> resolver.url_patterns
Traceback (most recent call last):
...
ImproperlyConfigured: The included urlconf regressiontests.urlpatterns_reverse.no_urls doesn't have any patterns in it
"""}
import unittest
from django.conf import settings
@ -107,6 +94,27 @@ test_data = (
)
class NoURLPatternsTests(TestCase):
urls = 'regressiontests.urlpatterns_reverse.no_urls'
def assertRaisesErrorWithMessage(self, error, message, callable,
*args, **kwargs):
self.assertRaises(error, callable, *args, **kwargs)
try:
callable(*args, **kwargs)
except error, e:
self.assertEqual(message, str(e))
def test_no_urls_exception(self):
"""
RegexURLResolver should raise an exception when no urlpatterns exist.
"""
resolver = RegexURLResolver(r'^$', self.urls)
self.assertRaisesErrorWithMessage(ImproperlyConfigured,
"The included urlconf regressiontests.urlpatterns_reverse.no_urls "\
"doesn't have any patterns in it", getattr, resolver, 'url_patterns')
class URLPatternReverse(TestCase):
urls = 'regressiontests.urlpatterns_reverse.urls'