Пример #1
0
    def test_rss_feed(self):
        PostFactory.create_batch(5, online=True)

        posts_url = reverse('posts:post_feed')

        # Check the "secret" debug branch
        with override_settings(DEBUG=True):
            response = self.client.get(posts_url, {'debug': 'yep'})

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response['Content-Type'], 'text/plain; charset=utf-8')
        response = self.client.get(posts_url)
        self.assertEqual(response.status_code, 200)
        self._rss_response_is_sane(response, expected_item_count=5)
Пример #2
0
    def test_posts_sitemap(self):
        PostFactory.create_batch(5, online=True)

        # Check that offline ones aren't being shown.
        PostFactory.create(online=False, date=now() - timedelta(minutes=1))

        # ...and ones with a future publication date.
        PostFactory.create(online=True, date=now() + timedelta(days=1))

        response = self.client.get(
            reverse('django.contrib.sitemaps.views.sitemap'))
        self.assertEqual(response.status_code, 200)

        tree = ElementTree.fromstring(response.content.decode('utf-8'))
        self.assertEqual(len(list(tree)), 5)
Пример #3
0
    def test_prefetching_categories(self):
        cat = CategoryFactory.create()
        cat2 = CategoryFactory.create()

        PostFactory.create_batch(10, online=True, categories=[cat, cat2])

        # Baseload number of queries for loading the list, with no objects,
        # should be 5. That is getting the current session, getting the
        # current user, some savepoint thing (two queries, one for grab & one
        # for release), and getting the total count of posts. Our prefetching
        # should mean we only add 2 queries to this regardless of the number
        # of posts
        with self.assertNumQueries(7):
            response = self.client.get(reverse('admin:posts_post_changelist'))

        self.assertEqual(len(response.context_data['cl'].result_list), 10)
Пример #4
0
    def test_category_feed_view(self):
        category = CategoryFactory.create()
        post = PostFactory.create(online=True)
        post.categories.add(category)

        # Check queryset exclusion for other categories...
        PostFactory.create_batch(2, online=True)
        # ...and ensure that offline posts are being excluded.
        offline_post = PostFactory.create(online=False)
        offline_post.categories.add(category.pk)

        response = self.client.get(reverse('posts:post_category_feed', kwargs={'category': category.slug}))

        self.assertEqual(response.status_code, 200)
        self.assertEqual(list(response.context_data['object_list']), [post])
        self._rss_response_is_sane(response, expected_item_count=1)