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