test_floodprotection.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. from django.urls import reverse
  2. from misago.acl.test import patch_user_acl
  3. from misago.categories.models import Category
  4. from misago.threads import testutils
  5. from misago.users.testutils import AuthenticatedUserTestCase
  6. class FloodProtectionTests(AuthenticatedUserTestCase):
  7. def setUp(self):
  8. super().setUp()
  9. self.category = Category.objects.get(slug="first-category")
  10. self.thread = testutils.post_thread(category=self.category)
  11. self.post_link = reverse(
  12. "misago:api:thread-post-list", kwargs={"thread_pk": self.thread.pk}
  13. )
  14. def test_flood_has_no_showstoppers(self):
  15. """endpoint handles posting interruption"""
  16. response = self.client.post(
  17. self.post_link, data={"post": "This is test response!"}
  18. )
  19. self.assertEqual(response.status_code, 200)
  20. response = self.client.post(
  21. self.post_link, data={"post": "This is test response!"}
  22. )
  23. self.assertEqual(response.status_code, 403)
  24. self.assertEqual(
  25. response.json(),
  26. {"detail": "You can't post message so quickly after previous one."},
  27. )
  28. @patch_user_acl({"can_omit_flood_protection": True})
  29. def test_user_with_permission_omits_flood_protection(self):
  30. response = self.client.post(
  31. self.post_link, data={"post": "This is test response!"}
  32. )
  33. self.assertEqual(response.status_code, 200)
  34. response = self.client.post(
  35. self.post_link, data={"post": "This is test response!"}
  36. )
  37. self.assertEqual(response.status_code, 200)