def test_missing_renderer(self): channel = Mock(channel_type=ChannelType.PUSH, ) message = Mock() with self.assertRaises(UnsupportedChannelError): render(channel, message)
def send(msg): u""" Send a message to a recipient. Calling this method will result in an attempt being made to deliver the provided message to the recipient. Depending on the configured policies, it may be transmitted to them over one or more channels (email, sms, push etc). The message must have valid values for all required fields in order for it to be sent. Different channels have different requirements, so care must be taken to ensure that all of the needed information is present in the message before calling ``ace.send()``. Args: msg (Message): The message to send. """ msg.report_basics() channels_for_message = policy.channels_for(msg) for channel_type in channels_for_message: try: channel = get_channel_for_message(channel_type, msg) except UnsupportedChannelError: continue try: rendered_message = presentation.render(channel, msg) delivery.deliver(channel, rendered_message, msg) except ChannelError as error: msg.report( u'{channel_type}_error'.format(channel_type=channel_type), six.text_type(error))
def _get_rendered_message(self): channel = DjangoEmailChannel() message = Message( app_label='testapp', name='testmessage', options={}, recipient=Recipient(lms_user_id=123, email_address='*****@*****.**'), ) return render(channel, message)
def test_no_recipient_email_address(self): message = Message( app_label='testapp', name='testmessage', options={}, recipient=Recipient(lms_user_id=123), ) rendered_email = render(self.channel, message) with self.assertRaisesRegex(InvalidMessageError, 'No email address'): deliver(self.channel, rendered_email, message)
def test_render_email_with_sailthru(self): message = Message( app_label=u'testapp', name=u'testmessage', options={}, recipient=Recipient(username=u'Robot', email_address=u'*****@*****.**'), ) rendered_email = render(self.channel, message) assert u'{beacon_src}' in rendered_email.body_html assert u'{view_url}' in rendered_email.body_html assert u'{optout_confirm_url}' in rendered_email.body_html
def test_on_behalf_option_with_sailthru(self, message_options, expected_options): """ Tests sailthru send API is called with on_behalf option """ message = Message( app_label=u'testapp', name=u'testmessage', options=message_options, recipient=Recipient(username=u'Robot', email_address=u'*****@*****.**'), ) rendered_email = render(self.channel, message) with patch('edx_ace.channel.sailthru.SailthruClient.send') as mock_send: deliver(self.channel, rendered_email, message) self.assertEqual(mock_send.call_args_list[0][1]['options'], expected_options)