test_floodprotection.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from __future__ import unicode_literals
  2. from django.urls import reverse
  3. from misago.acl.testutils import override_acl
  4. from misago.categories.models import Category
  5. from misago.threads import testutils
  6. from misago.users.testutils import AuthenticatedUserTestCase
  7. class PostMentionsTests(AuthenticatedUserTestCase):
  8. def setUp(self):
  9. super(PostMentionsTests, self).setUp()
  10. self.category = Category.objects.get(slug='first-category')
  11. self.thread = testutils.post_thread(category=self.category)
  12. self.override_acl()
  13. self.post_link = reverse(
  14. 'misago:api:thread-post-list', kwargs={
  15. 'thread_pk': self.thread.pk,
  16. }
  17. )
  18. def override_acl(self):
  19. new_acl = self.user.acl_cache
  20. new_acl['categories'][self.category.pk].update({
  21. 'can_see': 1,
  22. 'can_browse': 1,
  23. 'can_start_threads': 1,
  24. 'can_reply_threads': 1,
  25. })
  26. override_acl(self.user, new_acl)
  27. def test_flood_has_no_showstoppers(self):
  28. """endpoint handles posting interruption"""
  29. response = self.client.post(
  30. self.post_link, data={
  31. 'post': "This is test response!",
  32. }
  33. )
  34. self.assertEqual(response.status_code, 200)
  35. response = self.client.post(
  36. self.post_link, data={
  37. 'post': "This is test response!",
  38. }
  39. )
  40. self.assertContains(
  41. response, "You can't post message so quickly after previous one.", status_code=403
  42. )