def test_notification(self): sub = Subscription.objects.create( hub='http://blah/', topic='http://blah') Link.objects.create( name='foo', url='http://blah/', subscription=sub, user=self.user) count = Activity.objects.count() test_feed_data = """<?xml version='1.0'?> <feed xmlns='http://www.w3.org/2005/Atom' xmlns:activity='http://activitystrea.ms/spec/1.0/' xml:lang='en-US'> <link type='text/html' rel='alternate' href='http://example.com'/> <link type='application/atom+xml' rel='self' href='http://example.com/feed/'/> <entry> <activity:verb> http://activitystrea.ms/schema/1.0/follow </activity:verb> <activity:object-type> http://activitystrea.ms/schema/1.0/person </activity:object-type> <link type='text/html' rel='alternate' href='http://example.com/activity/'/> <title>Jane started following John</title> </entry> </feed>""" parsed = feedparser.parse(test_feed_data) handler = HandleNotification() handler.run(parsed, sub) self.assertEqual(Activity.objects.count(), count + 1)
def test_notification(self): sub = Subscription.objects.create(hub='http://blah/', topic='http://blah') Link.objects.create(name='foo', url='http://blah/', subscription=sub, user=self.user) count = Activity.objects.count() test_feed_data = """<?xml version='1.0'?> <feed xmlns='http://www.w3.org/2005/Atom' xmlns:activity='http://activitystrea.ms/spec/1.0/' xml:lang='en-US'> <link type='text/html' rel='alternate' href='http://example.com'/> <link type='application/atom+xml' rel='self' href='http://example.com/feed/'/> <entry> <activity:verb> http://activitystrea.ms/schema/1.0/follow </activity:verb> <activity:object-type> http://activitystrea.ms/schema/1.0/person </activity:object-type> <link type='text/html' rel='alternate' href='http://example.com/activity/'/> <title>Jane started following John</title> </entry> </feed>""" parsed = feedparser.parse(test_feed_data) handler = HandleNotification() handler.run(parsed, sub) self.assertEqual(Activity.objects.count(), count + 1)
def listener(notification, **kwargs): """ Create activity entries when we receive notifications of feed updates from a hub. """ sender = kwargs.get("sender", None) if not sender: return try: msg = "Received feed update notification: %s, sender: %s" log.debug(msg % (notification, sender)) eager_result = HandleNotification.apply_async(args=(notification, sender)) msg = "Result from the feed notification handler: %s, %s" log.debug(msg % (eager_result.status, eager_result.result)) except Exception, ex: log.warn("Unprocessable notification: %s (%s)" % (notification, ex))
def listener(notification, **kwargs): """ Create activity entries when we receive notifications of feed updates from a hub. """ sender = kwargs.get('sender', None) if not sender: return try: msg = 'Received feed update notification: %s, sender: %s' log.debug(msg % (notification, sender)) eager_result = HandleNotification.apply_async(args=(notification, sender)) msg = 'Result from the feed notification handler: %s, %s' log.debug(msg % (eager_result.status, eager_result.result)) except Exception, ex: log.warn("Unprocessable notification: %s (%s)" % (notification, ex))