2010-01-10 17:21:52 +00:00
|
|
|
from django.contrib.auth.models import User
|
2011-10-13 21:34:56 +00:00
|
|
|
from django.test import TestCase
|
2012-04-30 18:38:44 +00:00
|
|
|
from django.test.utils import override_settings
|
2010-01-10 17:21:52 +00:00
|
|
|
|
2011-04-02 13:26:54 +00:00
|
|
|
|
2012-04-30 18:38:44 +00:00
|
|
|
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
|
2010-01-10 17:21:52 +00:00
|
|
|
class SpecialHeadersTest(TestCase):
|
|
|
|
fixtures = ['data.xml']
|
2011-04-02 13:27:17 +00:00
|
|
|
urls = 'regressiontests.special_headers.urls'
|
2010-01-10 17:21:52 +00:00
|
|
|
|
|
|
|
def test_xheaders(self):
|
|
|
|
user = User.objects.get(username='super')
|
|
|
|
response = self.client.get('/special_headers/article/1/')
|
2010-10-18 23:58:06 +00:00
|
|
|
self.assertFalse('X-Object-Type' in response)
|
2010-01-10 17:21:52 +00:00
|
|
|
self.client.login(username='super', password='secret')
|
|
|
|
response = self.client.get('/special_headers/article/1/')
|
2010-10-18 23:58:06 +00:00
|
|
|
self.assertTrue('X-Object-Type' in response)
|
2010-01-10 17:21:52 +00:00
|
|
|
user.is_staff = False
|
|
|
|
user.save()
|
|
|
|
response = self.client.get('/special_headers/article/1/')
|
2010-10-18 23:58:06 +00:00
|
|
|
self.assertFalse('X-Object-Type' in response)
|
2010-01-10 17:21:52 +00:00
|
|
|
user.is_staff = True
|
|
|
|
user.is_active = False
|
|
|
|
user.save()
|
|
|
|
response = self.client.get('/special_headers/article/1/')
|
2010-10-18 23:58:06 +00:00
|
|
|
self.assertFalse('X-Object-Type' in response)
|
2010-01-10 17:21:52 +00:00
|
|
|
|
2010-10-18 23:58:06 +00:00
|
|
|
def test_xview_func(self):
|
2010-01-10 17:21:52 +00:00
|
|
|
user = User.objects.get(username='super')
|
2010-10-18 23:58:06 +00:00
|
|
|
response = self.client.head('/special_headers/xview/func/')
|
|
|
|
self.assertFalse('X-View' in response)
|
2010-01-10 17:21:52 +00:00
|
|
|
self.client.login(username='super', password='secret')
|
2010-10-18 23:58:06 +00:00
|
|
|
response = self.client.head('/special_headers/xview/func/')
|
|
|
|
self.assertTrue('X-View' in response)
|
|
|
|
self.assertEqual(response['X-View'], 'regressiontests.special_headers.views.xview')
|
2010-01-10 17:21:52 +00:00
|
|
|
user.is_staff = False
|
|
|
|
user.save()
|
2010-10-18 23:58:06 +00:00
|
|
|
response = self.client.head('/special_headers/xview/func/')
|
|
|
|
self.assertFalse('X-View' in response)
|
2010-01-10 17:21:52 +00:00
|
|
|
user.is_staff = True
|
|
|
|
user.is_active = False
|
|
|
|
user.save()
|
2010-10-18 23:58:06 +00:00
|
|
|
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)
|