test_privatethread_reply_api.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. from django.contrib.auth import get_user_model
  2. from misago.threads import testutils
  3. from misago.threads.models import ThreadParticipant
  4. from .test_privatethreads import PrivateThreadsTestCase
  5. UserModel = get_user_model()
  6. class PrivateThreadReplyApiTestCase(PrivateThreadsTestCase):
  7. def setUp(self):
  8. super().setUp()
  9. self.thread = testutils.post_thread(self.category, poster=self.user)
  10. self.api_link = self.thread.get_posts_api_url()
  11. self.other_user = UserModel.objects.create_user(
  12. 'BobBoberson', 'bob@boberson.com', 'pass123'
  13. )
  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(
  19. self.api_link, data={
  20. 'post': "This is test response!",
  21. }
  22. )
  23. self.assertEqual(response.status_code, 200)
  24. # don't count private thread replies
  25. self.reload_user()
  26. self.assertEqual(self.user.threads, 0)
  27. self.assertEqual(self.user.posts, 0)
  28. self.assertEqual(self.user.audittrail_set.count(), 1)
  29. # valid user was flagged to sync
  30. self.assertFalse(UserModel.objects.get(pk=self.user.pk).sync_unread_private_threads)
  31. self.assertTrue(UserModel.objects.get(pk=self.other_user.pk).sync_unread_private_threads)