Permalink
Browse files

Bug 848458 - Added debugging options to the automatic emails cron job.

  • Loading branch information...
1 parent 277d946 commit 8593d98e4ad7c8c4ab2a198c83b82ef2db56a977 @adngdb adngdb committed with rfw Mar 6, 2013
Showing with 47 additions and 2 deletions.
  1. +9 −2 socorro/cron/jobs/automatic_emails.py
  2. +38 −0 socorro/unittest/cron/jobs/test_automatic_emails.py
@@ -128,7 +128,7 @@ def run(self, connection, run_datetime):
def send_email(self, report):
logger = self.config.logger
list_service = self.email_service.list()
- email = report['email']
+ email = report['email'].strip()
if self.config.test_mode:
email = self.config.test_email_address
@@ -153,7 +153,14 @@ def send_email(self, report):
'EMAIL_FORMAT_': 'H',
'TOKEN': subscriber_key
}
- self.email_service.trigger_send(self.config.email_template, fields)
+ try:
+ self.email_service.trigger_send(self.config.email_template, fields)
+ except exacttarget.NewsletterException, error_msg:
+ logger.error(
+ 'Unable to send an email to %s, error is: %s',
+ email, str(error_msg), exc_info=True
+ )
+
def update_user(self, report, sending_datetime, connection):
cursor = connection.cursor()
@@ -347,6 +347,44 @@ def test_send_email_test_mode(self, exacttarget_mock):
fields
)
+ @mock.patch('socorro.external.exacttarget.exacttarget.ExactTarget')
+ def test_error_in_send_email(self, exacttarget_mock):
+ list_service_mock = exacttarget_mock.return_value.list.return_value
+ list_service_mock.get_subscriber.return_value = {
+ 'token': 'fake@example.com'
+ }
+
+ exacttarget_mock.return_value.trigger_send.side_effect = (
+ exacttarget.NewsletterException('error')
+ )
+
+ config_manager = self._setup_simple_config()
+ with config_manager.context() as config:
+ job = automatic_emails.AutomaticEmailsCronApp(config, '')
+
+ report = {
+ 'email': 'fake@example.com',
+ 'product': 'WaterWolf',
+ 'version': '20.0',
+ 'release_channel': 'Release',
+ }
+ job.send_email(report)
+
+ fields = {
+ 'EMAIL_ADDRESS_': 'fake@example.com',
+ 'EMAIL_FORMAT_': 'H',
+ 'TOKEN': 'fake@example.com'
+ }
+ exacttarget_mock.return_value.trigger_send.assert_called_with(
+ 'socorro_dev_test',
+ fields
+ )
+ self.assertEqual(config.logger.error.call_count, 1)
+ config.logger.error.assert_called_with(
+ 'Unable to send an email to %s, error is: %s',
+ 'fake@example.com', 'error', exc_info=True
+ )
+
def test_update_user(self):
config_manager = self._setup_simple_config()
with config_manager.context() as config:

0 comments on commit 8593d98

Please sign in to comment.