From ad8647704d5c12ca98e55c62e17550ded4031deb Mon Sep 17 00:00:00 2001 From: Giacomo Leidi Date: Sat, 5 Feb 2022 18:46:48 +0100 Subject: [PATCH] Add event name to notifications. (#136) --- mobilizon_reshare/publishers/coordinator.py | 9 ++++++--- tests/commands/test_start.py | 14 +++++++++----- tests/publishers/test_coordinator.py | 7 +++++-- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/mobilizon_reshare/publishers/coordinator.py b/mobilizon_reshare/publishers/coordinator.py index deb1f93..367bca6 100644 --- a/mobilizon_reshare/publishers/coordinator.py +++ b/mobilizon_reshare/publishers/coordinator.py @@ -43,7 +43,8 @@ class EventPublicationReport(BasePublicationReport): return ( f"Publication {self.publication.id} failed with status: {self.status}.\n" f"Reason: {self.reason}\n" - f"Publisher: {self.publication.publisher.name}" + f"Publisher: {self.publication.publisher.name}\n" + f"Event: {self.publication.event.name}" ) @@ -193,13 +194,15 @@ class RecapCoordinator: recap_publication.publisher.send(message) reports.append( BasePublicationReport( - status=PublicationStatus.COMPLETED, reason=None, + status=PublicationStatus.COMPLETED, + reason=None, ) ) except PublisherError as e: reports.append( BasePublicationReport( - status=PublicationStatus.FAILED, reason=str(e), + status=PublicationStatus.FAILED, + reason=str(e), ) ) diff --git a/tests/commands/test_start.py b/tests/commands/test_start.py index 8964326..7f10849 100644 --- a/tests/commands/test_start.py +++ b/tests/commands/test_start.py @@ -14,7 +14,8 @@ from mobilizon_reshare.models.publication import PublicationStatus @pytest.mark.asyncio @pytest.mark.parametrize( - "elements", [[]], + "elements", + [[]], ) async def test_start_no_event( mock_mobilizon_success_answer, mobilizon_answer, caplog, elements @@ -84,7 +85,8 @@ async def test_start_new_event( "publisher_class", [pytest.lazy_fixture("mock_publisher_class")] ) @pytest.mark.parametrize( - "elements", [[]], + "elements", + [[]], ) async def test_start_event_from_db( mock_mobilizon_success_answer, @@ -129,7 +131,8 @@ async def test_start_event_from_db( "publisher_class", [pytest.lazy_fixture("mock_publisher_invalid_class")] ) @pytest.mark.parametrize( - "elements", [[]], + "elements", + [[]], ) async def test_start_publisher_failure( mock_mobilizon_success_answer, @@ -163,7 +166,7 @@ async def test_start_publisher_failure( assert "Event to publish found" in caplog.text assert message_collector == [ f"Publication {p.id} failed with status: 0." - f"\nReason: credentials error\nPublisher: mock" + f"\nReason: credentials error\nPublisher: mock\nEvent: test event" for p in publications for _ in range(2) ] # 2 publications failed * 2 notifiers @@ -209,7 +212,8 @@ def second_event_element(): "publisher_class", [pytest.lazy_fixture("mock_publisher_class")] ) @pytest.mark.parametrize( - "elements", [[second_event_element()]], + "elements", + [[second_event_element()]], ) async def test_start_second_execution( mock_mobilizon_success_answer, diff --git a/tests/publishers/test_coordinator.py b/tests/publishers/test_coordinator.py index c8eac2f..f461308 100644 --- a/tests/publishers/test_coordinator.py +++ b/tests/publishers/test_coordinator.py @@ -23,12 +23,15 @@ from tests import today @pytest.fixture() -def failure_report(mock_publisher_invalid): +def failure_report(mock_publisher_invalid, event): return EventPublicationReport( status=PublicationStatus.FAILED, reason="some failure", publication=EventPublication( - publisher=mock_publisher_invalid, formatter=None, event=None, id=UUID(int=1) + publisher=mock_publisher_invalid, + formatter=None, + event=event, + id=UUID(int=1), ), )