def test_make_thread_participants_aware(self): """ make_thread_participants_aware sets participants_list and participant adnotations on thread model """ User = get_user_model() user = User.objects.create_user("Bob", "*****@*****.**", "Pass.123") other_user = User.objects.create_user("Bob2", "*****@*****.**", "Pass.123") self.assertFalse(hasattr(self.thread, 'participants_list')) self.assertFalse(hasattr(self.thread, 'participant')) make_thread_participants_aware(user, self.thread) self.assertTrue(hasattr(self.thread, 'participants_list')) self.assertTrue(hasattr(self.thread, 'participant')) self.assertEqual(self.thread.participants_list, []) self.assertIsNone(self.thread.participant) ThreadParticipant.objects.add_participant(self.thread, user, True) ThreadParticipant.objects.add_participant(self.thread, other_user) make_thread_participants_aware(user, self.thread) self.assertEqual(self.thread.participant.user, user) for participant in self.thread.participants_list: if participant.user == user: break else: self.fail("thread.participants_list didn't contain user")
def test_make_thread_participants_aware(self): """ make_thread_participants_aware sets participants_list and participant adnotations on thread model """ User = get_user_model() user = User.objects.create_user( "Bob", "*****@*****.**", "Pass.123") other_user = User.objects.create_user( "Bob2", "*****@*****.**", "Pass.123") self.assertFalse(hasattr(self.thread, 'participants_list')) self.assertFalse(hasattr(self.thread, 'participant')) make_thread_participants_aware(user, self.thread) self.assertTrue(hasattr(self.thread, 'participants_list')) self.assertTrue(hasattr(self.thread, 'participant')) self.assertEqual(self.thread.participants_list, []) self.assertIsNone(self.thread.participant) ThreadParticipant.objects.add_participant(self.thread, user, True) ThreadParticipant.objects.add_participant(self.thread, other_user) make_thread_participants_aware(user, self.thread) self.assertEqual(self.thread.participant.user, user) for participant in self.thread.participants_list: if participant.user == user: break else: self.fail("thread.participants_list didn't contain user")
def check_thread_permissions(self, request, thread): add_acl(request.user, thread.forum) add_acl(request.user, thread) participants.make_thread_participants_aware(request.user, thread) allow_see_private_thread(request.user, thread) allow_use_private_threads(request.user)