Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/pip/development-dependencies-c11c…
Browse files Browse the repository at this point in the history
…862310
  • Loading branch information
rmccar authored Sep 16, 2024
2 parents 0336ea7 + 91761b5 commit c208680
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
3 changes: 1 addition & 2 deletions app/publisher/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions tests/app/publisher/test_publisher.py
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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()),
)

0 comments on commit c208680

Please sign in to comment.