test_privatethread_reply_api.py 1.4 KB

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