test_privatethread_reply_api.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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.assertFalse(User.objects.get(pk=self.user.pk).sync_unread_private_threads)
  26. self.assertTrue(
  27. User.objects.get(pk=self.other_user.pk).sync_unread_private_threads
  28. )