PageRenderTime 65ms CodeModel.GetById 55ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/regressiontests/special_headers/tests.py

https://code.google.com/p/mango-py/
Python | 59 lines | 54 code | 4 blank | 1 comment | 12 complexity | 9300962f41edc8414166656f99dd2937 MD5 | raw file
 1from django.test import TestCase
 2from django.contrib.auth.models import User
 3
 4class SpecialHeadersTest(TestCase):
 5    fixtures = ['data.xml']
 6
 7    def test_xheaders(self):
 8        user = User.objects.get(username='super')
 9        response = self.client.get('/special_headers/article/1/')
10        # import pdb; pdb.set_trace()
11        self.assertFalse('X-Object-Type' in response)
12        self.client.login(username='super', password='secret')
13        response = self.client.get('/special_headers/article/1/')
14        self.assertTrue('X-Object-Type' in response)
15        user.is_staff = False
16        user.save()
17        response = self.client.get('/special_headers/article/1/')
18        self.assertFalse('X-Object-Type' in response)
19        user.is_staff = True
20        user.is_active = False
21        user.save()
22        response = self.client.get('/special_headers/article/1/')
23        self.assertFalse('X-Object-Type' in response)
24
25    def test_xview_func(self):
26        user = User.objects.get(username='super')
27        response = self.client.head('/special_headers/xview/func/')
28        self.assertFalse('X-View' in response)
29        self.client.login(username='super', password='secret')
30        response = self.client.head('/special_headers/xview/func/')
31        self.assertTrue('X-View' in response)
32        self.assertEqual(response['X-View'], 'regressiontests.special_headers.views.xview')
33        user.is_staff = False
34        user.save()
35        response = self.client.head('/special_headers/xview/func/')
36        self.assertFalse('X-View' in response)
37        user.is_staff = True
38        user.is_active = False
39        user.save()
40        response = self.client.head('/special_headers/xview/func/')
41        self.assertFalse('X-View' in response)
42
43    def test_xview_class(self):
44        user = User.objects.get(username='super')
45        response = self.client.head('/special_headers/xview/class/')
46        self.assertFalse('X-View' in response)
47        self.client.login(username='super', password='secret')
48        response = self.client.head('/special_headers/xview/class/')
49        self.assertTrue('X-View' in response)
50        self.assertEqual(response['X-View'], 'regressiontests.special_headers.views.XViewClass')
51        user.is_staff = False
52        user.save()
53        response = self.client.head('/special_headers/xview/class/')
54        self.assertFalse('X-View' in response)
55        user.is_staff = True
56        user.is_active = False
57        user.save()
58        response = self.client.head('/special_headers/xview/class/')
59        self.assertFalse('X-View' in response)