123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- from django.contrib.auth import get_user_model
- from django.utils import timezone
- from misago.acl.testutils import override_acl
- from misago.forums.models import Forum
- from misago.users.testutils import AuthenticatedUserTestCase
- from misago.threads import testutils
- from misago.threads.models import ThreadParticipant
- class PrivateThreadTests(AuthenticatedUserTestCase):
- def setUp(self):
- super(PrivateThreadTests, self).setUp()
- self.forum = Forum.objects.private_threads()
- self.thread = testutils.post_thread(self.forum)
- def test_anon_access_to_view(self):
- """anonymous user has no access to private thread"""
- self.logout_user()
- response = self.client.get(self.thread.get_absolute_url())
- self.assertEqual(response.status_code, 403)
- def test_non_participant_access_to_thread(self):
- """non-participant user has no access to private thread"""
- override_acl(self.user, {'can_use_private_threads': True})
- response = self.client.get(self.thread.get_absolute_url())
- self.assertEqual(response.status_code, 404)
- def test_owner_can_access_thread(self):
- """owner has access to private thread"""
- override_acl(self.user, {'can_use_private_threads': True})
- ThreadParticipant.objects.set_owner(self.thread, self.user)
- response = self.client.get(self.thread.get_absolute_url())
- self.assertEqual(response.status_code, 200)
- self.assertIn(self.thread.title, response.content)
- def test_participant_can_access_thread(self):
- """participant has access to private thread"""
- override_acl(self.user, {'can_use_private_threads': True})
- ThreadParticipant.objects.add_participant(self.thread, self.user)
- response = self.client.get(self.thread.get_absolute_url())
- self.assertEqual(response.status_code, 200)
- self.assertIn(self.thread.title, response.content)
- def test_removed_user_cant_access_thread(self):
- """removed user can't access thread"""
- override_acl(self.user, {'can_use_private_threads': True})
- ThreadParticipant.objects.add_participant(self.thread, self.user)
- ThreadParticipant.objects.remove_participant(self.thread, self.user)
- response = self.client.get(self.thread.get_absolute_url())
- self.assertEqual(response.status_code, 404)
- def test_moderator_cant_access_unreported_thread(self):
- """moderator cant see private thread without reports"""
- override_acl(self.user, {
- 'can_use_private_threads': True,
- 'can_moderate_private_threads': True
- })
- response = self.client.get(self.thread.get_absolute_url())
- self.assertEqual(response.status_code, 404)
- def test_moderator_can_access_reported_thread(self):
- """moderator can see private thread with reports"""
- override_acl(self.user, {
- 'can_use_private_threads': True,
- 'can_moderate_private_threads': True
- })
- self.thread.has_reported_posts = True
- self.thread.save()
- response = self.client.get(self.thread.get_absolute_url())
- self.assertEqual(response.status_code, 200)
- self.assertIn(self.thread.title, response.content)
- def test_moderator_can_takeover_reported_thread(self):
- """moderator can take over private thread"""
- override_acl(self.user, {
- 'can_use_private_threads': True,
- 'can_moderate_private_threads': True
- })
- self.thread.has_reported_posts = True
- self.thread.save()
- response = self.client.post(self.thread.get_absolute_url(), data={
- 'thread_action': 'takeover'
- })
- self.assertEqual(response.status_code, 302)
- user = self.thread.threadparticipant_set.get(user=self.user)
- self.assertTrue(user.is_owner)
- def test_owner_can_pass_thread_to_participant(self):
- """thread owner can pass thread to other participant"""
- User = get_user_model()
- new_owner = User.objects.create_user("Bob", "bob@bob.com", "pass123")
- ThreadParticipant.objects.set_owner(self.thread, self.user)
- ThreadParticipant.objects.add_participant(self.thread, new_owner)
- override_acl(self.user, {'can_use_private_threads': True})
- response = self.client.post(self.thread.get_absolute_url(), data={
- 'thread_action': 'make_owner:%s' % new_owner.id
- })
- self.assertEqual(response.status_code, 302)
- user = self.thread.threadparticipant_set.get(user=self.user)
- self.assertFalse(user.is_owner)
- user = self.thread.threadparticipant_set.get(user=new_owner)
- self.assertTrue(user.is_owner)
|