test_decorators.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. from django.core.urlresolvers import reverse
  2. from misago.users.testutils import UserTestCase
  3. class DenyAuthenticatedTests(UserTestCase):
  4. ajax_header = {'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest'}
  5. def test_success(self):
  6. """deny_authenticated decorator allowed guest request"""
  7. response = self.client.get(reverse('misago:request_password_reset'))
  8. self.assertEqual(response.status_code, 200)
  9. def test_fail(self):
  10. """deny_authenticated decorator blocked authenticated request"""
  11. self.login_user(self.get_authenticated_user())
  12. response = self.client.get(reverse('misago:request_password_reset'))
  13. self.assertEqual(response.status_code, 302)
  14. response = self.client.get(reverse('misago:request_password_reset'),
  15. **self.ajax_header)
  16. self.assertEqual(response.status_code, 403)
  17. class DenyGuestsTests(UserTestCase):
  18. ajax_header = {'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest'}
  19. def test_success(self):
  20. """deny_guests decorator allowed authenticated request"""
  21. self.login_user(self.get_authenticated_user())
  22. response = self.client.post(
  23. reverse('misago:usercp_change_forum_options'))
  24. self.assertEqual(response.status_code, 200)
  25. def test_fail(self):
  26. """deny_guests decorator blocked authenticated request"""
  27. response = self.client.post(
  28. reverse('misago:usercp_change_forum_options'))
  29. self.assertEqual(response.status_code, 302)
  30. response = self.client.get(
  31. reverse('misago:usercp_change_forum_options'), **self.ajax_header)
  32. self.assertEqual(response.status_code, 403)