Ticket #17113: test_custom_handlers.diff

File test_custom_handlers.diff, 2.2 KB (added by Claude Paroz, 13 years ago)

Test that custom error handler of custom urls.py is called

  • tests/regressiontests/test_utils/tests.py

    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  
    11from __future__ import with_statement, absolute_import
    22
     3from django.core.urlresolvers import get_resolver
    34from django.forms import EmailField
    45from django.test import SimpleTestCase, TestCase, skipUnlessDBFeature
    56from django.utils.unittest import skip
    class SaveRestoreWarningState(TestCase):  
    117118        self.restore_warnings_state()
    118119
    119120
     121class 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
    120132class SkippingExtraTests(TestCase):
    121133    fixtures = ['should_not_be_loaded.json']
    122134
  • tests/regressiontests/test_utils/urls.py

    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  
    44
    55from . import views
    66
     7handler404 = 'regressiontests.test_utils.views.empty_view'
    78
    89urlpatterns = patterns('',
    910    (r'^test_utils/get_person/(\d+)/$', views.get_person),
  • tests/regressiontests/test_utils/views.py

    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  
    88
    99def get_person(request, pk):
    1010    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
     13def empty_view(request, *args, **kwargs):
     14    return HttpResponse('')
Back to Top