Пример #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
Пример #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, update_feed_subscription, parse, AtomEntry
    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 AtomEntry.view(mb, Message.by_timestamp, include_docs=True, reduce=False):
        seen_ids.append(ni.entry_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
Пример #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, update_feed_subscription, parse, AtomEntry
    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 AtomEntry.view(mb, Message.by_timestamp,
                                 include_docs=True, reduce=False):
        seen_ids.append(ni.entry_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 AtomEntry.view(mb, Message.by_timestamp,
                             include_docs=True, reduce=False):
        seen_ids.append(ni.entry_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
Пример #4
0
def test_feed_delete_sticks():
    """
    make sure that an item deleted from a mailbox does not 
    reappear if it still exists in the source feed.
    """
    from radarpost.feed import FeedSubscription, update_feed_subscription, parse, AtomEntry
    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 = []
    news_items = []
    for ni in AtomEntry.view(mb, Message.by_timestamp,
                             include_docs=True, reduce=False):
        seen_ids.append(ni.entry_id)
        news_items.append(ni)

    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


    # delete one of the items
    killed_item = news_items[0]
    del mb[killed_item.id]
    assert killed_item.id not in mb

    # update with the same info
    update_feed_subscription(mb, sub, feed)
    # item should not have reappeared
    assert killed_item.id not in mb

    # now update with the whole set of items
    feed = parse(feed_doc2, url)
    update_feed_subscription(mb, sub, feed)
    
    # item should not have reappeared.
    assert killed_item.id not in mb


    # check that all other expected 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 AtomEntry.view(mb, Message.by_timestamp,
                             include_docs=True, reduce=False):
        seen_ids.append(ni.entry_id)

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