Commit 66e2ebb3 by Ahsan Ulhaq

Catch Exception on getting sailthru cookie

LEARNER-3465
parent ff7fa721
......@@ -82,7 +82,11 @@ def add_email_marketing_cookies(sender, response=None, user=None,
post_parms['cookies'] = {'anonymous_interest': sailthru_content}
time_before_call = datetime.datetime.now()
sailthru_response = get_email_cookies_via_sailthru.delay(user.email, post_parms)
try:
sailthru_response = get_email_cookies_via_sailthru.delay(user.email, post_parms)
except Exception as exc: # pylint: disable=broad-except
log.error("Exception Connecting to celery task: %s", unicode(exc))
return response
try:
# synchronous call to get result of an asynchronous celery task, with timeout
......
......@@ -172,6 +172,7 @@ class EmailMarketingTests(TestCase):
add_email_marketing_cookies(None, response=response, user=self.user)
self.assertFalse('sailthru_hid' in response.cookies)
@patch('email_marketing.tasks.log.error')
@patch('email_marketing.tasks.SailthruClient.api_post')
@patch('email_marketing.tasks.SailthruClient.api_get')
......@@ -195,6 +196,22 @@ class EmailMarketingTests(TestCase):
self.assertEquals(userparms['vars']['activated'], 1)
self.assertEquals(userparms['lists']['new list'], 1)
@patch('email_marketing.tasks.get_email_cookies_via_sailthru.delay')
def test_drop_cookie_task_error(self, mock_task):
"""
test that task error is handled
"""
mock_task.side_effect = Exception
with LogCapture(LOGGER_NAME, level=logging.INFO) as logger:
add_email_marketing_cookies(None, response=None, user=self.user)
logger.check(
(LOGGER_NAME, 'ERROR',
'Exception Connecting to celery task: {exception}'.format(
exception=Exception
)
)
)
@patch('email_marketing.tasks.log.error')
@patch('email_marketing.tasks.SailthruClient.api_post')
@patch('email_marketing.tasks.SailthruClient.api_get')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment