def test_tag_filter_decreased_count(self): tag_filter = TagFilter(is_multivalue=True) tag_filter.value = ['refactoring'] query = Article.get_published() query = tag_filter.filter(query) context = tag_filter.get_context_data([item.id for item in query]) for tag in context['tag_cloud']: if tag.slug == "south": self.assertEqual(tag.count, 1)
def test_own_filter_articles(self): filter = OwnerFilter() filter.value = 'articles' filter.user = User.objects.get(username="******") query = Article.get_published() query = filter.filter(query) self.assertEqual(len(query), 6) context = filter.get_context_data([item.id for item in query]) self.assertTrue(context.has_key('own_articles')) self.assertEqual(context['own_articles_count'], 6) self.assertEqual(context['own_drafts_count'], 1)
def test_own_filter_anonymous(self): filter = OwnerFilter() filter.value = 'articles' query = Article.get_published() query = filter.filter(query) self.assertEqual(len(query), 39) context = filter.get_context_data([item.id for item in query]) self.assertFalse(context.has_key('own_articles')) self.assertFalse(context.has_key('own_articles_count')) self.assertFalse(context.has_key('own_drafts')) self.assertFalse(context.has_key('own_drafts_count'))
def test_tag_filter_single_value(self): tag_filter = TagFilter(is_multivalue=True) tag_filter.value = ['south'] query = Article.get_published() query = tag_filter.filter(query) self.assertEqual(len(query), 2) context = tag_filter.get_context_data([item.id for item in query]) self.assertTrue(context.has_key('tag_cloud')) self.assertEqual(len(context['tag_cloud']), 7) for tag in context['tag_cloud']: if tag.slug == "south": self.assertEqual(tag.count, 2) self.assertTrue(tag.selected) self.assertFalse(hasattr(tag, 'disabled'))
def test_filter(self): filter = CategoryFilter() filter.value = "django" query = Article.get_published() query = filter.filter(query) self.assertEqual(len(query), 2)
def get_feed_articles(): return Article.get_published()[:LATEST_FEED_COUNT]