diff --git a/feedgen/ext/media.py b/feedgen/ext/media.py index 40f506a..e947f8a 100644 --- a/feedgen/ext/media.py +++ b/feedgen/ext/media.py @@ -5,7 +5,7 @@ Extends the feedgen to produce media tags. - :copyright: 2013-2016, Lars Kiesow + :copyright: 2013-2017, Lars Kiesow :license: FreeBSD and LGPL, see license.* for more details. ''' @@ -29,7 +29,7 @@ class MediaEntryExtension(BaseEntryExtension): ''' def __init__(self): - self.__media_content = None + self.__media_content = [] self.__media_thumbnail = None def extend_atom(self, entry): @@ -84,6 +84,9 @@ class MediaEntryExtension(BaseEntryExtension): return entry + def extend_rss(self, item): + return self.extend_atom(item) + def media_content(self, url=None, fileSize=None, type=None, medium=None, isDefault=None, expression=None, bitrate=None, framerate=None, samplingrate=None, channels=None, diff --git a/tests/test_extension.py b/tests/test_extension.py index d717e20..bcb58bb 100644 --- a/tests/test_extension.py +++ b/tests/test_extension.py @@ -194,3 +194,35 @@ class TestExtensionTorrent(unittest.TestCase): filename = root.xpath('/rss/channel/item/torrent:filename/text()', namespaces=ns) assert filename == ['file.xy'] + + +class TestExtensionMedia(unittest.TestCase): + + def setUp(self): + self.fg = FeedGenerator() + self.fg.load_extension('media') + self.fg.id('id') + self.fg.title('title') + self.fg.link(href='http://example.com', rel='self') + self.fg.description('description') + + def test_media_content(self): + fe = self.fg.add_item() + fe.id('id') + fe.title('title') + fe.content('content') + fe.media.media_content(url='file1.xy') + + ns = {'media': 'http://search.yahoo.com/mrss/', + 'a': 'http://www.w3.org/2005/Atom'} + # Check that we have the item in the resulting RSS + root = etree.fromstring(self.fg.rss_str()) + url = root.xpath('/rss/channel/item/media:group/media:content[1]/@url', + namespaces=ns) + assert url == ['file1.xy'] + + # Check that we have the item in the resulting Atom feed + root = etree.fromstring(self.fg.atom_str()) + url = root.xpath('/a:feed/a:entry/media:group/media:content[1]/@url', + namespaces=ns) + assert url == ['file1.xy']