Example #1
0
    def test_update_with_changed_hub_and_self(self):
        update_data = """<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <!-- 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>
</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)

        subscription = Subscription.objects.get(
                hub='http://myhub.example.com/endpoint',
                topic='http://publisher.example.com/happycats.xml')
        self.assertEquals(subscription.hub, 'http://myhub.example.com/endpoint')
        self.assertEquals(subscription.topic, 'http://publisher.example.com/happycats.xml')

        self.assertEquals(len(self.requests), 1)
        self.assertEquals(self.requests[0][0],
                          'http://myhub.example.com/endpoint')
        self.assert_((self.requests[0][1]['lease_seconds'] - 86400) < 5)
Example #2
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"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <!-- 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>

</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')