Skip to content

Commit

Permalink
Improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
yakky committed May 3, 2016
1 parent 5178748 commit b1b6c91
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
11 changes: 7 additions & 4 deletions djangocms_blog/feeds.py
Expand Up @@ -99,7 +99,7 @@ def add_root_elements(self, handler):
handler.addQuickElement('link', self.feed['link'])
handler.addQuickElement('description', self.feed['description'])
if self.feed['language'] is not None:
handler.addQuickElement('language', 'it-it')
handler.addQuickElement('language', self.feed['language'])
for cat in self.feed['categories']:
handler.addQuickElement('category', cat)
if self.feed['feed_copyright'] is not None:
Expand All @@ -112,10 +112,10 @@ def add_item_elements(self, handler, item):
super(FBInstantFeed, self).add_item_elements(handler, item)
if item['author']:
handler.addQuickElement('author', item['author'])
if item['date_pub'] is not None:
handler.addQuickElement("modDate", item['date'].isoformat())
if item['date_mod'] is not None:
handler.addQuickElement("pubDate", item['date'].isoformat())
handler.addQuickElement('pubDate', item['date'].isoformat())
if item['date_pub'] is not None:
handler.addQuickElement('modDate', item['date'].isoformat())
handler.startElement('description', {})
handler._write('<![CDATA[{0}]]>'.format(h.unescape(force_text(item['abstract']))))
handler.endElement('description')
Expand Down Expand Up @@ -166,6 +166,9 @@ def item_extra_kwargs(self, item):
'abstract': abstract
}

def item_categories(self, item):
return [category.safe_translation_getter('name') for category in item.categories.all()]

def item_author_name(self, item):
return ''

Expand Down
19 changes: 19 additions & 0 deletions tests/test_views.py
Expand Up @@ -4,6 +4,7 @@
import os.path

from aldryn_apphooks_config.utils import get_app_instance
from cms.api import add_plugin
from cms.toolbar.items import ModalItem
from django.contrib.auth.models import AnonymousUser
from django.core.exceptions import ImproperlyConfigured
Expand Down Expand Up @@ -315,9 +316,13 @@ def test_taggedlist_view(self):
self.assertEqual(context['post_list'][0].title, 'First post')

def test_feed(self):
self.user.first_name = 'Admin'
self.user.last_name = 'User'
self.user.save()
posts = self.get_posts()
pages = self.get_pages()
posts[0].tags.add('tag 1', 'tag 2', 'tag 3', 'tag 4')
posts[0].author = self.user
posts[0].save()
posts[1].tags.add('tag 6', 'tag 2', 'tag 5', 'tag 8')
posts[1].save()
Expand All @@ -335,6 +340,7 @@ def test_feed(self):
xml = feed(request)
self.assertContains(xml, posts[0].get_absolute_url())
self.assertContains(xml, 'Blog articles on example.com')
self.assertContains(xml, 'Admin User</dc:creator>')

with smart_override('it'):
with switch_language(posts[0], 'it'):
Expand All @@ -352,8 +358,18 @@ def test_feed(self):
self.assertEqual(list(feed.items('tag-2')), [posts[0]])

def test_instant_articles(self):
self.user.first_name = 'Admin'
self.user.last_name = 'User'
self.user.save()
posts = self.get_posts()
pages = self.get_pages()
posts[0].tags.add('tag 1', 'tag 2', 'tag 3', 'tag 4')
posts[0].categories.add(self.category_1)
posts[0].author = self.user
posts[0].save()
add_plugin(
posts[0].content, 'TextPlugin', language='en', body='<h3>Ciao</h3><p></p><p>Ciao</p>'
)

with smart_override('en'):
with switch_language(posts[0], 'en'):
Expand All @@ -373,6 +389,9 @@ def test_instant_articles(self):
self.assertContains(xml, '<link rel="canonical" href="{0}"/>'.format(
posts[0].get_full_url()
))
# Assert text transformation
self.assertContains(xml, '<h2>Ciao</h2><p>Ciao</p>')
self.assertContains(xml, '<a>Admin User</a>')

def test_sitemap(self):
posts = self.get_posts()
Expand Down

0 comments on commit b1b6c91

Please sign in to comment.