From e683beb6079122cd8ab90909ea8c4e7a6cfde36c Mon Sep 17 00:00:00 2001 From: Luke Plant Date: Mon, 23 May 2011 16:08:45 +0000 Subject: [PATCH] Changed utils/decorators.py tests to use RequestFactory git-svn-id: http://code.djangoproject.com/svn/django/trunk@16272 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/regressiontests/utils/decorators.py | 26 ++++++++++++++++++++--- tests/regressiontests/utils/urls.py | 8 ------- tests/regressiontests/utils/views.py | 17 --------------- tests/urls.py | 1 - 4 files changed, 23 insertions(+), 29 deletions(-) delete mode 100644 tests/regressiontests/utils/urls.py delete mode 100644 tests/regressiontests/utils/views.py diff --git a/tests/regressiontests/utils/decorators.py b/tests/regressiontests/utils/decorators.py index ca9214f787..db32418de7 100644 --- a/tests/regressiontests/utils/decorators.py +++ b/tests/regressiontests/utils/decorators.py @@ -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): """ Tests for view decorators created using ``django.utils.decorators.decorator_from_middleware``. """ + rf = RequestFactory() def test_process_view_middleware(self): """ Test a middleware that implements process_view. """ - self.client.get('/utils/xview/') + xview(self.rf.get('/')) def test_callable_process_view_middleware(self): """ Test a middleware that implements process_view, operating on a callable class. """ - self.client.get('/utils/class_xview/') + class_xview(self.rf.get('/')) diff --git a/tests/regressiontests/utils/urls.py b/tests/regressiontests/utils/urls.py deleted file mode 100644 index ba09d14b3d..0000000000 --- a/tests/regressiontests/utils/urls.py +++ /dev/null @@ -1,8 +0,0 @@ -from django.conf.urls.defaults import * - -import views - -urlpatterns = patterns('', - (r'^xview/$', views.xview), - (r'^class_xview/$', views.class_xview), -) diff --git a/tests/regressiontests/utils/views.py b/tests/regressiontests/utils/views.py deleted file mode 100644 index ef97c6502d..0000000000 --- a/tests/regressiontests/utils/views.py +++ /dev/null @@ -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()) diff --git a/tests/urls.py b/tests/urls.py index 77a75784ec..b3f719d840 100644 --- a/tests/urls.py +++ b/tests/urls.py @@ -29,5 +29,4 @@ urlpatterns = patterns('', # admin widget tests (r'widget_admin/', include('regressiontests.admin_widgets.urls')), - (r'^utils/', include('regressiontests.utils.urls')), )