Add tests

This commit is contained in:
Iacopo Spalletti 2016-04-30 08:12:31 +02:00
parent 91df9a8b43
commit b0bb317be5
No known key found for this signature in database
GPG key ID: BDCBC2EB289F60C6
2 changed files with 27 additions and 1 deletions

View file

@ -81,6 +81,7 @@ class FBInstantFeed(Rss201rev2Feed):
handler._write(force_text(item['content']))
handler._write(']]>')
handler.endElement('content:encoded')
handler.addQuickElement('guid', item['guid'])
class FBInstantArticles(LatestEntriesFeed):
@ -101,4 +102,5 @@ class FBInstantArticles(LatestEntriesFeed):
return {
'content': content,
'slug': item.safe_translation_getter('slug'),
'guid': item.guid,
}

View file

@ -2,6 +2,7 @@
from __future__ import absolute_import, print_function, unicode_literals
import os.path
from django.utils.encoding import force_text
from aldryn_apphooks_config.utils import get_app_instance
from cms.toolbar.items import ModalItem
@ -15,7 +16,7 @@ from parler.tests.utils import override_parler_settings
from parler.utils.conf import add_default_language_settings
from parler.utils.context import smart_override, switch_language
from djangocms_blog.feeds import LatestEntriesFeed, TagFeed
from djangocms_blog.feeds import LatestEntriesFeed, TagFeed, FBInstantArticles
from djangocms_blog.models import BLOG_CURRENT_NAMESPACE
from djangocms_blog.settings import get_setting
from djangocms_blog.sitemaps import BlogSitemap
@ -350,6 +351,29 @@ class ViewTest(BaseTest):
feed.config = self.app_config_1
self.assertEqual(list(feed.items('tag-2')), [posts[0]])
def test_instant_articles(self):
posts = self.get_posts()
pages = self.get_pages()
with smart_override('en'):
with switch_language(posts[0], 'en'):
request = self.get_page_request(
pages[1], self.user, path=posts[0].get_absolute_url()
)
feed = FBInstantArticles()
feed.namespace, feed.config = get_app_instance(request)
self.assertEqual(list(feed.items()), [posts[0]])
xml = feed(request)
self.assertContains(xml, '<guid>{0}</guid>'.format(posts[0].guid))
self.assertContains(xml, 'content:encoded')
self.assertContains(xml, 'class="op-published" datetime="{0}"'.format(
posts[0].date_published.isoformat()
))
self.assertContains(xml, '<link rel="canonical" href="{0}"/>'.format(
posts[0].get_full_url()
))
def test_sitemap(self):
posts = self.get_posts()
self.get_pages()