fixed facebook format (#142)
This commit is contained in:
parent
9c44c8d730
commit
11de1e1213
|
@ -5,6 +5,7 @@ import pkg_resources
|
|||
from facebook import GraphAPIError
|
||||
|
||||
from mobilizon_reshare.event.event import MobilizonEvent
|
||||
from mobilizon_reshare.formatting.description import html_to_plaintext
|
||||
from mobilizon_reshare.publishers.abstract import (
|
||||
AbstractPlatform,
|
||||
AbstractEventFormatter,
|
||||
|
@ -38,6 +39,11 @@ class FacebookFormatter(AbstractEventFormatter):
|
|||
def _validate_message(self, message) -> None:
|
||||
pass
|
||||
|
||||
def _preprocess_event(self, event: MobilizonEvent):
|
||||
event.description = html_to_plaintext(event.description)
|
||||
event.name = html_to_plaintext(event.name)
|
||||
return event
|
||||
|
||||
|
||||
class FacebookPlatform(AbstractPlatform):
|
||||
"""
|
||||
|
|
|
@ -7,3 +7,5 @@
|
|||
|
||||
{% endif %}
|
||||
{{ description }}
|
||||
|
||||
Link: {{mobilizon_link}}
|
|
@ -0,0 +1,71 @@
|
|||
from datetime import datetime, timedelta, timezone
|
||||
from uuid import UUID
|
||||
|
||||
import arrow
|
||||
import pytest
|
||||
|
||||
from mobilizon_reshare.event.event import MobilizonEvent
|
||||
from mobilizon_reshare.publishers.platforms.platform_mapping import get_formatter_class
|
||||
|
||||
|
||||
@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),
|
||||
mobilizon_link="http://some_link.com/123",
|
||||
mobilizon_id=UUID(int=12345),
|
||||
thumbnail_link="http://some_link.com/123.jpg",
|
||||
location="location",
|
||||
last_update_time=begin_date,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"publisher_name,expected_output",
|
||||
[
|
||||
[
|
||||
"facebook",
|
||||
"""#
|
||||
|
||||
🕒 01 January, 11:30 - 01 January, 12:30
|
||||
|
||||
|
||||
📍 location
|
||||
|
||||
|
||||
description of the event
|
||||
|
||||
Link: http://some_link.com/123
|
||||
""",
|
||||
],
|
||||
[
|
||||
"telegram",
|
||||
"""<strong>test event</strong>
|
||||
|
||||
🕒 01 January, 11:30 - 01 January, 12:30
|
||||
📍 location
|
||||
|
||||
description of the event
|
||||
|
||||
<a href="http://some_link.com/123">Link</a>""",
|
||||
],
|
||||
],
|
||||
)
|
||||
def test_output_format(event, publisher_name, expected_output):
|
||||
assert (
|
||||
get_formatter_class(publisher_name)().get_message_from_event(event).strip()
|
||||
== expected_output.strip()
|
||||
)
|
Loading…
Reference in New Issue