Exemple #1
0
    def test_update_with_changed_hub_and_self(self):
        update_data = """<?xml version="1.0"?>
<atom:feed>
  <!-- Normally here would be source, title, etc ... -->

  <link rel="hub" href="http://myhub.example.com/endpoint" />
  <link rel="self" href="http://publisher.example.com/happycats.xml" />
  <updated>2008-08-11T02:15:01Z</updated>

  <entry>
    <title>Heathcliff</title>
    <link href="http://publisher.example.com/happycat25.xml" />
    <id>http://publisher.example.com/happycat25.xml</id>
    <updated>2008-08-11T02:15:01Z</updated>
    <content>
      What a happy cat. Full content goes here.
    </content>
  </entry>
</atom:feed>
"""
        sub, _ = Subscription.objects.get_or_create(
            hub="hub",
            topic="topic",
            lease_expires=datetime.now() + timedelta(days=1))

        callback_data = []
        updated.connect(
            lambda sender=None, update=None, **kwargs: callback_data.append(
                (sender, update)),
            weak=False)

        self.responses.append(MockResponse(204))

        response = self.client.post(reverse('pubsubhubbub_callback',
                                            args=(sub.pk,)),
                                    update_data, 'application/atom+xml')
        self.assertEquals(response.status_code, 200)
        self.assertEquals(
            Subscription.objects.filter(
                hub='http://myhub.example.com/endpoint',
                topic='http://publisher.example.com/happycats.xml',
            ).count(), 1)
        self.assertEquals(len(self.requests), 1)
        self.assertEquals(self.requests[0][0],
                          'http://myhub.example.com/endpoint')
        callback_url = urlparse.urljoin(
            'http://testserver',
            reverse('pubsubhubbub_callback', args=(sub.pk,)),
        )
        self.assertEquals(self.requests[0][1]['callback'], callback_url)
        self.assert_((self.requests[0][1]['lease_seconds'] - 86400) < 5)
Exemple #2
0
    def test_update_with_changed_hub_and_self(self):
        update_data = """<?xml version="1.0"?>
<atom:feed>
  <!-- Normally here would be source, title, etc ... -->

  <link rel="hub" href="http://myhub.example.com/endpoint" />
  <link rel="self" href="http://publisher.example.com/happycats.xml" />
  <updated>2008-08-11T02:15:01Z</updated>

  <entry>
    <title>Heathcliff</title>
    <link href="http://publisher.example.com/happycat25.xml" />
    <id>http://publisher.example.com/happycat25.xml</id>
    <updated>2008-08-11T02:15:01Z</updated>
    <content>
      What a happy cat. Full content goes here.
    </content>
  </entry>
</atom:feed>
"""
        sub = Subscription.objects.create(hub="hub",
                                          topic="topic",
                                          lease_expires=datetime.now() +
                                          timedelta(days=1))

        callback_data = []
        updated.connect(
            lambda sender=None, update=None, **kwargs: callback_data.append(
                (sender, update)),
            weak=False)

        self.responses.append(MockResponse(204))

        response = self.client.post(
            reverse('pubsubhubbub_callback', args=(sub.pk, )), update_data,
            'application/atom+xml')
        self.assertEquals(response.status_code, 200)
        self.assertEquals(
            Subscription.objects.filter(
                hub='http://myhub.example.com/endpoint',
                topic='http://publisher.example.com/happycats.xml',
                verified=True).count(), 1)
        self.assertEquals(len(self.requests), 1)
        self.assertEquals(self.requests[0][0],
                          'http://myhub.example.com/endpoint')
        self.assertEquals(self.requests[0][1]['callback'],
                          'http://testserver/1/')
        self.assert_((self.requests[0][1]['lease_seconds'] - 86400) < 5)
Exemple #3
0
import requests
from djpubsubhubbub.signals import updated

from .models import Feed, FeedEntry


def update_handler(sender, update, **kwargs):
    """
    Process new content being provided from SuperFeedr

    """

    feeds = Feed.objects.filter(feed_url=sender.topic)

    for feed in feeds:
        for entry in update.entries:
            r = requests.get(entry['link'])
            feed_entry, created = FeedEntry.objects.get_or_create(
                link=r.url,
                feed=feed,
                defaults={
                    'title': entry['title'],
                    'summary': entry['summary']
                }
            )

            if created:
                feed_entry.add_to_kipt()

updated.connect(update_handler, dispatch_uid='superfeedr')
Exemple #4
0
    def test_update(self):
        # this data comes from
        # http://pubsubhubbub.googlecode.com/svn/trunk/pubsubhubbub-core-0.1.html#anchor3
        update_data = """<?xml version="1.0"?>
<atom:feed>
  <!-- Normally here would be source, title, etc ... -->

  <link rel="hub" href="http://myhub.example.com/endpoint" />
  <link rel="self" href="http://publisher.example.com/happycats.xml" />
  <updated>2008-08-11T02:15:01Z</updated>

  <!-- Example of a full entry. -->
  <entry>
    <title>Heathcliff</title>
    <link href="http://publisher.example.com/happycat25.xml" />
    <id>http://publisher.example.com/happycat25.xml</id>
    <updated>2008-08-11T02:15:01Z</updated>
    <content>
      What a happy cat. Full content goes here.
    </content>
  </entry>

  <!-- Example of an entity that isn't full/is truncated. This is implied
       by the lack of a <content> element and a <summary> element instead. -->
  <entry >
    <title>Heathcliff</title>
    <link href="http://publisher.example.com/happycat25.xml" />
    <id>http://publisher.example.com/happycat25.xml</id>
    <updated>2008-08-11T02:15:01Z</updated>
    <summary>
      What a happy cat!
    </summary>
  </entry>

  <!-- Meta-data only; implied by the lack of <content> and
       <summary> elements. -->
  <entry>
    <title>Garfield</title>
    <link rel="alternate" href="http://publisher.example.com/happycat24.xml" />
    <id>http://publisher.example.com/happycat25.xml</id>
    <updated>2008-08-11T02:15:01Z</updated>
  </entry>

  <!-- Context entry that's meta-data only and not new. Implied because the
       update time on this entry is before the //atom:feed/updated time. -->
  <entry>
    <title>Nermal</title>
    <link rel="alternate" href="http://publisher.example.com/happycat23s.xml" />
    <id>http://publisher.example.com/happycat25.xml</id>
    <updated>2008-07-10T12:28:13Z</updated>
  </entry>

</atom:feed>
"""

        sub = Subscription.objects.create(
            hub="http://myhub.example.com/endpoint",
            topic="http://publisher.example.com/happycats.xml")

        callback_data = []
        updated.connect(
            lambda sender=None, update=None, **kwargs: callback_data.append(
                (sender, update)),
            weak=False)

        response = self.client.post(reverse('pubsubhubbub_callback',
                                            args=(sub.pk,)),
                                    update_data, 'application/atom+xml')
        self.assertEquals(response.status_code, 200)

        self.assertEquals(len(callback_data), 1)
        sender, update = callback_data[0]
        self.assertEquals(sender, sub)
        self.assertEquals(len(update.entries), 4)
        self.assertEquals(update.entries[0].id,
                          'http://publisher.example.com/happycat25.xml')
        self.assertEquals(update.entries[1].id,
                          'http://publisher.example.com/happycat25.xml')
        self.assertEquals(update.entries[2].id,
                          'http://publisher.example.com/happycat25.xml')
        self.assertEquals(update.entries[3].id,
                          'http://publisher.example.com/happycat25.xml')
Exemple #5
0
    def test_update(self):
        # this data comes from
        # http://pubsubhubbub.googlecode.com/svn/trunk/pubsubhubbub-core-0.1.html#anchor3
        update_data = """<?xml version="1.0"?>
<atom:feed>
  <!-- Normally here would be source, title, etc ... -->

  <link rel="hub" href="http://myhub.example.com/endpoint" />
  <link rel="self" href="http://publisher.example.com/happycats.xml" />
  <updated>2008-08-11T02:15:01Z</updated>

  <!-- Example of a full entry. -->
  <entry>
    <title>Heathcliff</title>
    <link href="http://publisher.example.com/happycat25.xml" />
    <id>http://publisher.example.com/happycat25.xml</id>
    <updated>2008-08-11T02:15:01Z</updated>
    <content>
      What a happy cat. Full content goes here.
    </content>
  </entry>

  <!-- Example of an entity that isn't full/is truncated. This is implied
       by the lack of a <content> element and a <summary> element instead. -->
  <entry >
    <title>Heathcliff</title>
    <link href="http://publisher.example.com/happycat25.xml" />
    <id>http://publisher.example.com/happycat25.xml</id>
    <updated>2008-08-11T02:15:01Z</updated>
    <summary>
      What a happy cat!
    </summary>
  </entry>

  <!-- Meta-data only; implied by the lack of <content> and
       <summary> elements. -->
  <entry>
    <title>Garfield</title>
    <link rel="alternate" href="http://publisher.example.com/happycat24.xml" />
    <id>http://publisher.example.com/happycat25.xml</id>
    <updated>2008-08-11T02:15:01Z</updated>
  </entry>

  <!-- Context entry that's meta-data only and not new. Implied because the
       update time on this entry is before the //atom:feed/updated time. -->
  <entry>
    <title>Nermal</title>
    <link rel="alternate" href="http://publisher.example.com/happycat23s.xml" />
    <id>http://publisher.example.com/happycat25.xml</id>
    <updated>2008-07-10T12:28:13Z</updated>
  </entry>

</atom:feed>
"""

        sub = Subscription.objects.create(
            hub="http://myhub.example.com/endpoint",
            topic="http://publisher.example.com/happycats.xml")

        callback_data = []
        updated.connect(
            lambda sender=None, update=None, **kwargs: callback_data.append(
                (sender, update)),
            weak=False)

        response = self.client.post(
            reverse('pubsubhubbub_callback', args=(sub.pk, )), update_data,
            'application/atom+xml')
        self.assertEquals(response.status_code, 200)

        self.assertEquals(len(callback_data), 1)
        sender, update = callback_data[0]
        self.assertEquals(sender, sub)
        self.assertEquals(len(update.entries), 4)
        self.assertEquals(update.entries[0].id,
                          'http://publisher.example.com/happycat25.xml')
        self.assertEquals(update.entries[1].id,
                          'http://publisher.example.com/happycat25.xml')
        self.assertEquals(update.entries[2].id,
                          'http://publisher.example.com/happycat25.xml')
        self.assertEquals(update.entries[3].id,
                          'http://publisher.example.com/happycat25.xml')