From 8901310fa08866b634f8c84fb02d2bb68b3fb370 Mon Sep 17 00:00:00 2001 From: Lars Kiesow Date: Mon, 13 Mar 2017 20:55:14 +0100 Subject: [PATCH] Added Torrent Tests This patch adds tests for the torrent extension. It also fixes a minor bug discovered by the new tests. Signed-off-by: Lars Kiesow --- feedgen/ext/torrent.py | 3 ++- tests/test_extension.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/feedgen/ext/torrent.py b/feedgen/ext/torrent.py index 29e8b4b..a2eb49c 100644 --- a/feedgen/ext/torrent.py +++ b/feedgen/ext/torrent.py @@ -32,6 +32,7 @@ class TorrentEntryExtension(BaseEntryExtension): self.__torrent_contentlength = None self.__torrent_seeds = None self.__torrent_peers = None + self.__torrent_verified = None def extend_rss(self, entry): '''Add additional fields to an RSS item. @@ -61,7 +62,7 @@ class TorrentEntryExtension(BaseEntryExtension): peers = etree.SubElement(entry, '{%s}peers' % TORRENT_NS) peers.text = self.__torrent_peers - if self.__torrent_seeds: + if self.__torrent_verified: verified = etree.SubElement(entry, '{%s}verified' % TORRENT_NS) verified.text = self.__torrent_verified diff --git a/tests/test_extension.py b/tests/test_extension.py index c1506a9..3c41b70 100644 --- a/tests/test_extension.py +++ b/tests/test_extension.py @@ -161,3 +161,36 @@ class TestExtensionDc(unittest.TestCase): self.fg.id('123') assert self.fg.atom_str() assert self.fg.rss_str() + + +class TestExtensionTorrent(unittest.TestCase): + + def setUp(self): + self.fg = FeedGenerator() + self.fg.load_extension('torrent') + self.fg.title('title') + self.fg.link(href='http://example.com', rel='self') + self.fg.description('description') + + def test_podcastEntryItems(self): + fe = self.fg.add_item() + fe.title('y') + fe.torrent.filename('file.xy') + fe.torrent.infohash('123') + fe.torrent.contentlength('23') + fe.torrent.seeds('1') + fe.torrent.peers('2') + fe.torrent.verified('1') + assert fe.torrent.filename() == 'file.xy' + assert fe.torrent.infohash() == '123' + assert fe.torrent.contentlength() == '23' + assert fe.torrent.seeds() == '1' + assert fe.torrent.peers() == '2' + assert fe.torrent.verified() == '1' + + # Check that we have the item in the resulting XML + ns = {'torrent': 'http://xmlns.ezrss.it/0.1/dtd/'} + root = etree.fromstring(self.fg.rss_str()) + filename = root.xpath('/rss/channel/item/torrent:filename/text()', + namespaces=ns) + assert filename == ['file.xy']