コード例 #1
0
    def test_view_should_not_render_hidden_comment_for_regular_user(self):
        comment = make_comment(self.user, self.thread)
        hidden_comment = make_comment(self.user, self.thread, visible=False)
        response = self.client.get(f"{self.detail_url}")
        self.assertEqual(len(response.context['comments']), 1)

        login(self, self.user, 'password')
        response = self.client.get(f"{self.detail_url}")
        self.assertEqual(len(response.context['comments']), 1)
コード例 #2
0
ファイル: test_models.py プロジェクト: successIA/ClassicForum
    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))
コード例 #3
0
ファイル: test_models.py プロジェクト: successIA/ClassicForum
    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)
コード例 #4
0
 def setUp(self):
     super().setUp()
     self.comment = make_comment(self.user, self.thread, visible=False)
     self.update_url = reverse(
         'comments:comment_update', 
         kwargs={'thread_slug': self.thread.slug, 'pk': self.comment.pk}
     )
     self.data = {'message': 'hello world 23'}
コード例 #5
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)
コード例 #6
0
ファイル: test_models.py プロジェクト: successIA/ClassicForum
    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))
コード例 #7
0
ファイル: test_models.py プロジェクト: successIA/ClassicForum
    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))
コード例 #8
0
    def test_synchronise_for_create(self):
        self.assertEqual(self.thread.comment_count, 0)
        comment = make_comment(self.user, self.thread)
        self.thread.synchronise(comment)
        self.thread.refresh_from_db()
        self.assertEqual(self.thread.comment_count, 1)

        comment2 = make_comment(self.user, self.thread)
        self.thread.synchronise(comment2)
        self.thread.refresh_from_db()
        self.assertEqual(self.thread.comment_count, 2)

        comment3 = make_comment(self.user, self.thread)
        self.thread.synchronise(comment3, added=False)
        self.thread.refresh_from_db()
        self.assertEqual(self.thread.comment_count, 1)
        self.assertEqual(self.thread.final_comment_user, comment3.user)
        self.assertEqual(self.thread.final_comment_time, comment3.created)
コード例 #9
0
 def test_notify_receiver_for_reply(self):
     reply = make_comment(self.sender, self.thread)
     reply.parent = self.comment
     reply.save()
     Notification.objects.create(sender=reply.user,
                                 receiver=reply.parent.user,
                                 comment=reply,
                                 notif_type=Notification.COMMENT_REPLIED)
     self.assertEqual(Notification.objects.count(), 1)
コード例 #10
0
 def test_create_from_thread(self):
     comment = make_comment(self.user,
                            self.thread,
                            is_starting_comment=True)
     self.thread.starting_comment = comment
     self.thread.save()
     comment.message = 'Updated message'
     comment.save()
     self.thread.title = 'Updated title'
     self.thread.save()
コード例 #11
0
ファイル: test_models.py プロジェクト: successIA/ClassicForum
    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))
コード例 #12
0
ファイル: test_models.py プロジェクト: successIA/ClassicForum
    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)
コード例 #13
0
ファイル: test_models.py プロジェクト: successIA/ClassicForum
    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))
コード例 #14
0
ファイル: test_models.py プロジェクト: successIA/ClassicForum
    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)
コード例 #15
0
ファイル: test_models.py プロジェクト: successIA/ClassicForum
    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))
コード例 #16
0
ファイル: test_models.py プロジェクト: successIA/ClassicForum
    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))
コード例 #17
0
ファイル: test_models.py プロジェクト: successIA/ClassicForum
 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))
コード例 #18
0
 def setUp(self):
     self.sender = self.make_user('testuser1')
     self.receiver = self.make_user('testuser2')
     self.category = make_category()
     self.thread = make_threads(user=self.sender, category=self.category)
     self.comment = make_comment(self.sender, self.thread)
コード例 #19
0
ファイル: test_models.py プロジェクト: successIA/ClassicForum
 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))
コード例 #20
0
ファイル: test_models.py プロジェクト: successIA/ClassicForum
 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))
コード例 #21
0
ファイル: test_models.py プロジェクト: successIA/ClassicForum
 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))
コード例 #22
0
ファイル: test_models.py プロジェクト: successIA/ClassicForum
 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))
コード例 #23
0
ファイル: test_models.py プロジェクト: successIA/ClassicForum
 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))