test_privatethread_view.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. from .. import test
  2. from ...acl.test import patch_user_acl
  3. from ..models import ThreadParticipant
  4. from .test_privatethreads import PrivateThreadsTestCase
  5. class PrivateThreadViewTests(PrivateThreadsTestCase):
  6. def setUp(self):
  7. super().setUp()
  8. self.thread = test.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. @patch_user_acl({"can_use_private_threads": False})
  16. def test_no_permission(self):
  17. """user needs to have permission to see private thread"""
  18. response = self.client.get(self.test_link)
  19. self.assertContains(response, "t use private threads", status_code=403)
  20. def test_no_participant(self):
  21. """user cant see thread he isn't part of"""
  22. response = self.client.get(self.test_link)
  23. self.assertEqual(response.status_code, 404)
  24. @patch_user_acl({"can_moderate_private_threads": True})
  25. def test_mod_not_reported(self):
  26. """moderator can't see private thread that has no reports"""
  27. response = self.client.get(self.test_link)
  28. self.assertEqual(response.status_code, 404)
  29. def test_reported_not_mod(self):
  30. """non-mod can't see private thread that has reported posts"""
  31. self.thread.has_reported_posts = True
  32. self.thread.save()
  33. response = self.client.get(self.test_link)
  34. self.assertEqual(response.status_code, 404)
  35. def test_can_see_owner(self):
  36. """user can see thread he is owner of"""
  37. ThreadParticipant.objects.set_owner(self.thread, self.user)
  38. response = self.client.get(self.test_link)
  39. self.assertContains(response, self.thread.title)
  40. def test_can_see_participant(self):
  41. """user can see thread he is participant of"""
  42. ThreadParticipant.objects.add_participants(self.thread, [self.user])
  43. response = self.client.get(self.test_link)
  44. self.assertContains(response, self.thread.title)
  45. @patch_user_acl({"can_moderate_private_threads": True})
  46. def test_mod_can_see_reported(self):
  47. """moderator can see private thread that has reports"""
  48. self.thread.has_reported_posts = True
  49. self.thread.save()
  50. response = self.client.get(self.test_link)
  51. self.assertContains(response, self.thread.title)