Example #1
0
    def test_can_hide_post_with_post_moderator(self):
        """Only a post moderator can hide the post he/she is moderating"""
        thread = make_only_thread(self.regular_user, self.category)
        comment = make_comment(self.regular_user, thread)
        self.assertTrue(self.moderator.can_hide_post(thread))
        self.assertTrue(self.moderator.can_hide_post(comment))

        thread = make_only_thread(self.superuser, self.category2)
        comment = make_comment(self.superuser, thread)
        self.assertTrue(self.moderator3.can_hide_post(thread))
        self.assertTrue(self.moderator3.can_hide_post(comment))
Example #2
0
    def test_synchronise_with_revision(self):
        attachment = Attachment.objects.create(image=self.test_image)
        category = make_category()
        thread = make_only_thread(self.user, category)

        message = f'![]({attachment.image.url})'
        comment = make_comment(self.user, thread, message=message)
        Attachment.objects.synchronise(comment)
        self.assertIn(
            comment, Attachment.objects.all().first().comments.all()
        )
        self.assertFalse(Attachment.objects.last().is_orphaned)

        Comment.objects.filter(pk=comment.pk).update(
            message='No more image source'
        )
        revision = CommentRevision.objects.create(
            comment=comment, message=comment.message
        )
        comment.refresh_from_db()
        Attachment.objects.synchronise(comment, revision.message)
        self.assertNotIn(
            comment, Attachment.objects.all().first().comments.all()
        )
        self.assertTrue(Attachment.objects.last().is_orphaned)
Example #3
0
 def setUp(self):
     self.sender = self.make_user('testuser1')
     self.receiver = self.make_user('testuser2')
     self.receiver2 = self.make_user('testuser3')
     self.receiver_list = [self.receiver, self.receiver2]
     self.category = make_category()
     self.thread = make_only_thread(self.sender, self.category)
     self.comment = make_comment(self.sender, self.thread)
Example #4
0
    def test_can_hide_post_with_invisible_post(self):
        """An invisible post cannot be hidden"""
        thread = make_only_thread(self.user, self.category, visible=False)
        comment = make_comment(self.user, thread, visible=False)
        self.assertFalse(self.moderator.can_hide_post(thread))
        self.assertFalse(self.supermoderator.can_hide_post(thread))

        self.assertFalse(self.moderator.can_hide_post(comment))
        self.assertFalse(self.supermoderator.can_hide_post(comment))
Example #5
0
    def test_is_moderating_post(self):
        thread = make_only_thread(self.user, self.category)
        comment = make_comment(self.user, thread)

        self.assertFalse(self.moderator3.is_moderating_post(thread))
        self.assertFalse(self.moderator3.is_moderating_post(comment))

        self.assertTrue(self.moderator.is_moderating_post(thread))
        self.assertTrue(self.moderator.is_moderating_post(comment))
Example #6
0
    def test_can_unhide_post_with_supermoderator_to_owner(self):
        """
        A post can be unhidden by a supermoderator who did not hide the post
        but moderating the post.
        """
        thread = make_only_thread(self.user, self.category, visible=False)
        self.moderator.hidden_threads.add(thread)
        comment = make_comment(self.user, thread, visible=False)
        self.moderator.hidden_comments.add(comment)

        self.assertTrue(self.supermoderator.can_unhide_post(thread))
        self.assertTrue(self.supermoderator.can_unhide_post(comment))
Example #7
0
    def test_synchronise(self):
        attachment = Attachment.objects.create(image=self.test_image)
        category = make_category()
        thread = make_only_thread(self.user, category)

        message = f'![]({attachment.image.url})'
        comment = make_comment(self.user, thread, message=message)
        Attachment.objects.synchronise(comment)
        self.assertIn(
            comment, Attachment.objects.all().first().comments.all()
        )
        self.assertFalse(Attachment.objects.last().is_orphaned)
Example #8
0
    def test_can_unhide_post_with_visible_post(self):
        """A visible post cannot be unhidden"""
        thread = make_only_thread(self.superuser, self.category)
        comment = make_comment(self.superuser, thread)

        self.assertFalse(self.supermoderator.can_unhide_post(thread))
        self.assertFalse(self.supermoderator.can_unhide_post(comment))

        self.supermoderator.hidden_threads.add(thread)
        self.supermoderator.hidden_comments.add(comment)

        self.assertFalse(self.supermoderator.can_unhide_post(thread))
        self.assertFalse(self.supermoderator.can_unhide_post(comment))
Example #9
0
    def test_can_unhide_post_with_owner(self):
        """
        A post can be unhidden by a moderator who hid the post
        """
        thread = make_only_thread(self.regular_user,
                                  self.category,
                                  visible=False)
        self.moderator2.hidden_threads.add(thread)

        comment = make_comment(self.regular_user, thread, visible=False)
        self.moderator2.hidden_comments.add(comment)

        self.assertTrue(self.moderator2.can_unhide_post(thread))
        self.assertTrue(self.moderator2.can_unhide_post(comment))
Example #10
0
    def test_get_hidden_posts(self):
        thread = make_only_thread(self.user, self.category)
        hidden_posts = self.moderator.get_hidden_posts(thread)
        self.assertQuerysetEqual(self.moderator.hidden_threads.all(),
                                 hidden_posts)

        comment = make_comment(self.user, thread)
        hidden_posts = self.moderator.get_hidden_posts(comment)
        self.assertQuerysetEqual(self.moderator.hidden_comments.all(),
                                 hidden_posts)

        msg = "post has to be an instance either Thread or Comment"
        with self.assertRaisesMessage(TypeError, msg):
            self.moderator.get_hidden_posts(self.category)
Example #11
0
    def test_can_unhide_post_without_post_moderator(self):
        """
        A post cannot unhidden by a moderator who is not moderating 
        the post.
        """
        thread = make_only_thread(self.regular_user,
                                  self.category2,
                                  visible=False)
        self.supermoderator.hidden_threads.add(thread)

        comment = make_comment(self.user, thread, visible=False)
        self.supermoderator.hidden_comments.add(comment)

        self.assertFalse(self.supermoderator.can_unhide_post(thread))
        self.assertFalse(self.supermoderator.can_unhide_post(comment))
Example #12
0
 def test_can_hide_post_with_supermoderator_to_post(self):
     """A supermoderator can hide the post of another moderator"""
     thread = make_only_thread(self.user, self.category)
     comment = make_comment(self.user, thread)
     self.assertTrue(self.supermoderator.can_hide_post(thread))
     self.assertTrue(self.supermoderator.can_hide_post(comment))
Example #13
0
 def test_can_hide_post_without_supermoderator_to_post(self):
     """A supermoderator cannot hide the post he/she is not moderating"""
     thread = make_only_thread(self.regular_user, self.category2)
     comment = make_comment(self.regular_user, thread)
     self.assertFalse(self.supermoderator.can_hide_post(thread))
Example #14
0
 def test_can_hide_post_without_post_moderator(self):
     """A moderator cannot hide a post he/she is not moderating"""
     thread = make_only_thread(self.regular_user, self.category)
     comment = make_comment(self.regular_user, thread)
     self.assertFalse(self.moderator3.can_hide_post(thread))
     self.assertFalse(self.moderator3.can_hide_post(comment))
Example #15
0
 def test_can_hide_post_with_starting_comment(self):
     """A starting_comment cannot be hidden"""
     thread = make_only_thread(self.user, self.category, visible=False)
     comment = make_comment(self.user, thread, is_starting_comment=True)
     self.assertFalse(self.moderator.can_hide_post(comment))
     self.assertFalse(self.supermoderator.can_hide_post(comment))
Example #16
0
 def test_can_hide_post_with_moderator_owner(self):
     """A moderator can hide his/her post"""
     thread = make_only_thread(self.user, self.category)
     comment = make_comment(self.user, thread)
     self.assertTrue(self.moderator.can_hide_post(thread))
     self.assertTrue(self.moderator.can_hide_post(comment))
Example #17
0
 def setUp(self):
     super().setUp()
     # Returns a thread without starting comment
     self.thread = make_only_thread(self.user, self.category)
     self.detail_url = reverse('thread_detail',
                               kwargs={'thread_slug': self.thread.slug})
Example #18
0
 def setUp(self):
     super().setUp()
     make_only_thread(self.user, self.category, count=15)
     self.list_url = reverse('home')
Example #19
0
 def test_can_hide_post_without_moderator_owner(self):
     """A moderator cannot hide a post of another moderator"""
     thread = make_only_thread(self.user, self.category)
     comment = make_comment(self.user, thread)
     self.assertFalse(self.moderator2.can_hide_post(thread))
     self.assertFalse(self.moderator2.can_hide_post(comment))