tests.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:securethenews 作者: freedomofpress 项目源码 文件源码
def test_frontend_cache_invalidation(self, mock_purge_page_from_cache):
        """When a BlogPost is published or unpublished, we should invalidate
        the frontend cache for the corresponding BlogIndexPage."""
        blog_index_page = BlogIndexPage.objects.first()
        new_blog_post = BlogPost(
            title='New Blog Post',
            slug='new-blog-post',
            date=datetime.date.today(),
            byline='Author'
        )
        blog_index_page.add_child(instance=new_blog_post)

        # Publishing a BlogPost should trigger frontend cache invalidation for
        # the corresponding BlogIndexPage.
        #
        # XXX: For some reason, Wagtail uses the generic Page object as the
        # instance for the page_published signal, but uses the specific object
        # (e.g. BlogIndexPage) as the instance for the page_unpublished signal.
        # You can get the generic Page object from a specific object with
        # .page_ptr, or go the other way with .specific. For more, see:
        # http://docs.wagtail.io/en/v1.8/topics/pages.html#working-with-pages
        new_blog_post.save_revision().publish()
        mock_purge_page_from_cache.assert_called_once_with(
                                            blog_index_page.page_ptr)

        # Unpublishing the BlogPost should also trigger frontend cache
        # invalidation for the corresponding BlogIndexPage.
        mock_purge_page_from_cache.reset_mock()
        new_blog_post.unpublish()
        mock_purge_page_from_cache.assert_called_once_with(blog_index_page)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号