test_decorators.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. from django.core.urlresolvers import reverse
  2. from misago.users.testutils import UserTestCase
  3. class DenyAuthenticatedTests(UserTestCase):
  4. def test_success(self):
  5. """deny_authenticated decorator allowed guest request"""
  6. response = self.client.post('/api/auth/')
  7. self.assertEqual(response.status_code, 400)
  8. def test_fail(self):
  9. """deny_authenticated decorator denied authenticated request"""
  10. self.login_user(self.get_authenticated_user())
  11. response = self.client.post('/api/auth/')
  12. self.assertEqual(response.status_code, 403)
  13. class DeflectAuthenticatedTests(UserTestCase):
  14. def test_success(self):
  15. """deflect_authenticated decorator allowed guest request"""
  16. response = self.client.get(reverse('misago:forgotten_password'))
  17. self.assertEqual(response.status_code, 200)
  18. def test_fail(self):
  19. """deflect_authenticated decorator deflected authenticated request"""
  20. self.login_user(self.get_authenticated_user())
  21. response = self.client.get(reverse('misago:forgotten_password'))
  22. self.assertEqual(response.status_code, 302)
  23. class DeflectGuestsTests(UserTestCase):
  24. def test_success(self):
  25. """deflect_guests decorator allowed authenticated request"""
  26. self.login_user(self.get_authenticated_user())
  27. response = self.client.post(
  28. reverse('misago:usercp_change_forum_options'))
  29. self.assertEqual(response.status_code, 200)
  30. def test_fail(self):
  31. """deflect_guests decorator deflected authenticated request"""
  32. response = self.client.post(
  33. reverse('misago:usercp_change_forum_options'))
  34. self.assertEqual(response.status_code, 302)