test_decorators.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. from django.core.urlresolvers import reverse
  2. from misago.users.models import BAN_IP, Ban
  3. from misago.users.testutils import UserTestCase
  4. class DenyAuthenticatedTests(UserTestCase):
  5. def test_success(self):
  6. """deny_authenticated decorator allowed guest request"""
  7. response = self.client.post(reverse('misago:request-activation'))
  8. self.assertEqual(response.status_code, 200)
  9. def test_fail(self):
  10. """deny_authenticated decorator denied authenticated request"""
  11. self.login_user(self.get_authenticated_user())
  12. response = self.client.post(reverse('misago:request-activation'))
  13. self.assertEqual(response.status_code, 403)
  14. class DenyGuestsTests(UserTestCase):
  15. def test_success(self):
  16. """deny_guests decorator allowed authenticated request"""
  17. self.login_user(self.get_authenticated_user())
  18. response = self.client.post(reverse('misago:options'))
  19. self.assertEqual(response.status_code, 200)
  20. def test_fail(self):
  21. """deny_guests decorator blocked guest request"""
  22. response = self.client.post(reverse('misago:options'))
  23. self.assertEqual(response.status_code, 403)
  24. class DenyBannedIPTests(UserTestCase):
  25. def test_success(self):
  26. """deny_banned_ips decorator allowed unbanned request"""
  27. Ban.objects.create(
  28. check_type=BAN_IP,
  29. banned_value='83.*',
  30. user_message='Ya got banned!')
  31. response = self.client.post(reverse('misago:request-activation'))
  32. self.assertEqual(response.status_code, 200)
  33. def test_fail(self):
  34. """deny_banned_ips decorator denied banned request"""
  35. Ban.objects.create(
  36. check_type=BAN_IP,
  37. banned_value='127.*',
  38. user_message='Ya got banned!')
  39. response = self.client.post(reverse('misago:request-activation'))
  40. self.assertEqual(response.status_code, 403)
  41. self.assertIn('<p>Ya got banned!</p>', response.content)