102 lines
2.6 KiB
Python
102 lines
2.6 KiB
Python
|
# -*- coding: utf-8 -*-
|
||
|
from datetime import datetime, timezone
|
||
|
|
||
|
import pytest
|
||
|
|
||
|
from tenkan.feed import Feed
|
||
|
|
||
|
data = {
|
||
|
'title': 'bla',
|
||
|
'url': 'bla',
|
||
|
'fetched_content': 'bla',
|
||
|
'last_update': None,
|
||
|
'gmi_url': 'bla',
|
||
|
'json_hash_last_update': 'bl',
|
||
|
'fetched_hash_last_update': 'bla',
|
||
|
}
|
||
|
|
||
|
article_data1 = {
|
||
|
'title': 'article_title',
|
||
|
'article_formatted_title': 'article_formatted_title',
|
||
|
'article_content': {'summary': 'article_content'},
|
||
|
'article_date': datetime(2022, 1, 7, 15, 25, 0, tzinfo=timezone.utc),
|
||
|
'http_url': 'article_link',
|
||
|
'updated': 'Fri, 07 Jan 2022 15:25:00 +0000',
|
||
|
'updated_parsed': datetime(
|
||
|
2022, 1, 7, 15, 25, 0, tzinfo=timezone.utc
|
||
|
).timetuple(),
|
||
|
}
|
||
|
|
||
|
article_data2 = {
|
||
|
'title': 'article_title',
|
||
|
'article_formatted_title': 'article_formatted_title',
|
||
|
'article_content': {'summary': 'article_content'},
|
||
|
'article_date': 'bad_date',
|
||
|
'http_url': 'article_link',
|
||
|
'updated_': 'bad_date',
|
||
|
}
|
||
|
|
||
|
|
||
|
def test_needs_update_no_last_update():
|
||
|
data['json_hash_last_update'] = None
|
||
|
feed = Feed(input_content=data)
|
||
|
assert feed.needs_update() is True
|
||
|
|
||
|
|
||
|
def test_needs_update_last_update_ne_updated_field():
|
||
|
feed = Feed(input_content=data)
|
||
|
assert feed.needs_update() is True
|
||
|
|
||
|
|
||
|
def test_no_need_update():
|
||
|
data['json_hash_last_update'] = 'bla'
|
||
|
feed = Feed(input_content=data)
|
||
|
assert feed.needs_update() is False
|
||
|
|
||
|
|
||
|
def test_content_exported():
|
||
|
# TODO : use article_data
|
||
|
feed = Feed(input_content=data)
|
||
|
|
||
|
expected_data = {
|
||
|
'title': 'bla',
|
||
|
'last_update': None,
|
||
|
'gmi_url': 'bla',
|
||
|
'articles': [],
|
||
|
'hash_last_update': 'bla',
|
||
|
}
|
||
|
|
||
|
assert feed.export_content() == expected_data
|
||
|
|
||
|
|
||
|
def test_date_format_published():
|
||
|
data['articles'] = article_data1
|
||
|
feed = Feed(input_content=data)
|
||
|
assert (
|
||
|
feed._get_article_date(article_data1)
|
||
|
== data['articles']['article_date']
|
||
|
)
|
||
|
|
||
|
|
||
|
def test_bad_date_format():
|
||
|
data['articles'] = article_data2
|
||
|
feed = Feed(input_content=data)
|
||
|
with pytest.raises(SystemExit) as pytest_wrapped_e:
|
||
|
feed._get_article_date(article_data2)
|
||
|
assert pytest_wrapped_e.type == SystemExit
|
||
|
assert pytest_wrapped_e.value.code == 1
|
||
|
|
||
|
|
||
|
def test_article_content_formatted():
|
||
|
feed = Feed(input_content=data, formatting={'truncated_feeds': 'rien'})
|
||
|
res = feed._format_article_content(content='coucou', link='blbl')
|
||
|
assert res == 'coucou'
|
||
|
|
||
|
|
||
|
def test_title_formatted():
|
||
|
feed = Feed(input_content=data, formatting={'title_size': 10})
|
||
|
art = article_data1
|
||
|
art['title'] = 'blabla / bla ?'
|
||
|
res = feed._format_article_title(article=article_data1)
|
||
|
assert res == 'blabla-'
|