4
from miro import subscription
5
from miro import autodiscover
9
from miro.test.framework import MiroTestCase
11
URL_1 = "http://www.domain-1.com/videos/rss.xml"
12
URL_2 = "http://www.domain-2.com/videos/rss.xml"
13
URL_3 = "http://www.domain-1.com/videos/atom.xml"
14
URL_4 = "http://www.domain-2.com/videos/atom.xml"
16
# -----------------------------------------------------------------------------
19
"""Removes most of the boilerplate for getting subscriptions given
20
some specific entry or entries in the <body> ... </body> section.
23
<?xml version="1.0" encoding="utf-8" ?>
24
<!-- OPML generated by Miro v3.1-git on Thu Jul 22 15:23:10 2010 -->
26
xmlns:miro="http://getmiro.com/opml/subscriptions">
28
<title>miro_subscriptions.opml</title>
35
return autodiscover.parse_content(teststring)
37
class TestImporter(unittest.TestCase):
38
def test_simple_flat(self):
40
<?xml version="1.0" encoding="utf-8"?>
42
xmlns:miro="http://getmiro.com/opml/subscriptions">
44
<title>Sample OPML Flat Subscription List</title>
47
<outline text="Sample Dummy RSS Feed 1" type="rss" xmlUrl="%s" />
48
<outline text="Sample Dummy Atom Feed 1" type="rss" xmlUrl="%s" />
49
<outline text="Sample Dummy RSS Feed 2" type="rss" xmlUrl="%s" />
50
<outline text="Sample Dummy Atom Feed 2" type="rss" xmlUrl="%s" />
53
""" % (URL_1, URL_3, URL_2, URL_4)
55
subscriptions = autodiscover.parse_content(teststring)
56
self.assertEquals(len(subscriptions), 4)
57
for feed in subscriptions:
58
self.assertEquals(feed['type'], 'feed')
59
self.assertEquals(subscriptions[0]['url'], URL_1)
60
self.assertEquals(subscriptions[1]['url'], URL_3)
61
self.assertEquals(subscriptions[2]['url'], URL_2)
62
self.assertEquals(subscriptions[3]['url'], URL_4)
64
def test_simple_nested(self):
66
<?xml version="1.0" encoding="utf-8"?>
68
xmlns:miro="http://getmiro.com/opml/subscriptions">
70
<title>Sample OPML Flat Subscription List</title>
73
<outline text="folder 1">
74
<outline text="Sample Dummy RSS Feed 1" type="rss" xmlUrl="%s" />
75
<outline text="folder1-1">
76
<outline text="Sample Dummy Atom Feed 1" type="rss" xmlUrl="%s" />
79
<outline text="folder 2">
80
<outline text="folder2-1">
81
<outline text="Sample Dummy RSS Feed 2" type="rss" xmlUrl="%s" />
83
<outline text="Sample Dummy Atom Feed 2" type="rss" xmlUrl="%s" />
87
""" % (URL_1, URL_3, URL_2, URL_4)
89
subscriptions = autodiscover.parse_content(teststring)
90
self.assertEquals(len(subscriptions), 4)
91
for feed in subscriptions:
92
self.assertEquals(feed['type'], 'feed')
94
self.assertEquals(subscriptions[0]['url'], URL_1)
95
self.assertEquals(subscriptions[1]['url'], URL_3)
96
self.assertEquals(subscriptions[2]['url'], URL_2)
97
self.assertEquals(subscriptions[3]['url'], URL_4)
99
def test_basic_feed(self):
100
subs = _get_subs("""\
102
text="GeekBeat.TV (Large MP4)"
103
xmlUrl="http://revision3.com/geekbeattv/feed/MP4-Large"
104
miro:section="video" />
108
self.assertEquals(feed['type'], 'feed')
110
feed['url'], u"http://revision3.com/geekbeattv/feed/MP4-Large")
111
self.assertEquals(feed['section'], u"video")
113
feed['title'], u"GeekBeat.TV (Large MP4)")
115
def test_basic_feed_2(self):
116
subs = _get_subs("""\
118
text="The Economist: All video"
119
xmlUrl="http://feeds2.feedburner.com/feedroom/xDDO"
121
miro:autoDownload="off"/>
125
self.assertEquals(feed['type'], 'feed')
127
feed['url'], u"http://feeds2.feedburner.com/feedroom/xDDO")
128
self.assertEquals(feed['section'], u"video")
130
feed['title'], u"The Economist: All video")
132
feed["auto_download_mode"], u"off")
135
# if there's no url, there shouldn't be a subscription
136
subs = _get_subs("""\
137
<outline type="rss" />
139
self.assert_(len(subs) == 0)
141
# if there's a url, we pick it up
142
subs = _get_subs("""\
144
xmlUrl="http://example.com/feed/"/>
146
self.assertEquals(subs[0]["url"], u"http://example.com/feed/")
148
def test_title(self):
149
# if there's no title, then the sub won't have a title key
150
subs = _get_subs("""\
152
xmlUrl="http://feeds2.feedburner.com/feedroom/xDDO"
154
miro:autoDownload="off"/>
156
self.assert_("title" not in subs[0])
158
# if there's no title, then the sub won't have a title key
159
subs = _get_subs("""\
161
xmlUrl="http://feeds2.feedburner.com/feedroom/xDDO"
164
miro:autoDownload="off"/>
166
self.assert_("title" not in subs[0])
168
# if title == url, then the sub won't have a title key
169
subs = _get_subs("""\
171
xmlUrl="http://feeds2.feedburner.com/feedroom/xDDO"
172
text="http://feeds2.feedburner.com/feedroom/xDDO"
174
miro:autoDownload="off"/>
176
self.assert_("title" not in subs[0])
178
def test_section(self):
179
# if there's no section, there won't be a section key
180
subs = _get_subs("""\
182
xmlUrl="http://feeds2.feedburner.com/feedroom/xDDO"
183
miro:autoDownload="off"/>
185
self.assert_("section" not in subs[0])
187
# if the section isn't "audio" or "video", there won't be
189
subs = _get_subs("""\
191
xmlUrl="http://feeds2.feedburner.com/feedroom/xDDO"
193
miro:autoDownload="off"/>
195
self.assert_("section" not in subs[0])
197
def test_auto_download(self):
198
# if there's no autodownload, then there's no key
199
subs = _get_subs("""\
201
xmlUrl="http://feeds2.feedburner.com/feedroom/xDDO"/>
203
self.assert_("auto_download_mode" not in subs[0])
205
# autodownload can be autoDownload
206
subs = _get_subs("""\
208
xmlUrl="http://feeds2.feedburner.com/feedroom/xDDO"
211
self.assertEquals(subs[0]["auto_download_mode"], "all")
213
# autodownload can be miro:autoDownload
214
subs = _get_subs("""\
216
xmlUrl="http://feeds2.feedburner.com/feedroom/xDDO"
217
miro:autoDownload="all"/>
219
self.assertEquals(subs[0]["auto_download_mode"], "all")
221
# must be either "all", "off", or "new"
222
subs = _get_subs("""\
224
xmlUrl="http://feeds2.feedburner.com/feedroom/xDDO"
225
miro:autoDownload="foo"/>
227
self.assert_("auto_download_mode" not in subs[0])
229
def test_expiry_time(self):
230
# if there's no expiryTime, then there's no key
231
subs = _get_subs("""\
233
xmlUrl="http://feeds2.feedburner.com/feedroom/xDDO"/>
235
self.assert_("expiry_time" not in subs[0])
237
# expiry_time can be expiryTime
238
subs = _get_subs("""\
240
xmlUrl="http://feeds2.feedburner.com/feedroom/xDDO"
243
self.assertEquals(subs[0]["expiry_time"], 240)
245
# expiry_time can be miro:expiryTime
246
subs = _get_subs("""\
248
xmlUrl="http://feeds2.feedburner.com/feedroom/xDDO"
249
miro:expiryTime="240"/>
251
self.assertEquals(subs[0]["expiry_time"], 240)
253
# expiry_time can be int or "never" or "system"
254
subs = _get_subs("""\
256
xmlUrl="http://feeds2.feedburner.com/feedroom/xDDO"
257
miro:expiryTime="never"/>
259
self.assertEquals(subs[0]["expiry_time"], "never")
261
subs = _get_subs("""\
263
xmlUrl="http://feeds2.feedburner.com/feedroom/xDDO"
264
miro:expiryTime="system"/>
266
self.assertEquals(subs[0]["expiry_time"], "system")
268
subs = _get_subs("""\
270
xmlUrl="http://feeds2.feedburner.com/feedroom/xDDO"
271
miro:expiryTime="foo"/>
273
self.assert_("expiry_time" not in subs[0])
275
# FIXME - test folders
278
class TestExporter(MiroTestCase):
279
def _get_export(self, media_tabs, site_tabs):
280
return opml.Exporter().export_content(
281
"/tmp/foo.opml", media_tabs, site_tabs)
283
def test_simple(self):
284
feed1 = feed.Feed(u"http://example.com/feed/")
285
feed1.finish_generate_feed(
286
feed.RSSFeedImpl(u"http://example.com/feed/",
290
data = self._get_export([feed1], [])
292
subs = autodiscover.parse_content(data)
293
self.assertEquals(subs[0]["url"], u"http://example.com/feed/")
294
self.assertEquals(subs[0]["title"], u"Foo feed")
295
self.assertEquals(subs[0]["type"], "feed")
297
# FIXME - add more export tests
298
# FIXME - test folders