当前位置: 首页>>代码示例>>Python>>正文


Python Topic.mark_as_undeleted方法代码示例

本文整理汇总了Python中pybb.models.Topic.mark_as_undeleted方法的典型用法代码示例。如果您正苦于以下问题:Python Topic.mark_as_undeleted方法的具体用法?Python Topic.mark_as_undeleted怎么用?Python Topic.mark_as_undeleted使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pybb.models.Topic的用法示例。


在下文中一共展示了Topic.mark_as_undeleted方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_compute

# 需要导入模块: from pybb.models import Topic [as 别名]
# 或者: from pybb.models.Topic import mark_as_undeleted [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_undeleted方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。