commit f984bc0d4b9ff16ee74e893a616e2f72321bc2e5
Author: Claude Paroz <claude@2xlibre.net>
Date: Wed Oct 26 09:43:21 2011 +0200
Add test for error handlers of custom urls.py
diff --git a/tests/regressiontests/test_utils/tests.py b/tests/regressiontests/test_utils/tests.py
index c192d51..f3c8c1e 100644
a
|
b
|
|
1 | 1 | from __future__ import with_statement, absolute_import |
2 | 2 | |
| 3 | from django.core.urlresolvers import get_resolver |
3 | 4 | from django.forms import EmailField |
4 | 5 | from django.test import SimpleTestCase, TestCase, skipUnlessDBFeature |
5 | 6 | from django.utils.unittest import skip |
… |
… |
class SaveRestoreWarningState(TestCase):
|
117 | 118 | self.restore_warnings_state() |
118 | 119 | |
119 | 120 | |
| 121 | class CustomUrlHandlersTests(TestCase): |
| 122 | urls = 'regressiontests.test_utils.urls' |
| 123 | |
| 124 | def test_custom_error_handlers(self): |
| 125 | """ Test that error handlers of a custom urls.py are used """ |
| 126 | from .views import empty_view |
| 127 | handler = (empty_view, {}) |
| 128 | resolver = get_resolver(None) |
| 129 | self.assertEqual(resolver.resolve404(), handler) |
| 130 | |
| 131 | |
120 | 132 | class SkippingExtraTests(TestCase): |
121 | 133 | fixtures = ['should_not_be_loaded.json'] |
122 | 134 | |
diff --git a/tests/regressiontests/test_utils/urls.py b/tests/regressiontests/test_utils/urls.py
index 31fc5cc..20d300e 100644
a
|
b
|
from django.conf.urls import patterns
|
4 | 4 | |
5 | 5 | from . import views |
6 | 6 | |
| 7 | handler404 = 'regressiontests.test_utils.views.empty_view' |
7 | 8 | |
8 | 9 | urlpatterns = patterns('', |
9 | 10 | (r'^test_utils/get_person/(\d+)/$', views.get_person), |
diff --git a/tests/regressiontests/test_utils/views.py b/tests/regressiontests/test_utils/views.py
index 5495488..eac290f 100644
a
|
b
|
from .models import Person
|
8 | 8 | |
9 | 9 | def get_person(request, pk): |
10 | 10 | person = get_object_or_404(Person, pk=pk) |
11 | | return HttpResponse(person.name) |
12 | | No newline at end of file |
| 11 | return HttpResponse(person.name) |
| 12 | |
| 13 | def empty_view(request, *args, **kwargs): |
| 14 | return HttpResponse('') |