summaryrefslogtreecommitdiffstats
path: root/tests/test_extensions/test_torrent.py
blob: 230ec1ad93c3cc084d9654c97dbd4e095c32684a (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
import unittest

from lxml import etree

from feedgen.feed import FeedGenerator


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')
        self.assertEqual(fe.torrent.filename(), 'file.xy')
        self.assertEqual(fe.torrent.infohash(), '123')
        self.assertEqual(fe.torrent.contentlength(), '23')
        self.assertEqual(fe.torrent.seeds(), '1')
        self.assertEqual(fe.torrent.peers(), '2')
        self.assertEqual(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)
        self.assertEqual(filename, ['file.xy'])