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


Python Post.get_absolute_url方法代码示例

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


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

示例1: test_hidden

# 需要导入模块: from pybb.models import Post [as 别名]
# 或者: from pybb.models.Post import get_absolute_url [as 别名]
    def test_hidden(self):
        client = Client()
        parent = Forum(name='hcat', hidden=True)
        parent.save()

        forum_in_hidden = Forum(name='in_hidden', forum=parent)
        forum_in_hidden.save()

        topic_in_hidden = Topic(forum=forum_in_hidden, name='in_hidden', user=self.user)
        topic_in_hidden.save()

        forum_hidden = Forum(name='hidden', forum=self.parent_forum, hidden=True)
        forum_hidden.save()

        topic_hidden = Topic(forum=forum_hidden, name='hidden', user=self.user)
        topic_hidden.save()

        post_hidden = Post(topic=topic_hidden, user=self.user, body='hidden')
        post_hidden.save()

        post_in_hidden = Post(topic=topic_in_hidden, user=self.user, body='hidden')
        post_in_hidden.save()

        self.assertFalse(parent.id in [c.id for c in client.get(reverse('pybb:index')).context['forums']])
        self.assertEqual(client.get(parent.get_absolute_url()).status_code, 302)
        self.assertEqual(client.get(forum_in_hidden.get_absolute_url()).status_code, 302)
        self.assertEqual(client.get(topic_in_hidden.get_absolute_url()).status_code, 302)

        self.assertNotContains(client.get(reverse('pybb:index')), forum_hidden.get_absolute_url())
        self.assertNotContains(client.get(reverse('pybb:feed_topics')), topic_hidden.get_absolute_url())
        self.assertNotContains(client.get(reverse('pybb:feed_topics')), topic_in_hidden.get_absolute_url())

        self.assertNotContains(client.get(reverse('pybb:feed_posts')), post_hidden.get_absolute_url())
        self.assertNotContains(client.get(reverse('pybb:feed_posts')), post_in_hidden.get_absolute_url())
        self.assertEqual(client.get(forum_hidden.get_absolute_url()).status_code, 302)
        self.assertEqual(client.get(topic_hidden.get_absolute_url()).status_code, 302)

        client.login(username='zeus', password='zeus')

        self.assertTrue(parent.id in [c.id for c in client.get(reverse('pybb:index')).context['forums']])

        self.assertContains(client.get(reverse('pybb:index')), forum_hidden.get_absolute_url())

        self.assertEqual(client.get(parent.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(forum_in_hidden.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(topic_in_hidden.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(forum_hidden.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(topic_hidden.get_absolute_url()).status_code, 200)
        self.user.is_staff = True
        self.user.save()
        self.assertTrue(parent.id in [c.id for c in client.get(reverse('pybb:index')).context['forums']])
        self.assertContains(client.get(reverse('pybb:index')), forum_hidden.get_absolute_url())

        self.assertEqual(client.get(parent.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(forum_in_hidden.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(topic_in_hidden.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(forum_hidden.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(topic_hidden.get_absolute_url()).status_code, 200)
开发者ID:thoas,项目名称:pybbm,代码行数:60,代码来源:test_features.py

示例2: test_topic_tracker_redirect_view

# 需要导入模块: from pybb.models import Post [as 别名]
# 或者: from pybb.models.Post import get_absolute_url [as 别名]
    def test_topic_tracker_redirect_view(self):
        self.login_as(self.staff)

        self.post

        response = self.client.get(reverse('pybb:topic_tracker_redirect', kwargs={
            'topic_id': self.topic.pk
        }))

        self.assertRedirects(response, self.topic.get_absolute_url(), status_code=301)

        TopicReadTracker.objects.create(topic=self.topic,
                                        user=self.staff)

        response = self.client.get(reverse('pybb:topic_tracker_redirect', kwargs={
            'topic_id': self.topic.pk
        }))

        self.client.get(self.topic.get_absolute_url())

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

        response = self.client.get(reverse('pybb:topic_tracker_redirect', kwargs={
            'topic_id': self.topic.pk
        }))

        self.assertRedirects(response, post.get_absolute_url(), status_code=301)
开发者ID:thoas,项目名称:pybbm,代码行数:30,代码来源:test_trackers.py

示例3: test_subscription

# 需要导入模块: from pybb.models import Post [as 别名]
# 或者: from pybb.models.Post import get_absolute_url [as 别名]
 def test_subscription(self):
     user = get_user_model().objects.create_user(username='user2', password='user2', email='[email protected]')
     client = Client()
     client.login(username='user2', password='user2')
     response = client.post(reverse('pybb:subscription_create'), data={
         'topic_id': self.topic.pk,
         'type': Subscription.TYPE_INSTANT_ALERT
     })
     self.assertEqual(response.status_code, 302)
     self.assertRedirects(response, self.topic.get_absolute_url())
     self.assertTrue(user in list(self.topic.subscribers.all()))
     new_post = Post(topic=self.topic, user=self.user, body='test subscribtion юникод')
     new_post.save()
     self.assertTrue([msg for msg in mail.outbox if new_post.get_absolute_url() in msg.body])
     response = client.post(reverse('pybb:subscription_delete'), data={
         'topic_id': self.topic.pk
     })
     self.assertEqual(response.status_code, 302)
     self.assertRedirects(response, self.topic.get_absolute_url())
     self.assertTrue(user not in list(self.topic.subscribers.all()))
开发者ID:thoas,项目名称:pybbm,代码行数:22,代码来源:test_features.py


注:本文中的pybb.models.Post.get_absolute_url方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。