fix timezone in test (#145)
* added timezone fixture * Make output dependent on local timezone. * Fix non deterministic behavior in html to text conversion. Co-authored-by: Giacomo Leidi <goodoldpaul@autistici.org>
This commit is contained in:
parent
e003cf9a90
commit
bda4b8ee0d
|
@ -28,7 +28,9 @@ def show_events(events: Iterable[MobilizonEvent]):
|
|||
def pretty(event: MobilizonEvent):
|
||||
return (
|
||||
f"{event.name : ^40}{click.style(event.status.name, fg=status_to_color[event.status]) : ^22}"
|
||||
f"{str(event.mobilizon_id) : <40}{event.begin_datetime.isoformat() : <29}{event.end_datetime.isoformat()}"
|
||||
f"{str(event.mobilizon_id) : <40}"
|
||||
f"{event.begin_datetime.to('local').isoformat() : <29}"
|
||||
f"{event.end_datetime.to('local').isoformat()}"
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -1,28 +1,28 @@
|
|||
from typing import List
|
||||
|
||||
from bs4 import BeautifulSoup, Tag
|
||||
import markdownify
|
||||
|
||||
|
||||
def get_bottom_paragraphs(soup: BeautifulSoup) -> List[Tag]:
|
||||
def get_bottom_paragraphs(soup: BeautifulSoup) -> list[Tag]:
|
||||
return [d for d in soup.findAll("p") if not d.find("p")]
|
||||
|
||||
|
||||
def html_to_plaintext(content):
|
||||
def html_to_plaintext(content) -> str:
|
||||
"""
|
||||
Transform a HTML in a plaintext sting that can be more easily processed by the publishers.
|
||||
Transform a HTML in a plaintext string that can be more easily processed by the publishers.
|
||||
|
||||
:param content:
|
||||
:return:
|
||||
"""
|
||||
# TODO: support links and quotes
|
||||
soup = BeautifulSoup(content)
|
||||
return "\n".join(
|
||||
" ".join(tag.stripped_strings) for tag in get_bottom_paragraphs(soup)
|
||||
)
|
||||
p_list = get_bottom_paragraphs(soup)
|
||||
if p_list:
|
||||
return "\n".join(" ".join(tag.stripped_strings) for tag in p_list)
|
||||
else:
|
||||
return soup.text
|
||||
|
||||
|
||||
def html_to_markdown(content):
|
||||
def html_to_markdown(content) -> str:
|
||||
markdown = markdownify.markdownify(content)
|
||||
escaped_markdown = markdown.replace(">", "\\>")
|
||||
return escaped_markdown.strip()
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# {{ name }}
|
||||
|
||||
🕒 {{ begin_datetime.format('DD MMMM, HH:mm') }} - {{ end_datetime.format('DD MMMM, HH:mm') }}
|
||||
🕒 {{ begin_datetime.to('local').format('DD MMMM, HH:mm') }} - {{ end_datetime.to('local').format('DD MMMM, HH:mm') }}
|
||||
|
||||
{% if location %}
|
||||
📍 {{ location }}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# {{ name }}
|
||||
|
||||
🕒 {{ begin_datetime.format('DD MMMM, HH:mm') }} - {{ end_datetime.format('DD MMMM, HH:mm') }}
|
||||
🕒 {{ begin_datetime.to('local').format('DD MMMM, HH:mm') }} - {{ end_datetime.to('local').format('DD MMMM, HH:mm') }}
|
||||
|
||||
{% if location %}
|
||||
📍 {{ location }}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{{ name }}
|
||||
|
||||
🕒 {{ begin_datetime.format('DD MMMM, HH:mm') }} - {{ end_datetime.format('DD MMMM, HH:mm') }}
|
||||
🕒 {{ begin_datetime.to('local').format('DD MMMM, HH:mm') }} - {{ end_datetime.to('local').format('DD MMMM, HH:mm') }}
|
||||
|
||||
{% if location %}
|
||||
📍 {{ location }}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
*{{ name }}*
|
||||
|
||||
🕒 {{ begin_datetime.format('DD MMMM, HH:mm') }} - {{ end_datetime.format('DD MMMM, HH:mm') }}
|
||||
🕒 {{ begin_datetime.to('local').format('DD MMMM, HH:mm') }} - {{ end_datetime.to('local').format('DD MMMM, HH:mm') }}
|
||||
{% if location %}📍 {{ location }}{% endif %}
|
||||
🔗 {{mobilizon_link}}
|
|
@ -1,6 +1,6 @@
|
|||
<strong>{{ name }}</strong>
|
||||
|
||||
🕒 {{ begin_datetime.format('DD MMMM, HH:mm') }} - {{ end_datetime.format('DD MMMM, HH:mm') }}
|
||||
🕒 {{ begin_datetime.to('local').format('DD MMMM, HH:mm') }} - {{ end_datetime.to('local').format('DD MMMM, HH:mm') }}
|
||||
{% if location %}📍 {{ location }}{% endif %}
|
||||
|
||||
{{ description }}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
*{{ name }}*
|
||||
|
||||
🕒 {{ begin_datetime.format('DD MMMM, HH:mm') }} - {{ end_datetime.format('DD MMMM, HH:mm') }}
|
||||
🕒 {{ begin_datetime.to('local').format('DD MMMM, HH:mm') }} - {{ end_datetime.to('local').format('DD MMMM, HH:mm') }}
|
||||
{% if location %}📍 {{ location }}{% endif %}
|
||||
🔗 [Link]({{mobilizon_link}})
|
|
@ -1,6 +1,6 @@
|
|||
# {{ name }}
|
||||
|
||||
🕒 {{ begin_datetime.format('DD MMMM, HH:mm') }} - {{ end_datetime.format('DD MMMM, HH:mm') }}
|
||||
🕒 {{ begin_datetime.to('local').format('DD MMMM, HH:mm') }} - {{ end_datetime.to('local').format('DD MMMM, HH:mm') }}
|
||||
|
||||
{% if location %}
|
||||
📍 {{ location }}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# {{ name }}
|
||||
🕒 {{ begin_datetime.format('DD MMMM, HH:mm') }} - {{ end_datetime.format('DD MMMM, HH:mm') }}
|
||||
🕒 {{ begin_datetime.to('local').format('DD MMMM, HH:mm') }} - {{ end_datetime.to('local').format('DD MMMM, HH:mm') }}
|
||||
{% if location %}
|
||||
📍 {{ location }}
|
||||
{% endif %}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# {{ name }}
|
||||
|
||||
🕒 {{ begin_datetime.format('DD MMMM, HH:mm') }} - {{ end_datetime.format('DD MMMM, HH:mm') }}
|
||||
🕒 {{ begin_datetime.to('local').format('DD MMMM, HH:mm') }} - {{ end_datetime.to('local').format('DD MMMM, HH:mm') }}
|
||||
|
||||
{% if location %}
|
||||
📍 {{ location }}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# {{ name }}
|
||||
|
||||
🕒 {{ begin_datetime.format('DD MMMM, HH:mm') }} - {{ end_datetime.format('DD MMMM, HH:mm') }}
|
||||
🕒 {{ begin_datetime.to('local').format('DD MMMM, HH:mm') }} - {{ end_datetime.to('local').format('DD MMMM, HH:mm') }}
|
||||
|
||||
{% if location %}
|
||||
📍 {{ location }}
|
||||
|
|
|
@ -39,8 +39,3 @@ build-backend = "poetry.core.masonry.api"
|
|||
|
||||
[tool.poetry.scripts]
|
||||
mobilizon-reshare="mobilizon_reshare.cli.cli:mobilizon_reshare"
|
||||
|
||||
[tool.pytest.ini_options]
|
||||
markers=[
|
||||
"timezone_sensitive"
|
||||
]
|
|
@ -2,4 +2,4 @@
|
|||
|
||||
set -e
|
||||
|
||||
poetry run pytest -m "not timezone_sensitive"
|
||||
poetry run pytest
|
||||
|
|
|
@ -10,7 +10,6 @@ from mobilizon_reshare.publishers.platforms.platform_mapping import (
|
|||
from mobilizon_reshare.storage.query.event_converter import to_model
|
||||
|
||||
|
||||
@pytest.mark.timezone_sensitive
|
||||
@pytest.mark.parametrize("publisher_name", name_to_formatter_class.keys())
|
||||
@pytest.mark.asyncio
|
||||
async def test_format_event(runner, event, capsys, publisher_name):
|
||||
|
@ -26,7 +25,6 @@ async def test_format_event(runner, event, capsys, publisher_name):
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.timezone_sensitive
|
||||
@pytest.mark.asyncio
|
||||
async def test_format_event_missing(runner, capsys):
|
||||
event_id = uuid.uuid4()
|
||||
|
|
|
@ -7,24 +7,27 @@ import pytest
|
|||
from mobilizon_reshare.event.event import MobilizonEvent
|
||||
from mobilizon_reshare.publishers.platforms.platform_mapping import get_formatter_class
|
||||
|
||||
begin_date = arrow.get(
|
||||
datetime(
|
||||
year=2021,
|
||||
month=1,
|
||||
day=1,
|
||||
hour=11,
|
||||
minute=30,
|
||||
tzinfo=timezone(timedelta(hours=1)),
|
||||
)
|
||||
).to("local")
|
||||
|
||||
end_date = begin_date.shift(hours=1)
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def event() -> MobilizonEvent:
|
||||
begin_date = arrow.get(
|
||||
datetime(
|
||||
year=2021,
|
||||
month=1,
|
||||
day=1,
|
||||
hour=11,
|
||||
minute=30,
|
||||
tzinfo=timezone(timedelta(hours=1)),
|
||||
)
|
||||
)
|
||||
return MobilizonEvent(
|
||||
name="test event",
|
||||
description="<p>description of the event</p>",
|
||||
begin_datetime=begin_date,
|
||||
end_datetime=begin_date.shift(hours=1),
|
||||
end_datetime=end_date,
|
||||
mobilizon_link="http://some_link.com/123",
|
||||
mobilizon_id=UUID(int=12345),
|
||||
thumbnail_link="http://some_link.com/123.jpg",
|
||||
|
@ -38,9 +41,9 @@ def event() -> MobilizonEvent:
|
|||
[
|
||||
[
|
||||
"facebook",
|
||||
"""#
|
||||
f"""# test event
|
||||
|
||||
🕒 01 January, 11:30 - 01 January, 12:30
|
||||
🕒 01 January, {begin_date.format('HH:mm')} - 01 January, {end_date.format('HH:mm')}
|
||||
|
||||
|
||||
📍 location
|
||||
|
@ -53,9 +56,9 @@ Link: http://some_link.com/123
|
|||
],
|
||||
[
|
||||
"telegram",
|
||||
"""<strong>test event</strong>
|
||||
f"""<strong>test event</strong>
|
||||
|
||||
🕒 01 January, 11:30 - 01 January, 12:30
|
||||
🕒 01 January, {begin_date.format('HH:mm')} - 01 January, {end_date.format('HH:mm')}
|
||||
📍 location
|
||||
|
||||
description of the event
|
||||
|
|
Loading…
Reference in New Issue