コード例 #1
0
def test_parsed_entries_update(feedparser_mock, test_feed, feedparser_data):
    """Parsed info and entries should be inserted in DB, unless they already exist."""
    baker.make("Entry",
               feed=test_feed,
               link=feedparser_data["entries"][0]["link"])
    update_feed(test_feed.id)
    assert test_feed.entry_set.count() == 3
コード例 #2
0
def test_parsing_fail(feedparser_mock, test_feed, feedparser_test_data):
    """
    When parsing fails somehow (failed request or malformed rss), 1 is added to
    a counter for failed_tries.
    """
    feedparser_mock.return_value = feedparser_test_data
    update_feed(test_feed.id)
    test_feed.refresh_from_db()
    assert test_feed.failed_tries == 1
コード例 #3
0
def test_reset_failed_tries(feedparser_mock, feedparser_data):
    """On succesful parse, `failed_tries` counter should be reset."""
    feed = baker.make("Feed", failed_tries=42)
    update_feed(feed.id)
    feed.refresh_from_db()
    assert feed.failed_tries == 0
コード例 #4
0
def test_gone_feed(feedparser_mock, test_feed):
    """When a feed is parsed with 410 status, it should be set as gone"""
    feedparser_mock.return_value = {"status": 410}
    update_feed(test_feed.id)
    test_feed.refresh_from_db()
    assert test_feed.gone is True
コード例 #5
0
def test_feedparser_called(feedparser_mock, test_feed):
    """Feed updating should call feedparser and insert entries in DB"""
    update_feed(test_feed.id)
    feedparser_mock.assert_called_with(test_feed.url)
    assert test_feed.entry_set.count() == 3