Fixed #13842 -- Added tests to verify that XViewMiddleware works with class-based views.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14269 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
cb33aa1cc8
commit
2790cf482d
|
@ -8,33 +8,52 @@ class SpecialHeadersTest(TestCase):
|
|||
user = User.objects.get(username='super')
|
||||
response = self.client.get('/special_headers/article/1/')
|
||||
# import pdb; pdb.set_trace()
|
||||
self.failUnless('X-Object-Type' not in response)
|
||||
self.assertFalse('X-Object-Type' in response)
|
||||
self.client.login(username='super', password='secret')
|
||||
response = self.client.get('/special_headers/article/1/')
|
||||
self.failUnless('X-Object-Type' in response)
|
||||
self.assertTrue('X-Object-Type' in response)
|
||||
user.is_staff = False
|
||||
user.save()
|
||||
response = self.client.get('/special_headers/article/1/')
|
||||
self.failUnless('X-Object-Type' not in response)
|
||||
self.assertFalse('X-Object-Type' in response)
|
||||
user.is_staff = True
|
||||
user.is_active = False
|
||||
user.save()
|
||||
response = self.client.get('/special_headers/article/1/')
|
||||
self.failUnless('X-Object-Type' not in response)
|
||||
self.assertFalse('X-Object-Type' in response)
|
||||
|
||||
def test_xview(self):
|
||||
def test_xview_func(self):
|
||||
user = User.objects.get(username='super')
|
||||
response = self.client.head('/special_headers/xview/')
|
||||
self.failUnless('X-View' not in response)
|
||||
response = self.client.head('/special_headers/xview/func/')
|
||||
self.assertFalse('X-View' in response)
|
||||
self.client.login(username='super', password='secret')
|
||||
response = self.client.head('/special_headers/xview/')
|
||||
self.failUnless('X-View' in response)
|
||||
response = self.client.head('/special_headers/xview/func/')
|
||||
self.assertTrue('X-View' in response)
|
||||
self.assertEqual(response['X-View'], 'regressiontests.special_headers.views.xview')
|
||||
user.is_staff = False
|
||||
user.save()
|
||||
response = self.client.head('/special_headers/xview/')
|
||||
self.failUnless('X-View' not in response)
|
||||
response = self.client.head('/special_headers/xview/func/')
|
||||
self.assertFalse('X-View' in response)
|
||||
user.is_staff = True
|
||||
user.is_active = False
|
||||
user.save()
|
||||
response = self.client.head('/special_headers/xview/')
|
||||
self.failUnless('X-View' not in response)
|
||||
response = self.client.head('/special_headers/xview/func/')
|
||||
self.assertFalse('X-View' in response)
|
||||
|
||||
def test_xview_class(self):
|
||||
user = User.objects.get(username='super')
|
||||
response = self.client.head('/special_headers/xview/class/')
|
||||
self.assertFalse('X-View' in response)
|
||||
self.client.login(username='super', password='secret')
|
||||
response = self.client.head('/special_headers/xview/class/')
|
||||
self.assertTrue('X-View' in response)
|
||||
self.assertEqual(response['X-View'], 'regressiontests.special_headers.views.XViewClass')
|
||||
user.is_staff = False
|
||||
user.save()
|
||||
response = self.client.head('/special_headers/xview/class/')
|
||||
self.assertFalse('X-View' in response)
|
||||
user.is_staff = True
|
||||
user.is_active = False
|
||||
user.save()
|
||||
response = self.client.head('/special_headers/xview/class/')
|
||||
self.assertFalse('X-View' in response)
|
||||
|
|
|
@ -6,5 +6,6 @@ import views
|
|||
|
||||
urlpatterns = patterns('',
|
||||
(r'^article/(?P<object_id>\d+)/$', object_detail, {'queryset': Article.objects.all()}),
|
||||
(r'^xview/$', views.xview),
|
||||
(r'^xview/func/$', views.xview_dec(views.xview)),
|
||||
(r'^xview/class/$', views.xview_dec(views.XViewClass.as_view())),
|
||||
)
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
# -*- coding:utf-8 -*-
|
||||
from django.http import HttpResponse
|
||||
from django.utils.decorators import decorator_from_middleware
|
||||
from django.views.generic import View
|
||||
from django.middleware.doc import XViewMiddleware
|
||||
|
||||
xview_dec = decorator_from_middleware(XViewMiddleware)
|
||||
|
||||
def xview(request):
|
||||
return HttpResponse()
|
||||
xview = xview_dec(xview)
|
||||
|
||||
class XViewClass(View):
|
||||
def get(request):
|
||||
return HttpResponse()
|
||||
|
|
Loading…
Reference in New Issue