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