test_privatethread_reply_api.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. from django.contrib.auth import get_user_model
  2. from misago.acl.testutils import override_acl
  3. from misago.threads import testutils
  4. from misago.threads.models import ThreadParticipant
  5. from .test_privatethreads import PrivateThreadsTestCase
  6. UserModel = get_user_model()
  7. class PrivateThreadReplyApiTestCase(PrivateThreadsTestCase):
  8. def setUp(self):
  9. super(PrivateThreadReplyApiTestCase, self).setUp()
  10. self.thread = testutils.post_thread(self.category, poster=self.user)
  11. self.api_link = self.thread.get_posts_api_url()
  12. self.other_user = UserModel.objects.create_user(
  13. 'BobBoberson', 'bob@boberson.com', 'pass123')
  14. def test_reply_private_thread(self):
  15. """api sets other private thread participants sync thread flag"""
  16. ThreadParticipant.objects.set_owner(self.thread, self.user)
  17. ThreadParticipant.objects.add_participants(self.thread, [self.other_user])
  18. response = self.client.post(self.api_link, data={
  19. 'post': "This is test response!"
  20. })
  21. self.assertEqual(response.status_code, 200)
  22. # don't count private thread replies
  23. self.reload_user()
  24. self.assertEqual(self.user.threads, 0)
  25. self.assertEqual(self.user.posts, 0)
  26. # valid user was flagged to sync
  27. self.assertFalse(UserModel.objects.get(pk=self.user.pk).sync_unread_private_threads)
  28. self.assertTrue(UserModel.objects.get(pk=self.other_user.pk).sync_unread_private_threads)