def test_invalid_subscriptions(self): retval = autodiscover.parse_file("this-file-does-not-exist.xml") self.assertEquals(retval, None) retval = autodiscover.parse_content(INVALID_CONTENT_1) self.assertEquals(retval, None) retval = autodiscover.parse_content(INVALID_CONTENT_2) self.assertEquals(retval, None)
def test_simple_nested(self): teststring = u"""\ <?xml version="1.0" encoding="utf-8"?> <opml version="2.0" xmlns:miro="http://getmiro.com/opml/subscriptions"> <head> <title>Sample OPML Flat Subscription List</title> </head> <body> <outline text="folder 1"> <outline text="Sample Dummy RSS Feed 1" type="rss" xmlUrl="%s" /> <outline text="folder1-1"> <outline text="Sample Dummy Atom Feed 1" type="rss" xmlUrl="%s" /> </outline> </outline> <outline text="folder 2"> <outline text="folder2-1"> <outline text="Sample Dummy RSS Feed 2" type="rss" xmlUrl="%s" /> </outline> <outline text="Sample Dummy Atom Feed 2" type="rss" xmlUrl="%s" /> </outline> </body> </opml> """ % (URL_1, URL_3, URL_2, URL_4) subscriptions = autodiscover.parse_content(teststring) self.assertEquals(len(subscriptions), 4) for feed_ in subscriptions: self.assertEquals(feed_['type'], 'feed') self.assertEquals(subscriptions[0]['url'], URL_1) self.assertEquals(subscriptions[1]['url'], URL_3) self.assertEquals(subscriptions[2]['url'], URL_2) self.assertEquals(subscriptions[3]['url'], URL_4)
def test_reflexive_auto_discovery_in_atom(self): pageFile = file(REFLEXIVE_AUTO_DISCOVERY_PAGE_ATOM_FILENAME, "w") pageFile.write(REFLEXIVE_AUTO_DISCOVERY_PAGE_ATOM) pageFile.close() subscriptions = autodiscover.parse_content(REFLEXIVE_AUTO_DISCOVERY_IN_ATOM) try: self.assertDiscovered(subscriptions, SAMPLE_ATOM_SUBSCRIPTION_URL_1) finally: os.remove(REFLEXIVE_AUTO_DISCOVERY_PAGE_ATOM_FILENAME)
def test_reflexive_auto_discovery_in_rss(self): pageFile = file(REFLEXIVE_AUTO_DISCOVERY_PAGE_RSS_FILENAME, "w") pageFile.write(REFLEXIVE_AUTO_DISCOVERY_PAGE_RSS) pageFile.close() subscriptions = autodiscover.parse_content( REFLEXIVE_AUTO_DISCOVERY_IN_RSS) try: self.assertDiscovered(subscriptions, SAMPLE_RSS_SUBSCRIPTION_URL_1) finally: os.remove(REFLEXIVE_AUTO_DISCOVERY_PAGE_RSS_FILENAME)
def test_simple(self): feed1 = feed.Feed(u"http://example.com/feed/") feed1.finish_generate_feed( feed.RSSFeedImpl(u"http://example.com/feed/", feed1, u"Foo feed")) data = self._get_export([feed1], []) subs = autodiscover.parse_content(data) self.assertEquals(subs[0]["url"], u"http://example.com/feed/") self.assertEquals(subs[0]["title"], u"Foo feed") self.assertEquals(subs[0]["type"], "feed")
def _get_subs(entry): """Removes most of the boilerplate for getting subscriptions given some specific entry or entries in the <body> ... </body> section. """ teststring = u"""\ <?xml version="1.0" encoding="utf-8" ?> <!-- OPML generated by Miro v3.1-git on Thu Jul 22 15:23:10 2010 --> <opml version="2.0" xmlns:miro="http://getmiro.com/opml/subscriptions"> <head> <title>miro_subscriptions.opml</title> </head> <body> %s </body> </opml>""" % entry return autodiscover.parse_content(teststring)
def callback(info): if info.get('content-type') == expected_content_type: subscription_list = autodiscover.parse_content(info['body']) if subscription_list is None: text = _( "This %(appname)s podcast file has an invalid format: " "%(url)s. Please notify the publisher of this file.", { "appname": app.config.get(prefs.SHORT_APP_NAME), "url": real_url }) _complain_about_subscription_url(text) else: subscription.Subscriber().add_subscriptions(subscription_list) else: text = _( "This %(appname)s podcast file has the wrong content type: " "%(url)s. Please notify the publisher of this file.", { "appname": app.config.get(prefs.SHORT_APP_NAME), "url": real_url }) _complain_about_subscription_url(text)
def callback(info): if info.get('content-type') == expected_content_type: subscription_list = autodiscover.parse_content(info['body']) if subscription_list is None: text = _( "This %(appname)s podcast file has an invalid format: " "%(url)s. Please notify the publisher of this file.", {"appname": app.config.get(prefs.SHORT_APP_NAME), "url": real_url} ) _complain_about_subscription_url(text) else: subscription.Subscriber().add_subscriptions( subscription_list) else: text = _( "This %(appname)s podcast file has the wrong content type: " "%(url)s. Please notify the publisher of this file.", {"appname": app.config.get(prefs.SHORT_APP_NAME), "url": real_url} ) _complain_about_subscription_url(text)
def test_atom_link_construct_in_atom(self): subscriptions = autodiscover.parse_content(ATOM_LINK_CONSTRUCT_IN_ATOM) self.assertDiscovered(subscriptions, SAMPLE_ATOM_SUBSCRIPTION_URL_1)
def test_parse_content_garbage(self): retval = autodiscover.parse_content("") self.assertEquals(retval, None) retval = autodiscover.parse_content(1) self.assertEquals(retval, None)