test_floodprotection.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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={
  16. 'thread_pk': self.thread.pk,
  17. }
  18. )
  19. def override_acl(self):
  20. new_acl = self.user.acl_cache
  21. new_acl['categories'][self.category.pk].update({
  22. 'can_see': 1,
  23. 'can_browse': 1,
  24. 'can_start_threads': 1,
  25. 'can_reply_threads': 1,
  26. })
  27. override_acl(self.user, new_acl)
  28. def test_flood_has_no_showstoppers(self):
  29. """endpoint handles posting interruption"""
  30. response = self.client.post(
  31. self.post_link, data={
  32. 'post': "This is test response!",
  33. }
  34. )
  35. self.assertEqual(response.status_code, 200)
  36. response = self.client.post(
  37. self.post_link, data={
  38. 'post': "This is test response!",
  39. }
  40. )
  41. self.assertContains(
  42. response, "You can't post message so quickly after previous one.", status_code=403
  43. )