Example #1
0
    def test_atom_feed_entries_ordered(self):
        from datetime import datetime, timedelta
        from radarpost.feed import parse as parse_feed, \
            FeedSubscription, create_atom_entry, AtomEntry
        from random import shuffle
        
        c = self.get_test_app()
        slug = self.TEST_MAILBOX_SLUG
        mb = self.create_test_mailbox(slug)
        feed_url = self.url_for('atom_feed', mailbox_slug=slug)

        # there should currently be an empty feed 
        response = c.get(feed_url, status=200)
        ff = parse_feed(response.body, feed_url)
        assert len(ff.entries) == 0
        
        # now put some items in the mailbox 
        # by hand.
        items = []
        base_date = datetime(1999, 12, 29, 0)
        delta = timedelta(seconds=10)
        for i in range(10):
            item_id = 'TestItem%d' % i
            item = AtomEntry(
                fingerprint = item_id,
                entry_id = item_id,
                timestamp = base_date + i*delta,
                title = 'Test Item %d' % i,
                authors = [{'name': 'Joe'}],
                links = [{'href': 'http://www.example.org/%d' % i}],
                content = "Blah Blah %d" % i,
            )
            items.append(item)
        items.reverse() # order from newest to oldest
    
        # store them in a random order
        shuffled = list(items)
        shuffle(shuffled)
        for item in shuffled:
            item.store(mb)
    
        response = c.get(feed_url, status=200)
        ff = parse_feed(response.body, feed_url)
        assert len(ff.entries) == len(items)
        
        fake_sub = FeedSubscription(url=feed_url)
        for i, item in enumerate(items):
            ent = create_atom_entry(ff.entries[i], ff, fake_sub)
            #assert ent.item_id == item.item_id
            assert ent.timestamp == item.timestamp
            assert ent.authors[0].name == item.authors[0].name
            assert ent.links[0].href == item.links[0].href
            assert ent.content == item.content
Example #2
0
    def test_atom_feed_etag(self):

        from datetime import datetime, timedelta
        from radarpost.feed import parse as parse_feed, \
            FeedSubscription, create_atom_entry, AtomEntry
        from random import shuffle
        
        c = self.get_test_app()
        slug = self.TEST_MAILBOX_SLUG
        mb = self.create_test_mailbox(slug)
        feed_url = self.url_for('atom_feed', mailbox_slug=slug)

        # there should currently be an empty feed 
        response = c.get(feed_url, status=200)
        assert 'etag' in response.headers
        etag = response.headers['etag']
        ff = parse_feed(response.body, feed_url)
        assert len(ff.entries) == 0
        
        # should get 304 if we ask with the etag
        c.get(feed_url, headers=[('if-none-match', '"%s"' % etag)], status=304)

        # generate some items
        items = []
        base_date = datetime(1999, 12, 29, 0)
        delta = timedelta(seconds=10)
        for i in range(2):
            item_id = 'TestItem%d' % i
            item = AtomEntry(
                fingerprint = item_id,
                entry_id = item_id,
                timestamp = base_date + i*delta,
                title = 'Test Item %d' % i,
                authors = [{'name': 'Joe'}],
                links = [{'href': 'http://www.example.org/%d' % i}],
                content = "Blah Blah %d" % i,
            )
            items.append(item)
        
        items[0].store(mb)
            
        # the etag should be invalidated and replaced with a new etag
        res = c.get(feed_url, headers=[('if-none-match', '"%s"' % etag)], status=200)
        assert 'etag' in res.headers
        etag = res.headers['etag']
        # should get 304 with new etag
        c.get(feed_url, headers=[('if-none-match', '"%s"' % etag)], status=304)

        # store another item, again the etag should be invalidated and 
        # replaced with a new etag
        items[1].store(mb)
        res = c.get(feed_url, headers=[('if-none-match', '\"%s"' % etag)], status=200)
        assert 'etag' in res.headers
        etag = res.headers['etag']
        # should get 304 with new etag
        c.get(feed_url, headers=[('if-none-match', '"%s"' % etag)], status=304)        
Example #3
0
 def test_atom_feed_exists(self):
     from radarpost.feed import parse as parse_feed
     
     slug = self.TEST_MAILBOX_SLUG
     feed_url = self.url_for('atom_feed', mailbox_slug=slug)
     c = self.get_test_app()
     c.get(feed_url, status=404)
     mb = self.create_test_mailbox(slug)
     response = c.get(feed_url, status=200)
     
     # body should parse as a feed
     ff = parse_feed(response.body, feed_url)
     assert len(ff.entries) == 0