mirror of
https://github.com/django/django.git
synced 2024-12-29 04:26:28 +00:00
48 lines
1.8 KiB
Python
48 lines
1.8 KiB
Python
from django.contrib.auth.models import User
|
|
|
|
from .tests import AdminDocsTestCase, TestDataMixin
|
|
|
|
|
|
class XViewMiddlewareTest(TestDataMixin, AdminDocsTestCase):
|
|
|
|
def test_xview_func(self):
|
|
user = User.objects.get(username='super')
|
|
response = self.client.head('/xview/func/')
|
|
self.assertNotIn('X-View', response)
|
|
self.client.force_login(self.superuser)
|
|
response = self.client.head('/xview/func/')
|
|
self.assertIn('X-View', response)
|
|
self.assertEqual(response['X-View'], 'admin_docs.views.xview')
|
|
user.is_staff = False
|
|
user.save()
|
|
response = self.client.head('/xview/func/')
|
|
self.assertNotIn('X-View', response)
|
|
user.is_staff = True
|
|
user.is_active = False
|
|
user.save()
|
|
response = self.client.head('/xview/func/')
|
|
self.assertNotIn('X-View', response)
|
|
|
|
def test_xview_class(self):
|
|
user = User.objects.get(username='super')
|
|
response = self.client.head('/xview/class/')
|
|
self.assertNotIn('X-View', response)
|
|
self.client.force_login(self.superuser)
|
|
response = self.client.head('/xview/class/')
|
|
self.assertIn('X-View', response)
|
|
self.assertEqual(response['X-View'], 'admin_docs.views.XViewClass')
|
|
user.is_staff = False
|
|
user.save()
|
|
response = self.client.head('/xview/class/')
|
|
self.assertNotIn('X-View', response)
|
|
user.is_staff = True
|
|
user.is_active = False
|
|
user.save()
|
|
response = self.client.head('/xview/class/')
|
|
self.assertNotIn('X-View', response)
|
|
|
|
def test_callable_object_view(self):
|
|
self.client.force_login(self.superuser)
|
|
response = self.client.head('/xview/callable_object/')
|
|
self.assertEqual(response['X-View'], 'admin_docs.views.XViewCallableObject')
|