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
|
import unittest
from lxml import etree
from feedgen.feed import FeedGenerator
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.content(url='file1.xy')
fe.media.content(url='file2.xy')
fe.media.content(url='file1.xy', group=2)
fe.media.content(url='file2.xy', group=2)
fe.media.content(url='file.xy', group=None)
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)
self.assertEqual(url, ['file1.xy', 'file1.xy'])
# There is one without a group
url = root.xpath('/rss/channel/item/media:content[1]/@url',
namespaces=ns)
self.assertEqual(url, ['file.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)
self.assertEqual(url, ['file1.xy', 'file1.xy'])
fe.media.content(content=[], replace=True)
self.assertEqual(fe.media.content(), [])
def test_media_thumbnail(self):
fe = self.fg.add_item()
fe.id('id')
fe.title('title')
fe.content('content')
fe.media.thumbnail(url='file1.xy')
fe.media.thumbnail(url='file2.xy')
fe.media.thumbnail(url='file1.xy', group=2)
fe.media.thumbnail(url='file2.xy', group=2)
fe.media.thumbnail(url='file.xy', group=None)
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:thumbnail[1]/@url',
namespaces=ns)
self.assertEqual(url, ['file1.xy', 'file1.xy'])
# There is one without a group
url = root.xpath('/rss/channel/item/media:thumbnail[1]/@url',
namespaces=ns)
self.assertEqual(url, ['file.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:thumbnail[1]/@url',
namespaces=ns)
self.assertEqual(url, ['file1.xy', 'file1.xy'])
fe.media.thumbnail(thumbnail=[], replace=True)
self.assertEqual(fe.media.thumbnail(), [])
|