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


Python BlogPost.refresh_from_db方法代码示例

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


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

示例1: StatusTests

# 需要导入模块: from blog.models import BlogPost [as 别名]
# 或者: from blog.models.BlogPost import refresh_from_db [as 别名]
class StatusTests(TestCase):
    fixtures = ['devel']

    def setUp(self):
        self.client.login(username='admin', password='admin')
        self.user = ActiveUser.objects.filter(username='admin')[0]
        self.post = BlogPost(title='Hello World!',
                        author=self.user,
                        tags='hello world',
                        abstract='Hello World!',
                        text='Hello World!',
                        priority=BlogPost.PRIORITY_NORMAL)
        self.post.save()

        self.url = reverse('blog_pending_edit', kwargs={'pk': self.post.pk})
        self.form = {
            'title': self.post.title,
            'abstract': self.post.abstract,
            'tags': self.post.tags,
            'text': self.post.text,
            'priority': self.post.priority
        }

    def test_draft(self):
        self.form['action'] = UserCreatePostForm.ACTION_DRAFT
        response = self.client.post(self.url, self.form, follow=True)
        self.post.refresh_from_db()
        self.assertEqual(response.status_code, 200)
        self.assertLessEqual((datetime.datetime.now() - self.post.date_modified).total_seconds(), 10)

    def test_submitted(self):
        self.post.status = BlogPost.STATUS_DRAFT
        self.post.save()

        self.form['action'] = UserCreatePostForm.ACTION_SUBMIT
        response = self.client.post(self.url, self.form, follow=True)
        self.assertEqual(response.status_code, 200)

    def test_approved(self):
        self.form['action'] = UserCreatePostForm.ACTION_APPROVE
        response = self.client.post(self.url, self.form, follow=True)
        self.post.refresh_from_db()
        self.assertEqual(response.status_code, 200)
        self.assertLessEqual((datetime.datetime.now() - self.post.date_approved).total_seconds(), 10)

    def test_published(self):
        self.form['action'] = UserCreatePostForm.ACTION_PUBLISH
        response = self.client.post(self.url, self.form, follow=True)
        self.post.refresh_from_db()
        self.assertEqual(response.status_code, 200)
        self.assertLessEqual((datetime.datetime.now() - self.post.date_published).total_seconds(), 10)

    def test_reject(self):
        self.form['action'] = UserCreatePostForm.ACTION_DELETE
        response = self.client.post(self.url, self.form, follow=True)
        self.assertEqual(response.status_code, 200)
开发者ID:mgoeminne,项目名称:Lexpage,代码行数:58,代码来源:tests.py


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