More tests

This commit is contained in:
Iacopo Spalletti 2014-06-11 18:42:25 +02:00
parent 5180a68129
commit de9358701b
2 changed files with 47 additions and 3 deletions

View file

@ -15,7 +15,7 @@ class LatestEntriesFeed(Feed):
def title(self):
return _('Blog articles on %(site_name)s') % {'site_name': Site.objects.get_current().name}
def items(self, obj):
def items(self, obj=None):
return Post.objects.published().order_by('-date_published')[:10]
def item_title(self, item):
@ -28,7 +28,7 @@ class LatestEntriesFeed(Feed):
class TagFeed(LatestEntriesFeed):
def get_object(self, request, tag):
return tag
return tag # pragma: no cover
def items(self, obj):
def items(self, obj=None):
return Post.objects.published().filter(tags__slug=obj)[:10]

View file

@ -3,6 +3,8 @@ from datetime import date
from django.contrib.auth.models import AnonymousUser
from django.http import Http404
from django.utils.translation import activate
from djangocms_blog.feeds import LatestEntriesFeed, TagFeed
from djangocms_blog.sitemaps import BlogSitemap
from djangocms_blog.views import PostListView, PostDetailView, PostArchiveView, \
CategoryEntriesView, AuthorEntriesView, TaggedListView
@ -169,3 +171,45 @@ class ViewTest(BaseTest):
self.assertEqual(list(context['post_list']), [post2])
self.assertEqual(context['paginator'].count, 2)
self.assertEqual(context['post_list'][0].title, 'Second post')
def test_feed(self):
page1, page2 = self.get_pages()
post1, post2 = self.get_posts()
post1.tags.add('tag 1', 'tag 2', 'tag 3', 'tag 4')
post1.save()
post2.tags.add('tag 6', 'tag 2', 'tag 5', 'tag 8')
post2.save()
post1.set_current_language('en')
feed = LatestEntriesFeed()
self.assertEqual(list(feed.items()), [post1])
request = self.get_page_request(page1, self.user, r'/en/blog/', lang_code='en', edit=False)
xml = feed(request)
self.assertContains(xml, post1.get_absolute_url())
self.assertContains(xml, 'Blog articles on example.com')
activate('it')
post1.set_current_language('it')
feed = LatestEntriesFeed()
self.assertEqual(list(feed.items()), [post1])
request = self.get_page_request(page1, self.user, r'/it/blog/', lang_code='it', edit=False)
xml = feed(request)
self.assertContains(xml, post1.get_absolute_url())
self.assertContains(xml, 'Articoli del blog su example.com')
feed = TagFeed()
self.assertEqual(list(feed.items('tag-2')), [post1])
def test_sitemap(self):
post1, post2 = self.get_posts()
post1.tags.add('tag 1', 'tag 2', 'tag 3', 'tag 4')
post1.save()
post2.tags.add('tag 6', 'tag 2', 'tag 5', 'tag 8')
post2.publish = True
post2.save()
post1.set_current_language('en')
sitemap = BlogSitemap()
self.assertEqual(sitemap.items().count(), 2)
for item in sitemap.items():
self.assertTrue(sitemap.lastmod(item).date(), date.today())