test_floodprotection.py 1.4 KB

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