test_privatethread_view.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. from misago.acl.testutils import override_acl
  2. from misago.threads import testutils
  3. from misago.threads.models import ThreadParticipant
  4. from .test_privatethreads import PrivateThreadsTestCase
  5. class PrivateThreadViewTests(PrivateThreadsTestCase):
  6. def setUp(self):
  7. super(PrivateThreadViewTests, self).setUp()
  8. self.thread = testutils.post_thread(self.category, poster=self.user)
  9. self.test_link = self.thread.get_absolute_url()
  10. def test_anonymous(self):
  11. """anonymous user can't see private thread"""
  12. self.logout_user()
  13. response = self.client.get(self.test_link)
  14. self.assertContains(response, "sign in to use private threads", status_code=403)
  15. def test_no_permission(self):
  16. """user needs to have permission to see private thread"""
  17. override_acl(self.user, {
  18. 'can_use_private_threads': 0
  19. })
  20. response = self.client.get(self.test_link)
  21. self.assertContains(response, "t use private threads", status_code=403)
  22. def test_no_participant(self):
  23. """user cant see thread he isn't part of"""
  24. response = self.client.get(self.test_link)
  25. self.assertEqual(response.status_code, 404)
  26. def test_mod_not_reported(self):
  27. """moderator can't see private thread that has no reports"""
  28. override_acl(self.user, {
  29. 'can_moderate_private_threads': 1
  30. })
  31. response = self.client.get(self.test_link)
  32. self.assertEqual(response.status_code, 404)
  33. def test_reported_not_mod(self):
  34. """non-mod can't see private thread that has reported posts"""
  35. self.thread.has_reported_posts = True
  36. self.thread.save()
  37. response = self.client.get(self.test_link)
  38. self.assertEqual(response.status_code, 404)
  39. def test_can_see_owner(self):
  40. """user can see thread he is owner of"""
  41. ThreadParticipant.objects.set_owner(self.thread, self.user)
  42. response = self.client.get(self.test_link)
  43. self.assertContains(response, self.thread.title)
  44. def test_can_see_participant(self):
  45. """user can see thread he is participant of"""
  46. ThreadParticipant.objects.add_participants(self.thread, [self.user])
  47. response = self.client.get(self.test_link)
  48. self.assertContains(response, self.thread.title)
  49. def test_mod_can_see_reported(self):
  50. """moderator can see private thread that has reports"""
  51. override_acl(self.user, {
  52. 'can_moderate_private_threads': 1
  53. })
  54. self.thread.has_reported_posts = True
  55. self.thread.save()
  56. response = self.client.get(self.test_link)
  57. self.assertContains(response, self.thread.title)