Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
  • Loading branch information...
commit 2790cf482d5e5e428759c5e8e6e63db3c740f389 1 parent cb33aa1
@freakboy3742 freakboy3742 authored
View
45 tests/regressiontests/special_headers/tests.py
@@ -8,33 +8,52 @@ def test_xheaders(self):
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)
View
3  tests/regressiontests/special_headers/urls.py
@@ -6,5 +6,6 @@
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())),
)
View
6 tests/regressiontests/special_headers/views.py
@@ -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()
Please sign in to comment.
Something went wrong with that request. Please try again.