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 <lkiesow@uos.de>
This commit is contained in:
Lars Kiesow 2017-03-13 20:55:14 +01:00
parent f36ff20898
commit 8901310fa0
No known key found for this signature in database
GPG key ID: 5DAFE8D9C823CE73
2 changed files with 35 additions and 1 deletions

View file

@ -32,6 +32,7 @@ class TorrentEntryExtension(BaseEntryExtension):
self.__torrent_contentlength = None self.__torrent_contentlength = None
self.__torrent_seeds = None self.__torrent_seeds = None
self.__torrent_peers = None self.__torrent_peers = None
self.__torrent_verified = None
def extend_rss(self, entry): def extend_rss(self, entry):
'''Add additional fields to an RSS item. '''Add additional fields to an RSS item.
@ -61,7 +62,7 @@ class TorrentEntryExtension(BaseEntryExtension):
peers = etree.SubElement(entry, '{%s}peers' % TORRENT_NS) peers = etree.SubElement(entry, '{%s}peers' % TORRENT_NS)
peers.text = self.__torrent_peers peers.text = self.__torrent_peers
if self.__torrent_seeds: if self.__torrent_verified:
verified = etree.SubElement(entry, '{%s}verified' % TORRENT_NS) verified = etree.SubElement(entry, '{%s}verified' % TORRENT_NS)
verified.text = self.__torrent_verified verified.text = self.__torrent_verified

View file

@ -161,3 +161,36 @@ class TestExtensionDc(unittest.TestCase):
self.fg.id('123') self.fg.id('123')
assert self.fg.atom_str() assert self.fg.atom_str()
assert self.fg.rss_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']