def test_hub_discovery(self): """Using a google buzz profile, find the atom feed and the hub url.""" html = self.fixtures["buzz_profile.html"] feed_url = utils.parse_feed_url(html) self.assertEqual("https://www.googleapis.com/buzz/v1/activities/115398213828503499359/@public", feed_url) atom = self.fixtures["buzz_profile.atom"] hub_url = utils.parse_hub_url(atom) self.assertEqual("http://pubsubhubbub.appspot.com/", hub_url)
def test_hub_discovery(self): """Using a google buzz profile, find the atom feed and the hub url.""" html = self.fixtures['buzz_profile.html'] feed_url = utils.parse_feed_url(html) self.assertEqual( 'https://www.googleapis.com/buzz/v1/activities/115398213828503499359/@public', feed_url) atom = self.fixtures['buzz_profile.atom'] hub_url = utils.parse_hub_url(atom) self.assertEqual('http://pubsubhubbub.appspot.com/', hub_url)
def test_feed_parser(self): """Perform a straightforward test of the feed url parser.""" html = """ <html> <head> <title>Test HTML</title> <link rel="alternate" type="application/rss+xml" href="http://example.com/rss"> </head> <body> <h1>Test</h1> </body> </html> """ feed_url = utils.parse_feed_url(html) self.assertEqual('http://example.com/rss', feed_url)
def run(self, link, **kwargs): log = self.get_logger(**kwargs) hub_url = None feed_url = None try: log.debug("Attempting feed discovery on %s" % (link.url, )) html = urllib2.urlopen(link.url).read() feed_url = utils.parse_feed_url(html, link.url) log.debug("Found feed URL %s for %s" % (feed_url, link.url)) except: log.warning("Error discovering feed URL for %s. Retrying." % (link.url, )) self.retry([ link, ], kwargs) if not feed_url: return try: log.debug("Attempting hub discovery on %s" % (feed_url, )) feed = urllib2.urlopen(feed_url).read() hub_url = utils.parse_hub_url(feed, feed_url) log.debug("Found hub %s for %s" % (hub_url, feed_url)) except: log.warning("Error discovering hub URL for %s. Retrying." % (feed_url, )) self.retry([ link, ], kwargs) try: hub = hub_url or settings.SUPERFEEDR_URL log.debug("Attempting subscription of topic %s with hub %s" % (feed_url, hub)) subscription = Subscription.objects.subscribe(feed_url, hub=hub) log.info("Created subscription with callback url: %s" % (subscription.callback_url, )) except SubscriptionError, e: log.warning("SubscriptionError. Retrying (%s)" % (link.url, )) log.warning("Error: %s" % (str(e), )) self.retry([ link, ], kwargs)
def test_preference_of_atom(self): """Test that provided with RSS and Atom feeds, Atom comes out.""" html = """ <html> <head> <title>Test</title> <link rel="alternate" type="application/rss+xml" href="http://foo.com/rss" /> <link rel="alternate" type="application/rss+xml" href="http://foo.com/comments/rss" /> <link rel="alternate" type="application/atom+xml" href="http://foo.com/atom" /> <link rel="alternate" type="application/atom+xml" href="http://foo.com/comments/atom" /> </head> </html> """ feed_url = utils.parse_feed_url(html) self.assertEqual('http://foo.com/atom', feed_url)
def run(self, link, **kwargs): log = self.get_logger(**kwargs) hub_url = None feed_url = None try: log.debug("Attempting feed discovery on %s" % (link.url,)) html = urllib2.urlopen(link.url).read() feed_url = utils.parse_feed_url(html, link.url) log.debug("Found feed URL %s for %s" % (feed_url, link.url)) except: log.warning("Error discoverying feed URL for %s. Retrying." % ( link.url,)) self.retry([link, ], kwargs) if not feed_url: return try: log.debug("Attempting hub discovery on %s" % (feed_url,)) feed = urllib2.urlopen(feed_url).read() hub_url = utils.parse_hub_url(feed, feed_url) log.debug("Found hub %s for %s" % (hub_url, feed_url)) except: log.warning("Error discoverying hub URL for %s. Retrying." % ( feed_url,)) self.retry([link, ], kwargs) try: hub = hub_url or settings.SUPERFEEDR_URL log.debug("Attempting subscription of topic %s with hub %s" % ( feed_url, hub)) subscription = Subscription.objects.subscribe(feed_url, hub=hub) log.info("Created subscription with callback url: %s" % ( subscription.callback_url,)) except SubscriptionError, e: log.warning("SubscriptionError. Retrying (%s)" % (link.url,)) log.warning("Error: %s" % (str(e),)) self.retry([link, ], kwargs)
def test_invalid_markup(self): """Test that parsing invalid markup works.""" html = """<html><head><link rel="alternate" type="application/atom+xml" href="http://foo.com/atom"><body></html>""" feed_url = utils.parse_feed_url(html) self.assertEqual('http://foo.com/atom', feed_url)
def test_feed_parser_multiple_alternates(self): """Test that given HTML with multiple feeds, the first is returned.""" html = self.fixtures['selfhosted_wp_blog.html'] feed_url = utils.parse_feed_url(html) self.assertEqual('http://blog.eval.ca/feed/', feed_url)