コード例 #1
0
ファイル: test_forums.py プロジェクト: krisssbg/kitsune
class ForumDocumentSignalsTests(Elastic7TestCase):
    def setUp(self):
        self.post = PostFactory()
        self.post_id = self.post.id

    def get_doc(self):
        return ForumDocument.get(self.post_id)

    def test_post_save(self):
        self.post.content = "foobar"
        self.post.save()

        self.assertEqual(self.get_doc().content, "foobar")

    def test_thread_save(self):
        thread = self.post.thread
        thread.title = "foobar"
        thread.save()

        self.assertEqual(self.get_doc().thread_title, "foobar")

    def test_post_delete(self):
        self.post.delete()

        with self.assertRaises(NotFoundError):
            self.get_doc()

    def test_thread_delete(self):
        self.post.thread.delete()

        with self.assertRaises(NotFoundError):
            self.get_doc()
コード例 #2
0
ファイル: test_models.py プロジェクト: davehunt/kitsune
    def test_delete_post_removes_flag(self):
        """Deleting a post also removes the flags on that post."""
        p = PostFactory()

        u = UserFactory()
        FlaggedObject.objects.create(status=0, content_object=p, reason="language", creator_id=u.id)
        eq_(1, FlaggedObject.objects.count())

        p.delete()
        eq_(0, FlaggedObject.objects.count())
コード例 #3
0
    def test_delete_post_removes_flag(self):
        """Deleting a post also removes the flags on that post."""
        p = PostFactory()

        u = UserFactory()
        FlaggedObject.objects.create(
            status=0, content_object=p, reason='language', creator_id=u.id)
        eq_(1, FlaggedObject.objects.count())

        p.delete()
        eq_(0, FlaggedObject.objects.count())
コード例 #4
0
    def test_last_post_updated(self):
        # Adding/Deleting the last post in a thread and forum should
        # update the last_post field
        orig_post = PostFactory(created=YESTERDAY)
        t = orig_post.thread

        # add a new post, then check that last_post is updated
        new_post = PostFactory(thread=t, content='test')
        f = Forum.objects.get(id=t.forum_id)
        t = Thread.objects.get(id=t.id)
        eq_(f.last_post.id, new_post.id)
        eq_(t.last_post.id, new_post.id)

        # delete the new post, then check that last_post is updated
        new_post.delete()
        f = Forum.objects.get(id=f.id)
        t = Thread.objects.get(id=t.id)
        eq_(f.last_post.id, orig_post.id)
        eq_(t.last_post.id, orig_post.id)
コード例 #5
0
ファイル: test_models.py プロジェクト: Andisutra80/kitsune
    def test_last_post_updated(self):
        # Adding/Deleting the last post in a thread and forum should
        # update the last_post field
        orig_post = PostFactory(created=YESTERDAY)
        t = orig_post.thread

        # add a new post, then check that last_post is updated
        new_post = PostFactory(thread=t, content='test')
        f = Forum.objects.get(id=t.forum_id)
        t = Thread.objects.get(id=t.id)
        eq_(f.last_post.id, new_post.id)
        eq_(t.last_post.id, new_post.id)

        # delete the new post, then check that last_post is updated
        new_post.delete()
        f = Forum.objects.get(id=f.id)
        t = Thread.objects.get(id=t.id)
        eq_(f.last_post.id, orig_post.id)
        eq_(t.last_post.id, orig_post.id)
コード例 #6
0
    def test_move_updates_last_posts(self):
        # Moving the thread containing a forum's last post to a new
        # forum should update the last_post of both
        # forums. Consequently, deleting the last post shouldn't
        # delete the old forum. [bug 588994]

        # Setup forum to move latest thread from.
        old_forum = ForumFactory()
        t1 = ThreadFactory(forum=old_forum, posts=[])
        p1 = PostFactory(thread=t1, created=YESTERDAY)
        t2 = ThreadFactory(forum=old_forum, posts=[])
        p2 = PostFactory(thread=t2)  # Newest post of all.

        # Setup forum to move latest thread to.
        new_forum = ForumFactory()
        t3 = ThreadFactory(forum=new_forum, posts=[])
        p3 = PostFactory(thread=t3, created=YESTERDAY)

        # Verify the last_post's are correct.
        eq_(p2, Forum.objects.get(id=old_forum.id).last_post)
        eq_(p3, Forum.objects.get(id=new_forum.id).last_post)

        # Move the t2 thread.
        t2 = Thread.objects.get(id=t2.id)
        t2.forum = new_forum
        t2.save()

        # Old forum's last_post updated?
        eq_(p1.id, Forum.objects.get(id=old_forum.id).last_post_id)

        # New forum's last_post updated?
        eq_(p2.id, Forum.objects.get(id=new_forum.id).last_post_id)

        # Delete the post, and both forums should still exist:
        p2.delete()
        eq_(1, Forum.objects.filter(id=old_forum.id).count())
        eq_(1, Forum.objects.filter(id=new_forum.id).count())
コード例 #7
0
ファイル: test_models.py プロジェクト: Andisutra80/kitsune
    def test_move_updates_last_posts(self):
        # Moving the thread containing a forum's last post to a new
        # forum should update the last_post of both
        # forums. Consequently, deleting the last post shouldn't
        # delete the old forum. [bug 588994]

        # Setup forum to move latest thread from.
        old_forum = ForumFactory()
        t1 = ThreadFactory(forum=old_forum, posts=[])
        p1 = PostFactory(thread=t1, created=YESTERDAY)
        t2 = ThreadFactory(forum=old_forum, posts=[])
        p2 = PostFactory(thread=t2)  # Newest post of all.

        # Setup forum to move latest thread to.
        new_forum = ForumFactory()
        t3 = ThreadFactory(forum=new_forum, posts=[])
        p3 = PostFactory(thread=t3, created=YESTERDAY)

        # Verify the last_post's are correct.
        eq_(p2, Forum.objects.get(id=old_forum.id).last_post)
        eq_(p3, Forum.objects.get(id=new_forum.id).last_post)

        # Move the t2 thread.
        t2 = Thread.objects.get(id=t2.id)
        t2.forum = new_forum
        t2.save()

        # Old forum's last_post updated?
        eq_(p1.id, Forum.objects.get(id=old_forum.id).last_post_id)

        # New forum's last_post updated?
        eq_(p2.id, Forum.objects.get(id=new_forum.id).last_post_id)

        # Delete the post, and both forums should still exist:
        p2.delete()
        eq_(1, Forum.objects.filter(id=old_forum.id).count())
        eq_(1, Forum.objects.filter(id=new_forum.id).count())