diff --git a/tests/regressiontests/special_headers/tests.py b/tests/regressiontests/special_headers/tests.py index f304bfa932..4e2741b6dc 100644 --- a/tests/regressiontests/special_headers/tests.py +++ b/tests/regressiontests/special_headers/tests.py @@ -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) diff --git a/tests/regressiontests/special_headers/urls.py b/tests/regressiontests/special_headers/urls.py index 721f60ad94..c6b05d6266 100644 --- a/tests/regressiontests/special_headers/urls.py +++ b/tests/regressiontests/special_headers/urls.py @@ -6,5 +6,6 @@ import views urlpatterns = patterns('', (r'^article/(?P\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())), ) diff --git a/tests/regressiontests/special_headers/views.py b/tests/regressiontests/special_headers/views.py index 7a012038a1..7ec99ad4e1 100644 --- a/tests/regressiontests/special_headers/views.py +++ b/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()