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 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 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_hub_parser_no_hub(self): """Test that an rss feed with no hub declaration is returned as None""" rss = self.fixtures['rss_no_hub.rss'] hub_url = utils.parse_hub_url(rss) self.assertEqual(None, hub_url)
def test_hub_parser(self): """Test that we find a hub for a sample hosted WP rss feed.""" rss = self.fixtures['rss_hub.rss'] hub_url = utils.parse_hub_url(rss) self.assertEqual('http://commonspace.wordpress.com/?pushpress=hub', hub_url)