summaryrefslogtreecommitdiffstats
path: root/tests/test_extensions/test_podcast.py
blob: 84c8c963497684f734bd52c746402b5cbbc1336a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import unittest

from lxml import etree

from feedgen.feed import FeedGenerator


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')

    def test_category_new(self):
        self.fg.podcast.itunes_category([{'cat': 'Technology',
                                          'sub': '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')
        ns = {'itunes': 'http://www.itunes.com/dtds/podcast-1.0.dtd'}
        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',
                          namespaces=ns)
        self.assertEqual(cat[0], 'Technology')
        self.assertEqual(scat[0], 'Podcasting')

    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')
        ns = {'itunes': 'http://www.itunes.com/dtds/podcast-1.0.dtd'}
        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',
                          namespaces=ns)
        self.assertEqual(cat[0], 'Technology')
        self.assertEqual(scat[0], 'Podcasting')

    def test_podcastItems(self):
        fg = self.fg
        fg.podcast.itunes_author('Lars Kiesow')
        fg.podcast.itunes_block('x')
        fg.podcast.itunes_complete(False)
        fg.podcast.itunes_explicit('no')
        fg.podcast.itunes_image('x.png')
        fg.podcast.itunes_subtitle('x')
        fg.podcast.itunes_summary('x')
        fg.podcast.itunes_type('episodic')
        self.assertEqual(fg.podcast.itunes_author(), 'Lars Kiesow')
        self.assertEqual(fg.podcast.itunes_block(), 'x')
        self.assertEqual(fg.podcast.itunes_complete(), 'no')
        self.assertEqual(fg.podcast.itunes_explicit(), 'no')
        self.assertEqual(fg.podcast.itunes_image(), 'x.png')
        self.assertEqual(fg.podcast.itunes_subtitle(), 'x')
        self.assertEqual(fg.podcast.itunes_summary(), 'x')
        self.assertEqual(fg.podcast.itunes_type(), 'episodic')

        # Check that we have the item in the resulting XML
        ns = {'itunes': 'http://www.itunes.com/dtds/podcast-1.0.dtd'}
        root = etree.fromstring(self.fg.rss_str())
        author = root.xpath('/rss/channel/itunes:author/text()', namespaces=ns)
        self.assertEqual(author, ['Lars Kiesow'])

    def test_podcastEntryItems(self):
        fe = self.fg.add_item()
        fe.title('y')
        fe.podcast.itunes_author('Lars Kiesow')
        fe.podcast.itunes_block('x')
        fe.podcast.itunes_duration('00:01:30')
        fe.podcast.itunes_explicit('no')
        fe.podcast.itunes_image('x.png')
        fe.podcast.itunes_is_closed_captioned('yes')
        fe.podcast.itunes_order(1)
        fe.podcast.itunes_subtitle('x')
        fe.podcast.itunes_summary('x')
        fe.podcast.itunes_season(1)
        fe.podcast.itunes_episode(1)
        fe.podcast.itunes_title('Podcast Title')
        fe.podcast.itunes_episode_type('full')
        self.assertEqual(fe.podcast.itunes_author(), 'Lars Kiesow')
        self.assertEqual(fe.podcast.itunes_block(), 'x')
        self.assertEqual(fe.podcast.itunes_duration(), '00:01:30')
        self.assertEqual(fe.podcast.itunes_explicit(), 'no')
        self.assertEqual(fe.podcast.itunes_image(), 'x.png')
        self.assertTrue(fe.podcast.itunes_is_closed_captioned())
        self.assertEqual(fe.podcast.itunes_order(), 1)
        self.assertEqual(fe.podcast.itunes_subtitle(), 'x')
        self.assertEqual(fe.podcast.itunes_summary(), 'x')
        self.assertEqual(fe.podcast.itunes_season(), 1)
        self.assertEqual(fe.podcast.itunes_episode(), 1)
        self.assertEqual(fe.podcast.itunes_title(), 'Podcast Title')
        self.assertEqual(fe.podcast.itunes_episode_type(), 'full')

        # Check that we have the item in the resulting XML
        ns = {'itunes': 'http://www.itunes.com/dtds/podcast-1.0.dtd'}
        root = etree.fromstring(self.fg.rss_str())
        author = root.xpath('/rss/channel/item/itunes:author/text()',
                            namespaces=ns)
        self.assertEqual(author, ['Lars Kiesow'])