Improve coverage

This commit is contained in:
Iacopo Spalletti 2016-05-03 07:33:04 +02:00
parent 517874892a
commit b1b6c91050
No known key found for this signature in database
GPG key ID: BDCBC2EB289F60C6
2 changed files with 26 additions and 4 deletions

View file

@ -99,7 +99,7 @@ class FBInstantFeed(Rss201rev2Feed):
handler.addQuickElement('link', self.feed['link']) handler.addQuickElement('link', self.feed['link'])
handler.addQuickElement('description', self.feed['description']) handler.addQuickElement('description', self.feed['description'])
if self.feed['language'] is not None: if self.feed['language'] is not None:
handler.addQuickElement('language', 'it-it') handler.addQuickElement('language', self.feed['language'])
for cat in self.feed['categories']: for cat in self.feed['categories']:
handler.addQuickElement('category', cat) handler.addQuickElement('category', cat)
if self.feed['feed_copyright'] is not None: if self.feed['feed_copyright'] is not None:
@ -112,10 +112,10 @@ class FBInstantFeed(Rss201rev2Feed):
super(FBInstantFeed, self).add_item_elements(handler, item) super(FBInstantFeed, self).add_item_elements(handler, item)
if item['author']: if item['author']:
handler.addQuickElement('author', 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: 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.startElement('description', {})
handler._write('<![CDATA[{0}]]>'.format(h.unescape(force_text(item['abstract'])))) handler._write('<![CDATA[{0}]]>'.format(h.unescape(force_text(item['abstract']))))
handler.endElement('description') handler.endElement('description')
@ -166,6 +166,9 @@ class FBInstantArticles(LatestEntriesFeed):
'abstract': abstract '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): def item_author_name(self, item):
return '' return ''

View file

@ -4,6 +4,7 @@ from __future__ import absolute_import, print_function, unicode_literals
import os.path import os.path
from aldryn_apphooks_config.utils import get_app_instance from aldryn_apphooks_config.utils import get_app_instance
from cms.api import add_plugin
from cms.toolbar.items import ModalItem from cms.toolbar.items import ModalItem
from django.contrib.auth.models import AnonymousUser from django.contrib.auth.models import AnonymousUser
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
@ -315,9 +316,13 @@ class ViewTest(BaseTest):
self.assertEqual(context['post_list'][0].title, 'First post') self.assertEqual(context['post_list'][0].title, 'First post')
def test_feed(self): def test_feed(self):
self.user.first_name = 'Admin'
self.user.last_name = 'User'
self.user.save()
posts = self.get_posts() posts = self.get_posts()
pages = self.get_pages() pages = self.get_pages()
posts[0].tags.add('tag 1', 'tag 2', 'tag 3', 'tag 4') posts[0].tags.add('tag 1', 'tag 2', 'tag 3', 'tag 4')
posts[0].author = self.user
posts[0].save() posts[0].save()
posts[1].tags.add('tag 6', 'tag 2', 'tag 5', 'tag 8') posts[1].tags.add('tag 6', 'tag 2', 'tag 5', 'tag 8')
posts[1].save() posts[1].save()
@ -335,6 +340,7 @@ class ViewTest(BaseTest):
xml = feed(request) xml = feed(request)
self.assertContains(xml, posts[0].get_absolute_url()) self.assertContains(xml, posts[0].get_absolute_url())
self.assertContains(xml, 'Blog articles on example.com') self.assertContains(xml, 'Blog articles on example.com')
self.assertContains(xml, 'Admin User</dc:creator>')
with smart_override('it'): with smart_override('it'):
with switch_language(posts[0], 'it'): with switch_language(posts[0], 'it'):
@ -352,8 +358,18 @@ class ViewTest(BaseTest):
self.assertEqual(list(feed.items('tag-2')), [posts[0]]) self.assertEqual(list(feed.items('tag-2')), [posts[0]])
def test_instant_articles(self): def test_instant_articles(self):
self.user.first_name = 'Admin'
self.user.last_name = 'User'
self.user.save()
posts = self.get_posts() posts = self.get_posts()
pages = self.get_pages() 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 smart_override('en'):
with switch_language(posts[0], 'en'): with switch_language(posts[0], 'en'):
@ -373,6 +389,9 @@ class ViewTest(BaseTest):
self.assertContains(xml, '<link rel="canonical" href="{0}"/>'.format( self.assertContains(xml, '<link rel="canonical" href="{0}"/>'.format(
posts[0].get_full_url() 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): def test_sitemap(self):
posts = self.get_posts() posts = self.get_posts()