Exemple #1
0
    def test_cache_featured_review(self):
        """
        test cache invalidate for featured review
        """
        post = Post.objects.featured_review()
        self.assertEqual(post, None)

        post = Post()
        post.title = "first post"
        post.permalink = "first-post"
        post.body = "post first post"
        post.user = self.u1
        post.status = Post.PUBLIC_STATUS
        post.type = Post.TYPE_POST
        post.featured_note = True
        post.save()

        post = Post.objects.featured_review()
        self.assertEqual(post.permalink, u'first-post')

        post1 = Post()
        post1.title = "second post"
        post1.permalink = "second-post"
        post1.body = "post second post"
        post1.user = self.u1
        post1.status = Post.PUBLIC_STATUS
        post1.type = Post.TYPE_POST
        post1.featured_note = True
        post1.save()

        post = Post.objects.featured_review()
        self.assertEqual(post.permalink, u'second-post')

        post2 = Post()
        post2.title = "third post"
        post2.permalink = "third-post"
        post2.body = "post third post"
        post2.user = self.u1
        post2.status = Post.PUBLIC_STATUS
        post2.type = Post.TYPE_POST
        post2.featured_note = True
        post2.save()

        post = Post.objects.featured_review()
        self.assertEqual(post.permalink, u'third-post')

        # change featured post status and check if cache is invalidated
        post2 = Post.objects.get(title__iexact='third post')
        post2.status = Post.DRAFT_STATUS
        post2.save()

        post = Post.objects.featured_review()
        self.assertEqual(post.permalink, u'second-post')

        # republished post
        post2 = Post.objects.get(title__iexact='third post')
        post2.status = Post.PUBLIC_STATUS
        post2.save()

        post = Post.objects.featured_review()
        self.assertEqual(post.permalink, u'third-post')
        self.assertEqual(Post.objects.recent_reviews().count(), 0)
Exemple #2
0
    def test_cache_featured_review(self):
        """
        test cache invalidate for featured review
        """
        post = Post.objects.featured_review()
        self.assertEqual(post, None)

        post = Post()
        post.title = "first post"
        post.permalink = "first-post"
        post.body = "post first post"
        post.user = self.u1
        post.status = Post.PUBLIC_STATUS
        post.type = Post.TYPE_POST
        post.featured_note = True
        post.save()

        post = Post.objects.featured_review()
        self.assertEqual(post.permalink, u'first-post')

        post1 = Post()
        post1.title = "second post"
        post1.permalink = "second-post"
        post1.body = "post second post"
        post1.user = self.u1
        post1.status = Post.PUBLIC_STATUS
        post1.type = Post.TYPE_POST
        post1.featured_note = True
        post1.save()

        post = Post.objects.featured_review()
        self.assertEqual(post.permalink, u'second-post')

        post2 = Post()
        post2.title = "third post"
        post2.permalink = "third-post"
        post2.body = "post third post"
        post2.user = self.u1
        post2.status = Post.PUBLIC_STATUS
        post2.type = Post.TYPE_POST
        post2.featured_note = True
        post2.save()

        post = Post.objects.featured_review()
        self.assertEqual(post.permalink, u'third-post')

        # change featured post status and check if cache is invalidated
        post2 = Post.objects.get(title__iexact='third post')
        post2.status = Post.DRAFT_STATUS
        post2.save()

        post = Post.objects.featured_review()
        self.assertEqual(post.permalink, u'second-post')

        # republished post
        post2 = Post.objects.get(title__iexact='third post')
        post2.status = Post.PUBLIC_STATUS
        post2.save()

        post = Post.objects.featured_review()
        self.assertEqual(post.permalink, u'third-post')
        self.assertEqual(Post.objects.recent_reviews().count(), 0)