Esempio n. 1
0
    def test_atom_feed_entries_ordered(self):
        from datetime import datetime, timedelta
        from radarpost.feed import parse as parse_feed, BasicNewsItem, \
            FeedSubscription, create_basic_news_item
        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 = BasicNewsItem(
                fingerprint = item_id,
                item_id = item_id,
                timestamp = base_date + i*delta,
                title = 'Test Item %d' % i,
                author = 'Joe',
                link = '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_basic_news_item(ff.entries[i], ff, fake_sub)
            #assert ent.item_id == item.item_id
            assert ent.timestamp == item.timestamp
            assert ent.author == item.author
            assert ent.link == item.link
            assert ent.content == item.content
Esempio n. 2
0
def test_feed_basic():
    """
    test_feed_basic

    create a mailbox
    subscribe to a feed
    update the subscription
    assert expected items are in the mailbox
    """
    from radarpost.feed import FeedSubscription, BasicNewsItem, update_feed_subscription, parse
    from radarpost.mailbox import Message


    # create a random feed
    ff, entries = random_feed_info_and_entries(10)
    feed_doc = create_atom_feed(ff, entries)
    url = ff['url']

    # create a mailbox 
    mb = create_test_mailbox()
    # make sure there are no items in the mailbox
    count = 0
    for r in mb.view(Message.by_timestamp, group=False):
        count += r.value
    assert count == 0

    # subscribe to our feed and update the subscription  
    sub = FeedSubscription(url=url)
    sub.store(mb)
    feed = parse(feed_doc, url)
    update_feed_subscription(mb, sub, feed)

    # check that each item in the random feed is in the 
    # mailbox and only items from the random feed are in there.
    seen_ids = []
    for ni in BasicNewsItem.view(mb, Message.by_timestamp, include_docs=True, reduce=False):
        seen_ids.append(ni.item_id)
    
    expected_ids = set([e['id'] for e in entries])
    assert len(seen_ids) == len(entries)
    for iid in seen_ids:
        assert iid in expected_ids
Esempio n. 3
0
def test_feed_update():
    """
    create a mailbox
    subscribe to a feed
    update the subscription
    assert expected items are in the mailbox
    add new items to feed
    update subscription
    assert expected items are in the mailbox
    assert that old items are not repeated
    """
    from radarpost.feed import FeedSubscription, BasicNewsItem, update_feed_subscription, parse
    from radarpost.mailbox import Message

    # create two versions of a random feed.
    # the second version with additional items. 
    ff, entries = random_feed_info_and_entries(20)
    url = ff['url']
    ff1 = dict(ff)
    ff2 = dict(ff)
    entries1 = entries[10:] # last 10 only
    entries2 = entries # all entries
    ff1['timestamp'] = entries2[0]['timestamp']
    feed_doc1 = create_atom_feed(ff1, entries1) 
    feed_doc2 = create_atom_feed(ff2, entries2)

    # create a mailbox 
    mb = create_test_mailbox()
    # make sure there are no items in the mailbox
    count = 0
    for r in mb.view(Message.by_timestamp, group=False):
        count += r.value
    assert count == 0

    # subscribe to our feed and update the subscription  
    sub = FeedSubscription(url=url)
    sub.store(mb)
    
    # update with the first feed (first 10 items only)
    feed = parse(feed_doc1, url)
    update_feed_subscription(mb, sub, feed)

    # check that each item in the feed is in the 
    # mailbox and only items from the feed are in there.
    seen_ids = []
    for ni in BasicNewsItem.view(mb, Message.by_timestamp,
                                 include_docs=True, reduce=False):
        seen_ids.append(ni.item_id)

    expected_ids = set([e['id'] for e in entries1])
    assert len(seen_ids) == len(entries1)
    for iid in seen_ids:
        assert iid in expected_ids

    # now update with the whole set of items
    feed = parse(feed_doc2, url)
    update_feed_subscription(mb, sub, feed)
    
    # check that all items are now in the feed is in the 
    # mailbox and only items from the feed are in there 
    # and they're there exactly once.
    seen_ids = []
    for ni in BasicNewsItem.view(mb, Message.by_timestamp,
                                 include_docs=True, reduce=False):
        seen_ids.append(ni.item_id)

    expected_ids = set([e['id'] for e in entries2])
    assert len(seen_ids) == len(entries2)
    for iid in seen_ids:
        assert iid in expected_ids