2015-03-08 10:39:18 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
2016-09-04 18:56:30 +02:00
|
|
|
# vim: set et ts=4 sw=4 sts=4 sta tw=80 cc=81:
|
2015-03-08 10:39:18 +01:00
|
|
|
|
|
|
|
"""
|
|
|
|
Tests for extensions
|
|
|
|
"""
|
|
|
|
|
|
|
|
import unittest
|
2016-08-29 00:22:03 +02:00
|
|
|
from feedgen.feed import FeedGenerator
|
2015-03-08 10:39:18 +01:00
|
|
|
from lxml import etree
|
|
|
|
|
|
|
|
|
|
|
|
class TestExtensionSyndication(unittest.TestCase):
|
|
|
|
|
2016-12-21 02:04:24 +01:00
|
|
|
SYN_NS = {'sy': 'http://purl.org/rss/1.0/modules/syndication/'}
|
|
|
|
|
2015-03-08 10:39:18 +01:00
|
|
|
def setUp(self):
|
|
|
|
self.fg = FeedGenerator()
|
|
|
|
self.fg.load_extension('syndication')
|
|
|
|
self.fg.title('title')
|
|
|
|
self.fg.link(href='http://example.com', rel='self')
|
|
|
|
self.fg.description('description')
|
|
|
|
|
|
|
|
def test_update_period(self):
|
2016-12-21 02:04:24 +01:00
|
|
|
for period_type in ('hourly', 'daily', 'weekly', 'monthly', 'yearly'):
|
2015-03-08 10:39:18 +01:00
|
|
|
self.fg.syndication.update_period(period_type)
|
|
|
|
root = etree.fromstring(self.fg.rss_str())
|
|
|
|
a = root.xpath('/rss/channel/sy:UpdatePeriod',
|
2016-12-21 02:04:24 +01:00
|
|
|
namespaces=self.SYN_NS)
|
2015-03-08 10:39:18 +01:00
|
|
|
assert a[0].text == period_type
|
|
|
|
|
|
|
|
def test_update_frequency(self):
|
|
|
|
for frequency in (1, 100, 2000, 100000):
|
|
|
|
self.fg.syndication.update_frequency(frequency)
|
|
|
|
root = etree.fromstring(self.fg.rss_str())
|
|
|
|
a = root.xpath('/rss/channel/sy:UpdateFrequency',
|
2016-12-21 02:04:24 +01:00
|
|
|
namespaces=self.SYN_NS)
|
2015-03-08 10:39:18 +01:00
|
|
|
assert a[0].text == str(frequency)
|
|
|
|
|
|
|
|
def test_update_base(self):
|
|
|
|
base = '2000-01-01T12:00+00:00'
|
|
|
|
self.fg.syndication.update_base(base)
|
|
|
|
root = etree.fromstring(self.fg.rss_str())
|
2016-12-21 02:04:24 +01:00
|
|
|
a = root.xpath('/rss/channel/sy:UpdateBase', namespaces=self.SYN_NS)
|
2015-03-08 10:39:18 +01:00
|
|
|
assert a[0].text == base
|
2016-09-04 17:49:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TestExtensionPodcast(unittest.TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.fg = FeedGenerator()
|
|
|
|
self.fg.load_extension('podcast')
|
|
|
|
self.fg.title('title')
|
|
|
|
self.fg.link(href='http://example.com', rel='self')
|
|
|
|
self.fg.description('description')
|
|
|
|
|
2016-09-04 18:56:30 +02:00
|
|
|
def test_category_new(self):
|
2016-12-21 02:04:24 +01:00
|
|
|
self.fg.podcast.itunes_category([{'cat': 'Technology',
|
|
|
|
'sub': 'Podcasting'}])
|
2016-09-04 18:56:30 +02:00
|
|
|
self.fg.podcast.itunes_explicit('no')
|
|
|
|
self.fg.podcast.itunes_complete('no')
|
|
|
|
self.fg.podcast.itunes_new_feed_url('http://example.com/new-feed.rss')
|
|
|
|
self.fg.podcast.itunes_owner('John Doe', 'john@example.com')
|
2016-12-21 02:04:24 +01:00
|
|
|
ns = {'itunes': 'http://www.itunes.com/dtds/podcast-1.0.dtd'}
|
2016-09-04 18:56:30 +02:00
|
|
|
root = etree.fromstring(self.fg.rss_str())
|
|
|
|
cat = root.xpath('/rss/channel/itunes:category/@text', namespaces=ns)
|
|
|
|
scat = root.xpath('/rss/channel/itunes:category/itunes:category/@text',
|
2016-12-21 02:04:24 +01:00
|
|
|
namespaces=ns)
|
2016-09-04 18:56:30 +02:00
|
|
|
assert cat[0] == 'Technology'
|
|
|
|
assert scat[0] == 'Podcasting'
|
|
|
|
|
2016-09-04 17:49:07 +02:00
|
|
|
def test_category(self):
|
|
|
|
self.fg.podcast.itunes_category('Technology', 'Podcasting')
|
|
|
|
self.fg.podcast.itunes_explicit('no')
|
|
|
|
self.fg.podcast.itunes_complete('no')
|
|
|
|
self.fg.podcast.itunes_new_feed_url('http://example.com/new-feed.rss')
|
|
|
|
self.fg.podcast.itunes_owner('John Doe', 'john@example.com')
|
2016-12-21 02:04:24 +01:00
|
|
|
ns = {'itunes': 'http://www.itunes.com/dtds/podcast-1.0.dtd'}
|
2016-09-04 17:49:07 +02:00
|
|
|
root = etree.fromstring(self.fg.rss_str())
|
|
|
|
cat = root.xpath('/rss/channel/itunes:category/@text', namespaces=ns)
|
|
|
|
scat = root.xpath('/rss/channel/itunes:category/itunes:category/@text',
|
2016-12-21 02:04:24 +01:00
|
|
|
namespaces=ns)
|
2016-09-04 17:49:07 +02:00
|
|
|
assert cat[0] == 'Technology'
|
|
|
|
assert scat[0] == 'Podcasting'
|