diff --git a/app/publisher/publisher.py b/app/publisher/publisher.py index e4378dda24..909a437a3b 100644 --- a/app/publisher/publisher.py +++ b/app/publisher/publisher.py @@ -29,10 +29,9 @@ def _publish(self, topic_id: str, message: bytes) -> Future: response: Future = self._client.publish(topic_path, message) return response - # pragma: no cover def publish( self, topic_id: str, message: bytes, fulfilment_request_transaction_id: str - ) -> None: # pragma: no cover + ) -> None: response = self._publish(topic_id, message) try: # Resolve the future diff --git a/tests/app/publisher/test_publisher.py b/tests/app/publisher/test_publisher.py index f6e3c2c431..b29a2a2f3a 100644 --- a/tests/app/publisher/test_publisher.py +++ b/tests/app/publisher/test_publisher.py @@ -1,5 +1,11 @@ +from unittest.mock import Mock, patch +from uuid import uuid4 + +import pytest from google.pubsub_v1.types.pubsub import PubsubMessage +from app.publisher.exceptions import PublicationFailed + def test_publish(publisher, mocker): topic_id = "test-topic-id" @@ -24,3 +30,18 @@ def test_publish(publisher, mocker): # Check mock. batch.publish.assert_has_calls([mocker.call(PubsubMessage(data=b"test-message"))]) + + +def test_resolving_message_raises_exception_on_error(publisher): + mock_future = Mock() + mock_future.result.side_effect = Exception() + + with patch( + "app.publisher.publisher.PubSubPublisher._publish", return_value=mock_future + ): + with pytest.raises(PublicationFailed): + publisher.publish( + "test-topic-id", + b"test-message", + fulfilment_request_transaction_id=str(uuid4()), + )