mirror of
https://github.com/django/django.git
synced 2025-07-05 18:29:11 +00:00
[1.3.X] Changed utils/decorators.py tests to use RequestFactory
Backport of [16272] from trunk. Backported to make the backport of a bugfix (regression) easier. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.3.X@16278 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
18ecfad767
commit
afa092853f
@ -1,19 +1,39 @@
|
|||||||
from django.test import TestCase
|
from django.http import HttpResponse
|
||||||
|
from django.middleware.doc import XViewMiddleware
|
||||||
|
from django.test import TestCase, RequestFactory
|
||||||
|
from django.utils.decorators import decorator_from_middleware
|
||||||
|
|
||||||
|
|
||||||
|
xview_dec = decorator_from_middleware(XViewMiddleware)
|
||||||
|
|
||||||
|
|
||||||
|
@xview_dec
|
||||||
|
def xview(request):
|
||||||
|
return HttpResponse()
|
||||||
|
|
||||||
|
|
||||||
|
class ClassXView(object):
|
||||||
|
def __call__(self, request):
|
||||||
|
return HttpResponse()
|
||||||
|
|
||||||
|
class_xview = xview_dec(ClassXView())
|
||||||
|
|
||||||
|
|
||||||
class DecoratorFromMiddlewareTests(TestCase):
|
class DecoratorFromMiddlewareTests(TestCase):
|
||||||
"""
|
"""
|
||||||
Tests for view decorators created using
|
Tests for view decorators created using
|
||||||
``django.utils.decorators.decorator_from_middleware``.
|
``django.utils.decorators.decorator_from_middleware``.
|
||||||
"""
|
"""
|
||||||
|
rf = RequestFactory()
|
||||||
|
|
||||||
def test_process_view_middleware(self):
|
def test_process_view_middleware(self):
|
||||||
"""
|
"""
|
||||||
Test a middleware that implements process_view.
|
Test a middleware that implements process_view.
|
||||||
"""
|
"""
|
||||||
self.client.get('/utils/xview/')
|
xview(self.rf.get('/'))
|
||||||
|
|
||||||
def test_callable_process_view_middleware(self):
|
def test_callable_process_view_middleware(self):
|
||||||
"""
|
"""
|
||||||
Test a middleware that implements process_view, operating on a callable class.
|
Test a middleware that implements process_view, operating on a callable class.
|
||||||
"""
|
"""
|
||||||
self.client.get('/utils/class_xview/')
|
class_xview(self.rf.get('/'))
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
from django.conf.urls.defaults import *
|
|
||||||
|
|
||||||
import views
|
|
||||||
|
|
||||||
urlpatterns = patterns('',
|
|
||||||
(r'^xview/$', views.xview),
|
|
||||||
(r'^class_xview/$', views.class_xview),
|
|
||||||
)
|
|
@ -1,17 +0,0 @@
|
|||||||
from django.http import HttpResponse
|
|
||||||
from django.utils.decorators import decorator_from_middleware
|
|
||||||
from django.middleware.doc import XViewMiddleware
|
|
||||||
|
|
||||||
|
|
||||||
xview_dec = decorator_from_middleware(XViewMiddleware)
|
|
||||||
|
|
||||||
def xview(request):
|
|
||||||
return HttpResponse()
|
|
||||||
xview = xview_dec(xview)
|
|
||||||
|
|
||||||
|
|
||||||
class ClassXView(object):
|
|
||||||
def __call__(self, request):
|
|
||||||
return HttpResponse()
|
|
||||||
|
|
||||||
class_xview = xview_dec(ClassXView())
|
|
@ -29,8 +29,6 @@ urlpatterns = patterns('',
|
|||||||
# admin widget tests
|
# admin widget tests
|
||||||
(r'widget_admin/', include('regressiontests.admin_widgets.urls')),
|
(r'widget_admin/', include('regressiontests.admin_widgets.urls')),
|
||||||
|
|
||||||
(r'^utils/', include('regressiontests.utils.urls')),
|
|
||||||
|
|
||||||
# test urlconf for syndication tests
|
# test urlconf for syndication tests
|
||||||
(r'^syndication/', include('regressiontests.syndication.urls')),
|
(r'^syndication/', include('regressiontests.syndication.urls')),
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user