Skip to content

Commit

Permalink
fix: updated signal call and added tests (#296)
Browse files Browse the repository at this point in the history
  • Loading branch information
AhtishamShahid authored Aug 8, 2024
1 parent 8f9a355 commit 18c8f4d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion edx_ace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from .recipient import Recipient
from .recipient_resolver import RecipientResolver

__version__ = '1.11.0'
__version__ = '1.11.1'


__all__ = [
Expand Down
1 change: 0 additions & 1 deletion edx_ace/delivery.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,3 @@ def deliver(channel, rendered_message, message):
delivery_expired_report = f'{channel_type}_delivery_expired'
logger.debug(delivery_expired_report)
message.report(delivery_expired_report, get_current_time() - start_time)
ACE_MESSAGE_SENT.send(sender=channel, message=message)
22 changes: 20 additions & 2 deletions edx_ace/tests/test_delivery.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,26 @@ def setUp(self):
)
self.current_time = datetime.datetime.utcnow().replace(tzinfo=tzutc())

def test_happy_path(self):
@patch('edx_ace.delivery.ACE_MESSAGE_SENT.send')
def test_happy_path(self, mock_ace_message_sent):
deliver(self.mock_channel, sentinel.rendered_email, self.message)
self.mock_channel.deliver.assert_called_once_with(self.message, sentinel.rendered_email)
# check if ACE_MESSAGE_SENT is raised
mock_ace_message_sent.assert_called_once_with(sender=self.mock_channel, message=self.message)

def test_fatal_error(self):
self.mock_channel.deliver.side_effect = FatalChannelDeliveryError('testing')
with self.assertRaises(FatalChannelDeliveryError):
deliver(self.mock_channel, sentinel.rendered_email, self.message)

@patch('edx_ace.delivery.ACE_MESSAGE_SENT.send')
@patch('edx_ace.delivery.get_current_time')
def test_custom_message_expiration(self, mock_get_current_time):
def test_custom_message_expiration(self, mock_get_current_time, mock_ace_message_sent):
self.message.expiration_time = self.current_time - datetime.timedelta(seconds=10)
mock_get_current_time.return_value = self.current_time
deliver(self.mock_channel, sentinel.rendered_email, self.message)
assert not self.mock_channel.deliver.called
mock_ace_message_sent.assert_not_called()

@patch('edx_ace.delivery.time')
@patch('edx_ace.delivery.get_current_time')
Expand Down Expand Up @@ -100,3 +105,16 @@ def test_multiple_retries(self, mock_get_current_time, mock_time):
deliver(self.mock_channel, sentinel.rendered_email, self.message)
assert mock_time.sleep.call_args_list == [call(1), call(1)]
assert self.mock_channel.deliver.call_count == 3

@patch('edx_ace.delivery.ACE_MESSAGE_SENT.send')
def test_message_sent_signal_for_push_channel(self, mock_ace_message_sent):
"""
Test that ACE_MESSAGE_SENT signal is sent when a message is delivered to a push channel.
"""
mock_push_channel = Mock(
name='push_channel',
channel_type=ChannelType.PUSH
)
deliver(mock_push_channel, sentinel.rendered_email, self.message)
# check if ACE_MESSAGE_SENT is raised
mock_ace_message_sent.assert_called_once_with(sender=mock_push_channel, message=self.message)

0 comments on commit 18c8f4d

Please sign in to comment.