diff --git a/lms/djangoapps/email_marketing/tasks.py b/lms/djangoapps/email_marketing/tasks.py index 2823335a66..2d9fbf9d5d 100644 --- a/lms/djangoapps/email_marketing/tasks.py +++ b/lms/djangoapps/email_marketing/tasks.py @@ -96,7 +96,9 @@ def update_user(self, sailthru_vars, email, site=None, new_user=False, activatio return # if activating user, send welcome email - if activation and email_config.sailthru_welcome_template and is_default_site(site): + if activation and email_config.sailthru_welcome_template and is_default_site(site) and not \ + sailthru_vars.get('is_enterprise_learner'): + scheduled_datetime = datetime.utcnow() + timedelta(seconds=email_config.welcome_email_send_delay) try: sailthru_response = sailthru_client.api_post( diff --git a/lms/djangoapps/email_marketing/tests/test_signals.py b/lms/djangoapps/email_marketing/tests/test_signals.py index 78b731cbb0..ca34b3f4dc 100644 --- a/lms/djangoapps/email_marketing/tests/test_signals.py +++ b/lms/djangoapps/email_marketing/tests/test_signals.py @@ -212,6 +212,21 @@ class EmailMarketingTests(TestCase): self.assertFalse(mock_log_error.called) self.assertNotEqual(mock_sailthru_post.call_args[0][0], "send") + @patch('email_marketing.tasks.SailthruClient.api_post') + def test_email_not_sent_to_enterprise_learners(self, mock_sailthru_post): + """ + tests that welcome email is not sent to the enterprise learner + """ + mock_sailthru_post.return_value = SailthruResponse(JsonResponse({'ok': True})) + update_user.delay( + sailthru_vars={ + 'is_enterprise_learner': True, + 'enterprise_name': 'test name', + }, + email=self.user.email + ) + self.assertNotEqual(mock_sailthru_post.call_args[0][0], "send") + @patch('email_marketing.tasks.SailthruClient.api_post') @patch('email_marketing.tasks.SailthruClient.api_get') def test_add_user_list_existing_domain(self, mock_sailthru_get, mock_sailthru_post):