當前位置: 首頁>>代碼示例>>Python>>正文


Python Topic.mark_as_deleted方法代碼示例

本文整理匯總了Python中pybb.models.Topic.mark_as_deleted方法的典型用法代碼示例。如果您正苦於以下問題:Python Topic.mark_as_deleted方法的具體用法?Python Topic.mark_as_deleted怎麽用?Python Topic.mark_as_deleted使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pybb.models.Topic的用法示例。


在下文中一共展示了Topic.mark_as_deleted方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_compute

# 需要導入模塊: from pybb.models import Topic [as 別名]
# 或者: from pybb.models.Topic import mark_as_deleted [as 別名]
    def test_compute(self):
        # initials
        self.assertEqual(self.forum.forum_count, 0)
        self.assertEqual(self.parent_forum.forum_count, 1)

        self.topic
        self.post

        parent_forum = Forum.objects.get(pk=self.parent_forum.pk)

        self.assertEqual(parent_forum.topic_count, 1)
        self.assertEqual(parent_forum.post_count, 1)
        self.assertEqual(self.forum.topic_count, 1)
        self.assertEqual(self.forum.post_count, 1)

        forum = Forum.objects.create(name='bar', description='bar', forum=self.forum)

        topic = Topic(name='bar', forum=forum, user=self.user)
        topic.save()

        post = Post(topic=topic, user=self.user, body='my new post')
        post.save()

        self.assertEqual(topic.post_count, 1)
        self.assertEqual(forum.topic_count, 1)

        self.assertEqual(Forum.objects.get(pk=self.forum.pk).topic_count, 2)
        self.assertEqual(Forum.objects.get(pk=self.parent_forum.pk).topic_count, 2)

        new_topic = Topic(name='foo', forum=self.forum, user=self.user)
        new_topic.save()

        new_post = Post(topic=topic, user=self.user, body='my new post')
        new_post.save()

        self.assertEqual(Forum.objects.get(pk=self.forum.pk).topic_count, 3)
        self.assertEqual(Forum.objects.get(pk=self.parent_forum.pk).topic_count, 3)

        post.mark_as_deleted(commit=True)

        self.assertEqual(Forum.objects.get(pk=self.forum.pk).topic_count, 2)
        self.assertEqual(Forum.objects.get(pk=self.parent_forum.pk).topic_count, 2)

        self.assertTrue(Topic.objects.get(pk=topic.pk).deleted)

        self.assertEqual(Forum.objects.get(pk=forum.pk).topic_count, 0)
        self.assertEqual(Forum.objects.get(pk=forum.pk).post_count, 0)

        new_topic.mark_as_deleted()

        self.assertEqual(Forum.objects.get(pk=self.forum.pk).topic_count, 1)
        self.assertEqual(Forum.objects.get(pk=self.parent_forum.pk).topic_count, 1)
開發者ID:magatz,項目名稱:pybbm-1,代碼行數:54,代碼來源:tests.py

示例2: test_compute

# 需要導入模塊: from pybb.models import Topic [as 別名]
# 或者: from pybb.models.Topic import mark_as_deleted [as 別名]
    def test_compute(self):
        # initials
        self.assertEqual(self.forum.forum_count, 0)
        self.assertEqual(self.parent_forum.forum_count, 1)

        self.topic
        self.post

        parent_forum = Forum.objects.get(pk=self.parent_forum.pk)

        self.assertEqual(parent_forum.topic_count, 1)
        self.assertEqual(parent_forum.post_count, 1)
        self.assertEqual(self.forum.topic_count, 1)
        self.assertEqual(self.forum.post_count, 1)

        # Add (forum --> topic --> post) in self.forum
        forum = Forum.objects.create(name='bar', description='bar', forum=self.forum)

        topic = Topic(name='bar', forum=forum, user=self.user)
        topic.save()

        post = Post(topic=topic, user=self.user, body='my new post')
        post.save()

        self.assertEquals(Topic.objects.get(pk=topic.pk).first_post, post)
        self.assertEqual(topic.post_count, 1)
        self.assertEqual(forum.topic_count, 1)

        self.assertEqual(Forum.objects.get(pk=self.forum.pk).post_count, 2)
        self.assertEqual(Forum.objects.get(pk=self.forum.pk).topic_count, 2)
        self.assertEqual(Forum.objects.get(pk=self.parent_forum.pk).post_count, 2)
        self.assertEqual(Forum.objects.get(pk=self.parent_forum.pk).topic_count, 2)

        # Add (topic --> post) in self.forum
        new_topic = Topic(name='foo', forum=self.forum, user=self.user)
        new_topic.save()

        new_post = Post(topic=new_topic, user=self.user, body='my new post')
        new_post.save()
        self.assertEquals(Topic.objects.get(pk=new_topic.pk).first_post, new_post)

        self.assertEqual(Forum.objects.get(pk=self.forum.pk).post_count, 3)
        self.assertEqual(Forum.objects.get(pk=self.forum.pk).topic_count, 3)
        self.assertEqual(Forum.objects.get(pk=self.parent_forum.pk).post_count, 3)
        self.assertEqual(Forum.objects.get(pk=self.parent_forum.pk).topic_count, 3)

        # delete post in (self.parent_forum --> self.forum --> forum --> topic)
        post.mark_as_deleted(commit=True)

        self.assertTrue(Topic.objects.get(pk=topic.pk).deleted)
        self.assertEquals(Topic.objects.get(pk=topic.pk).first_post, post)
        self.assertTrue(Topic.objects.get(pk=topic.pk).first_post.deleted)

        self.assertEqual(Forum.objects.get(pk=forum.pk).topic_count, 0)
        self.assertEqual(Forum.objects.get(pk=forum.pk).post_count, 0)

        self.assertEqual(Forum.objects.get(pk=self.forum.pk).topic_count, 2)
        self.assertEqual(Forum.objects.get(pk=self.parent_forum.pk).topic_count, 2)

        # delete new_topic in (self.parent_forum --> self.forum)
        new_topic.mark_as_deleted()

        self.assertTrue(Topic.objects.get(pk=new_topic.pk).deleted)
        self.assertEquals(Topic.objects.get(pk=new_topic.pk).first_post, new_post)
        self.assertTrue(Topic.objects.get(pk=new_topic.pk).first_post.deleted)

        self.assertEqual(Forum.objects.get(pk=self.forum.pk).topic_count, 1)
        self.assertEqual(Forum.objects.get(pk=self.parent_forum.pk).topic_count, 1)

        # undelete new_topic in (self.parent_forum --> self.forum)
        new_topic.mark_as_undeleted()

        self.assertFalse(Topic.objects.get(pk=new_topic.pk).deleted)
        self.assertEquals(Topic.objects.get(pk=new_topic.pk).first_post, new_post)
        self.assertFalse(Topic.objects.get(pk=new_topic.pk).first_post.deleted)

        self.assertEqual(Forum.objects.get(pk=self.forum.pk).topic_count, 2)
        self.assertEqual(Forum.objects.get(pk=self.parent_forum.pk).topic_count, 2)

        # undelete post in (self.parent_forum --> self.forum --> forum --> topic)
        post.mark_as_undeleted(commit=True)

        self.assertFalse(Topic.objects.get(pk=topic.pk).deleted)
        self.assertEquals(Topic.objects.get(pk=topic.pk).first_post, post)
        self.assertFalse(Topic.objects.get(pk=topic.pk).first_post.deleted)

        self.assertEqual(Forum.objects.get(pk=forum.pk).post_count, 1)
        self.assertEqual(Forum.objects.get(pk=forum.pk).topic_count, 1)
        self.assertEqual(Forum.objects.get(pk=self.forum.pk).post_count, 3)
        self.assertEqual(Forum.objects.get(pk=self.forum.pk).topic_count, 3)
        self.assertEqual(Forum.objects.get(pk=self.parent_forum.pk).post_count, 3)
        self.assertEqual(Forum.objects.get(pk=self.parent_forum.pk).topic_count, 3)
開發者ID:thoas,項目名稱:pybbm,代碼行數:94,代碼來源:test_models.py


注:本文中的pybb.models.Topic.mark_as_deleted方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。