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


Python Question.was_published_recently方法代码示例

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


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

示例1: QuestionTest

# 需要导入模块: from questions.models import Question [as 别名]
# 或者: from questions.models.Question import was_published_recently [as 别名]

#.........这里部分代码省略.........
                                        pub_date=self.question1.pub_date)
        self.comment2 = QuestionComment(author=self.user1, question=self.question1, comment_text='another comment')

    def test_index(self):
        url = reverse('questions:index')
        resp = self.client.get(url, follow=True)
        self.assertEqual(resp.status_code, 200)

    def test_question_list(self):
        url = reverse('questions:question_list', kwargs={'page': 1})
        resp = self.client.get(url, follow=True)
        self.assertEqual(resp.status_code, 200)
        self.assertContains(resp, _('Login'))

        self.client.login(username=self.user1.username, password='admin')
        resp = self.client.get(url, follow=True)
        self.assertEqual(resp.status_code, 200)
    #
    #     for order in self.orders1:
    #         self.assertContains(resp, order.get_absolute_url(), 2)
    #         self.assertNotContains(resp, self.orders3.get_absolute_url())
    #         for order in self.orders2:
    #             self.assertNotContains(resp, order.get_absolute_url())

    def test_question(self):
        url = reverse('questions:question', kwargs={'question_id': self.question1.pk, 'page': 1, })
        resp = self.client.get(url, follow=True)
        self.assertEqual(resp.status_code, 200)
        self.assertContains(resp, _('Login'))

        self.client.login(username=self.user1.username, password='admin')
        resp = self.client.get(url, follow=True)
        self.assertEqual(resp.status_code, 200)


        # self.assertEqual(QuestionComment.objects.filter(question=self.question1).count(), 3)
        # self.assertEqual(QuestionComment.objects.filter(question=self.question2).count(), 5)

    # def test_new_comment(self):
    #     print 'id: ' + str(self.question1.id)
    #     # url = reverse('questions:new_comment', kwargs={'question_id': str(self.question1.id) })
    #     url = reverse('questions:new_comment', args=[self.question1.id])
    #     resp = self.client.get(url, follow=True)
    #     self.assertEqual(resp.status_code, 200)
    #     self.assertContains(resp, _('Login'))
    #
    #     self.client.login(username=self.user1.username, password='admin')
    #     resp = self.client.get(url, follow=True)
    #     self.assertEqual(resp.status_code, 200)

    def test_new_question(self):
        url = reverse('questions:new_question')
        resp = self.client.get(url, follow=True)
        self.assertEqual(resp.status_code, 200)
        self.assertContains(resp, _('Login'))

        self.client.login(username=self.user1.username, password='admin')
        resp = self.client.get(url, follow=True)
        self.assertEqual(resp.status_code, 200)

    def test_question_unicode(self):
        # self.assertEqual(self.question1,self.comment_text[:100] + ' ' + self.pub_date.strftime('%d.%m.%Y at %H:%M') )
        self.assertEqual(self.question1.__unicode__(), 'description by admin 29.12.2009 at 10:00')


    def test_question_get_descr(self):
        self.assertEqual(self.question1.get_descr(),'description by admin 29.12.2009 at 10:00 (How many more time ?)')
        self.question1.question_text = 'How many more time ?'*5 + '!'
        self.assertEqual(self.question1.get_descr(),'description by admin 29.12.2009 at 10:00 (' +\
                                                    'How many more time ?How many more time ?How many more time ?' +\
                                                    'How many more time ?How many more time ?...)')
    def test_question_was_published_recently(self):
        self.assertFalse(self.question1.was_published_recently())
        self.assertTrue(self.question2.was_published_recently())

    def test_question_get_absolute_url(self):
        self.assertEqual(self.question1.get_absolute_url(), '/questions/' + str(self.question1.pk) + '/page1/')

    def test_question_get_avatar24(self):
        self.assertEqual(self.question1.avatar24(),
                         'http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?d=mm&s=24')

    def test_question_pretty_pub_date(self):
        self.assertEqual(self.question1.pretty_pub_date(), '29.12.2009 at 10:00')

    def test_question_comment_unicode(self):
        self.assertEqual(self.comment1.__unicode__(), 'commentarium 29.12.2009 at 10:00')

    def test_question_comment_get_avatar24(self):
        self.assertEqual(self.comment1.avatar24(),
                         'http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?d=retro&s=24')

    def test_question_comment_pretty_pub_date(self):
        self.assertEqual(self.comment1.pretty_pub_date(), '29.12.2009 at 10:00')

    def test_add_comment_signal(self):
        self.comment_r = QuestionComment(author=self.user1, question=self.question1, comment_text='commentarium',
                                        pub_date=self.question1.pub_date)
        self.comment_r.save()
        self.assertGreater(len(mail.outbox), 1)
开发者ID:Blackwoodseller,项目名称:djbook,代码行数:104,代码来源:tests.py


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