本文整理汇总了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)
示例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)
示例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()))