예제 #1
0
 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)
예제 #2
0
파일: tests.py 프로젝트: mkcode/lernanta
 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)
예제 #3
0
파일: models.py 프로젝트: p2pu/lernanta
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))
예제 #4
0
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))