~ubuntu-branches/ubuntu/natty/miro/natty

« back to all changes in this revision

Viewing changes to lib/test/opmltest.py

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2011-01-22 02:46:33 UTC
  • mfrom: (1.4.10 upstream) (1.7.5 experimental)
  • Revision ID: james.westby@ubuntu.com-20110122024633-kjme8u93y2il5nmf
Tags: 3.5.1-1ubuntu1
* Merge from debian.  Remaining ubuntu changes:
  - Use python 2.7 instead of python 2.6
  - Relax dependency on python-dbus to >= 0.83.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import os
 
2
import unittest
 
3
 
 
4
from miro import subscription
 
5
from miro import autodiscover
 
6
from miro import feed
 
7
from miro import opml
 
8
 
 
9
from miro.test.framework import MiroTestCase
 
10
 
 
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"
 
15
 
 
16
# -----------------------------------------------------------------------------
 
17
 
 
18
def _get_subs(entry):
 
19
    """Removes most of the boilerplate for getting subscriptions given
 
20
    some specific entry or entries in the <body> ... </body> section.
 
21
    """
 
22
    teststring = u"""\
 
23
<?xml version="1.0" encoding="utf-8" ?>
 
24
<!-- OPML generated by Miro v3.1-git on Thu Jul 22 15:23:10 2010 -->
 
25
<opml version="2.0"
 
26
 xmlns:miro="http://getmiro.com/opml/subscriptions">
 
27
<head>
 
28
  <title>miro_subscriptions.opml</title>
 
29
</head>
 
30
<body>
 
31
  %s
 
32
</body>
 
33
</opml>""" % entry
 
34
        
 
35
    return autodiscover.parse_content(teststring)
 
36
 
 
37
class TestImporter(unittest.TestCase):
 
38
    def test_simple_flat(self):
 
39
        teststring = u"""\
 
40
<?xml version="1.0" encoding="utf-8"?>
 
41
<opml version="2.0"
 
42
 xmlns:miro="http://getmiro.com/opml/subscriptions">
 
43
  <head>
 
44
    <title>Sample OPML Flat Subscription List</title>
 
45
  </head>
 
46
  <body>
 
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" />
 
51
  </body>
 
52
</opml>
 
53
""" % (URL_1, URL_3, URL_2, URL_4)
 
54
 
 
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)
 
63
 
 
64
    def test_simple_nested(self):
 
65
        teststring = u"""\
 
66
<?xml version="1.0" encoding="utf-8"?>
 
67
<opml version="2.0"
 
68
 xmlns:miro="http://getmiro.com/opml/subscriptions">
 
69
  <head>
 
70
    <title>Sample OPML Flat Subscription List</title>
 
71
  </head>
 
72
  <body>
 
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" />
 
77
      </outline>
 
78
    </outline>
 
79
    <outline text="folder 2">
 
80
      <outline text="folder2-1">
 
81
        <outline text="Sample Dummy RSS Feed 2" type="rss" xmlUrl="%s" />
 
82
      </outline>
 
83
      <outline text="Sample Dummy Atom Feed 2" type="rss" xmlUrl="%s" />
 
84
    </outline>
 
85
  </body>
 
86
</opml>
 
87
""" % (URL_1, URL_3, URL_2, URL_4)
 
88
 
 
89
        subscriptions = autodiscover.parse_content(teststring)
 
90
        self.assertEquals(len(subscriptions), 4)
 
91
        for feed in subscriptions:
 
92
            self.assertEquals(feed['type'], 'feed')
 
93
 
 
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)
 
98
 
 
99
    def test_basic_feed(self):
 
100
        subs = _get_subs("""\
 
101
  <outline type="rss"
 
102
    text="GeekBeat.TV (Large MP4)"
 
103
    xmlUrl="http://revision3.com/geekbeattv/feed/MP4-Large"
 
104
    miro:section="video" />
 
105
""")
 
106
        feed = subs[0]
 
107
 
 
108
        self.assertEquals(feed['type'], 'feed')
 
109
        self.assertEquals(
 
110
            feed['url'], u"http://revision3.com/geekbeattv/feed/MP4-Large")
 
111
        self.assertEquals(feed['section'], u"video")
 
112
        self.assertEquals(
 
113
            feed['title'], u"GeekBeat.TV (Large MP4)")
 
114
        
 
115
    def test_basic_feed_2(self):
 
116
        subs = _get_subs("""\
 
117
  <outline type="rss"
 
118
    text="The Economist: All video"
 
119
    xmlUrl="http://feeds2.feedburner.com/feedroom/xDDO"
 
120
    miro:section="video"
 
121
    miro:autoDownload="off"/>  
 
122
""")
 
123
        feed = subs[0]
 
124
 
 
125
        self.assertEquals(feed['type'], 'feed')
 
126
        self.assertEquals(
 
127
            feed['url'], u"http://feeds2.feedburner.com/feedroom/xDDO")
 
128
        self.assertEquals(feed['section'], u"video")
 
129
        self.assertEquals(
 
130
            feed['title'], u"The Economist: All video")
 
131
        self.assertEquals(
 
132
            feed["auto_download_mode"], u"off")
 
133
 
 
134
    def test_url(self):
 
135
        # if there's no url, there shouldn't be a subscription
 
136
        subs = _get_subs("""\
 
137
  <outline type="rss" />  
 
138
""")
 
139
        self.assert_(len(subs) == 0)
 
140
 
 
141
        # if there's a url, we pick it up
 
142
        subs = _get_subs("""\
 
143
  <outline type="rss"
 
144
    xmlUrl="http://example.com/feed/"/>
 
145
""")
 
146
        self.assertEquals(subs[0]["url"], u"http://example.com/feed/")
 
147
 
 
148
    def test_title(self):
 
149
        # if there's no title, then the sub won't have a title key
 
150
        subs = _get_subs("""\
 
151
  <outline type="rss"
 
152
    xmlUrl="http://feeds2.feedburner.com/feedroom/xDDO"
 
153
    miro:section="video"
 
154
    miro:autoDownload="off"/>  
 
155
""")
 
156
        self.assert_("title" not in subs[0])
 
157
 
 
158
        # if there's no title, then the sub won't have a title key
 
159
        subs = _get_subs("""\
 
160
  <outline type="rss"
 
161
    xmlUrl="http://feeds2.feedburner.com/feedroom/xDDO"
 
162
    text=""
 
163
    miro:section="video"
 
164
    miro:autoDownload="off"/>  
 
165
""")
 
166
        self.assert_("title" not in subs[0])
 
167
 
 
168
        # if title == url, then the sub won't have a title key
 
169
        subs = _get_subs("""\
 
170
  <outline type="rss"
 
171
    xmlUrl="http://feeds2.feedburner.com/feedroom/xDDO"
 
172
    text="http://feeds2.feedburner.com/feedroom/xDDO"
 
173
    miro:section="video"
 
174
    miro:autoDownload="off"/>  
 
175
""")
 
176
        self.assert_("title" not in subs[0])
 
177
 
 
178
    def test_section(self):
 
179
        # if there's no section, there won't be a section key
 
180
        subs = _get_subs("""\
 
181
  <outline type="rss"
 
182
    xmlUrl="http://feeds2.feedburner.com/feedroom/xDDO"
 
183
    miro:autoDownload="off"/>  
 
184
""")
 
185
        self.assert_("section" not in subs[0])
 
186
 
 
187
        # if the section isn't "audio" or "video", there won't be
 
188
        # a section key
 
189
        subs = _get_subs("""\
 
190
  <outline type="rss"
 
191
    xmlUrl="http://feeds2.feedburner.com/feedroom/xDDO"
 
192
    miro:section="foo"
 
193
    miro:autoDownload="off"/>  
 
194
""")
 
195
        self.assert_("section" not in subs[0])
 
196
        
 
197
    def test_auto_download(self):
 
198
        # if there's no autodownload, then there's no key
 
199
        subs = _get_subs("""\
 
200
  <outline type="rss"
 
201
    xmlUrl="http://feeds2.feedburner.com/feedroom/xDDO"/>
 
202
""")
 
203
        self.assert_("auto_download_mode" not in subs[0])
 
204
 
 
205
        # autodownload can be autoDownload
 
206
        subs = _get_subs("""\
 
207
  <outline type="rss"
 
208
    xmlUrl="http://feeds2.feedburner.com/feedroom/xDDO"
 
209
    autoDownload="all"/>
 
210
""")
 
211
        self.assertEquals(subs[0]["auto_download_mode"], "all")
 
212
 
 
213
        # autodownload can be miro:autoDownload
 
214
        subs = _get_subs("""\
 
215
  <outline type="rss"
 
216
    xmlUrl="http://feeds2.feedburner.com/feedroom/xDDO"
 
217
    miro:autoDownload="all"/>
 
218
""")
 
219
        self.assertEquals(subs[0]["auto_download_mode"], "all")
 
220
 
 
221
        # must be either "all", "off", or "new"
 
222
        subs = _get_subs("""\
 
223
  <outline type="rss"
 
224
    xmlUrl="http://feeds2.feedburner.com/feedroom/xDDO"
 
225
    miro:autoDownload="foo"/>
 
226
""")
 
227
        self.assert_("auto_download_mode" not in subs[0])
 
228
 
 
229
    def test_expiry_time(self):
 
230
        # if there's no expiryTime, then there's no key
 
231
        subs = _get_subs("""\
 
232
  <outline type="rss"
 
233
    xmlUrl="http://feeds2.feedburner.com/feedroom/xDDO"/>
 
234
""")
 
235
        self.assert_("expiry_time" not in subs[0])
 
236
 
 
237
        # expiry_time can be expiryTime
 
238
        subs = _get_subs("""\
 
239
  <outline type="rss"
 
240
    xmlUrl="http://feeds2.feedburner.com/feedroom/xDDO"
 
241
    expiryTime="240"/>
 
242
""")
 
243
        self.assertEquals(subs[0]["expiry_time"], 240)
 
244
 
 
245
        # expiry_time can be miro:expiryTime
 
246
        subs = _get_subs("""\
 
247
  <outline type="rss"
 
248
    xmlUrl="http://feeds2.feedburner.com/feedroom/xDDO"
 
249
    miro:expiryTime="240"/>
 
250
""")
 
251
        self.assertEquals(subs[0]["expiry_time"], 240)
 
252
 
 
253
        # expiry_time can be int or "never" or "system"
 
254
        subs = _get_subs("""\
 
255
  <outline type="rss"
 
256
    xmlUrl="http://feeds2.feedburner.com/feedroom/xDDO"
 
257
    miro:expiryTime="never"/>
 
258
""")
 
259
        self.assertEquals(subs[0]["expiry_time"], "never")
 
260
 
 
261
        subs = _get_subs("""\
 
262
  <outline type="rss"
 
263
    xmlUrl="http://feeds2.feedburner.com/feedroom/xDDO"
 
264
    miro:expiryTime="system"/>
 
265
""")
 
266
        self.assertEquals(subs[0]["expiry_time"], "system")
 
267
 
 
268
        subs = _get_subs("""\
 
269
  <outline type="rss"
 
270
    xmlUrl="http://feeds2.feedburner.com/feedroom/xDDO"
 
271
    miro:expiryTime="foo"/>
 
272
""")
 
273
        self.assert_("expiry_time" not in subs[0])
 
274
 
 
275
    # FIXME - test folders
 
276
    # FIXME - test sites
 
277
 
 
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)
 
282
 
 
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/",
 
287
                             feed1,
 
288
                             u"Foo feed"))
 
289
            
 
290
        data = self._get_export([feed1], [])
 
291
 
 
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")
 
296
 
 
297
    # FIXME - add more export tests
 
298
    # FIXME - test folders
 
299
    # FIXME - test sites