tenkan/tests/processing_test.py

46 lines
1.1 KiB
Python
Raw Permalink Normal View History

2022-01-12 21:31:56 +01:00
# -*- coding: utf-8 -*-
from json import JSONDecodeError
from pathlib import Path
import feedparser
import pytest
from tenkan.config import load_config
from tenkan.processing import fetch_feeds, process_fetched_feeds
data = [
{
'title': 'bla',
'url': 'bla',
'fetched_content': None,
'last_update': None,
'gmi_url': 'bla',
'json_hash_last_update': 'bli',
'fetched_hash_last_update': 'bli',
}
]
def test_feed_fetched():
feeds = Path('./tests/data/feeds.json')
res = fetch_feeds(feeds_file=feeds, gmi_url='blbl')
assert type(res) is list
assert len(res) == 1
def test_feed_raise_when_shitty_feedfile():
feeds = Path('./tests/data/feeds.json_fail')
with pytest.raises(JSONDecodeError):
fetch_feeds(feeds_file=feeds, gmi_url='blbl')
def test_feed_processed():
config_file = Path('./tests/data/tenkan.conf')
conf = load_config(config_file)
data[0]['fetched_content'] = feedparser.parse(
'https://srad.jp/science.rss'
)
process_fetched_feeds(config=conf, fetched_feeds=data)