Merge pull request #19048 from edx/ziafazal/WL-1810
WL-1810: Do not send user info to sailthru when registered from white label site
This commit is contained in:
@@ -53,7 +53,7 @@ def update_sailthru(sender, user, mode, course_id, **kwargs): # pylint: disable
|
||||
"""
|
||||
if WAFFLE_SWITCHES.is_enabled(SAILTHRU_AUDIT_PURCHASE_ENABLED) and mode in CourseMode.AUDIT_MODES:
|
||||
email = str(user.email)
|
||||
update_course_enrollment.delay(email, course_id, mode)
|
||||
update_course_enrollment.delay(email, course_id, mode, site=_get_current_site())
|
||||
|
||||
|
||||
@receiver(CREATE_LOGON_COOKIE)
|
||||
|
||||
@@ -75,6 +75,10 @@ def update_user(self, sailthru_vars, email, site=None, new_user=False, activatio
|
||||
if not email_config.enabled:
|
||||
return
|
||||
|
||||
# do not add user if registered at a white label site
|
||||
if not is_default_site(site):
|
||||
return
|
||||
|
||||
sailthru_client = SailthruClient(email_config.sailthru_key, email_config.sailthru_secret)
|
||||
try:
|
||||
sailthru_response = sailthru_client.api_post("user",
|
||||
@@ -96,8 +100,7 @@ def update_user(self, sailthru_vars, email, site=None, new_user=False, activatio
|
||||
max_retries=email_config.sailthru_max_retries)
|
||||
return
|
||||
|
||||
if activation and email_config.sailthru_welcome_template and is_default_site(site) and not \
|
||||
sailthru_vars.get('is_enterprise_learner'):
|
||||
if activation and email_config.sailthru_welcome_template and not sailthru_vars.get('is_enterprise_learner'):
|
||||
|
||||
scheduled_datetime = datetime.utcnow() + timedelta(seconds=email_config.welcome_email_send_delay)
|
||||
try:
|
||||
@@ -295,14 +298,20 @@ def _retryable_sailthru_error(error):
|
||||
|
||||
|
||||
@task(bind=True, routing_key=ACE_ROUTING_KEY)
|
||||
def update_course_enrollment(self, email, course_key, mode):
|
||||
def update_course_enrollment(self, email, course_key, mode, site=None):
|
||||
"""Adds/updates Sailthru when a user adds to cart/purchases/upgrades a course
|
||||
Args:
|
||||
user: current user
|
||||
email: email address of enrolled user
|
||||
course_key: course key of course
|
||||
mode: mode user is enrolled in
|
||||
site: site where user enrolled
|
||||
Returns:
|
||||
None
|
||||
"""
|
||||
# do not add user if registered at a white label site
|
||||
if not is_default_site(site):
|
||||
return
|
||||
|
||||
course_url = build_course_url(course_key)
|
||||
config = EmailMarketingConfiguration.current()
|
||||
|
||||
|
||||
@@ -87,7 +87,6 @@ class EmailMarketingTests(TestCase):
|
||||
self.course_url = 'http://testserver/courses/edX/toy/2012_Fall/info'
|
||||
|
||||
self.site = Site.objects.get_current()
|
||||
self.site_domain = self.site.domain
|
||||
self.request.site = self.site
|
||||
super(EmailMarketingTests, self).setUp()
|
||||
|
||||
@@ -212,23 +211,6 @@ class EmailMarketingTests(TestCase):
|
||||
)
|
||||
))
|
||||
|
||||
@patch('email_marketing.tasks.log.error')
|
||||
@patch('email_marketing.tasks.SailthruClient.api_post')
|
||||
@patch('email_marketing.tasks.SailthruClient.api_get')
|
||||
def test_email_not_sent_to_white_label(self, mock_sailthru_get, mock_sailthru_post, mock_log_error):
|
||||
"""
|
||||
tests that welcome email is not sent to the white-label site learner
|
||||
"""
|
||||
white_label_site = Site.objects.create(domain='testwhitelabel.com', name='White Label')
|
||||
site_dict = {'id': white_label_site.id, 'domain': white_label_site.domain, 'name': white_label_site.name}
|
||||
mock_sailthru_post.return_value = SailthruResponse(JsonResponse({'ok': True}))
|
||||
mock_sailthru_get.return_value = SailthruResponse(JsonResponse({'lists': [{'name': 'new list'}], 'ok': True}))
|
||||
update_user.delay(
|
||||
{'gender': 'm', 'username': 'test', 'activated': 1}, TEST_EMAIL, site_dict, new_user=True
|
||||
)
|
||||
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):
|
||||
"""
|
||||
@@ -245,23 +227,16 @@ class EmailMarketingTests(TestCase):
|
||||
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):
|
||||
def test_add_user_list_not_called_on_white_label_domain(self, mock_sailthru_post):
|
||||
"""
|
||||
test non existing domain name updates Sailthru user lists with default list
|
||||
test user is not added to Sailthru user lists if registered from a whitel labe site
|
||||
"""
|
||||
existing_site = Site.objects.create(domain='testing.com', name='testing.com')
|
||||
existing_site = Site.objects.create(domain='testwhitelabel.com', name='White Label')
|
||||
site_dict = {'id': existing_site.id, 'domain': existing_site.domain, 'name': existing_site.name}
|
||||
mock_sailthru_post.return_value = SailthruResponse(JsonResponse({'ok': True}))
|
||||
mock_sailthru_get.return_value = SailthruResponse(
|
||||
JsonResponse({'lists': [{'name': 'new list'}, {'name': 'testing_com_user_list'}], 'ok': True})
|
||||
)
|
||||
update_user.delay(
|
||||
{'gender': 'm', 'username': 'test', 'activated': 1}, TEST_EMAIL, site=site_dict, new_user=True
|
||||
)
|
||||
self.assertEquals(mock_sailthru_post.call_args[0][0], "user")
|
||||
userparms = mock_sailthru_post.call_args[0][1]
|
||||
self.assertEquals(userparms['lists']['testing_com_user_list'], 1)
|
||||
self.assertFalse(mock_sailthru_post.called)
|
||||
|
||||
@patch('email_marketing.tasks.log.error')
|
||||
@patch('email_marketing.tasks.SailthruClient.api_post')
|
||||
@@ -276,7 +251,7 @@ class EmailMarketingTests(TestCase):
|
||||
# force Sailthru API exception
|
||||
mock_log_error.reset_mock()
|
||||
mock_sailthru.side_effect = SailthruClientError
|
||||
update_user.delay({}, self.user.email, self.site_domain)
|
||||
update_user.delay({}, self.user.email)
|
||||
self.assertTrue(mock_log_error.called)
|
||||
|
||||
# force Sailthru API exception on 2nd call
|
||||
@@ -713,6 +688,28 @@ class SailthruTests(TestCase):
|
||||
}]
|
||||
mock_sailthru_purchase.assert_called_with(TEST_EMAIL, item, options={})
|
||||
|
||||
@patch('sailthru.sailthru_client.SailthruClient.purchase')
|
||||
@patch('sailthru.sailthru_client.SailthruClient.api_get')
|
||||
@patch('sailthru.sailthru_client.SailthruClient.api_post')
|
||||
@patch('openedx.core.djangoapps.waffle_utils.WaffleSwitchNamespace.is_enabled')
|
||||
def test_update_course_enrollment_whitelabel(
|
||||
self,
|
||||
switch,
|
||||
mock_sailthru_api_post,
|
||||
mock_sailthru_api_get,
|
||||
mock_sailthru_purchase
|
||||
):
|
||||
"""test user record not sent to sailthru when enrolled in a course at white label site"""
|
||||
switch.return_value = True
|
||||
white_label_site = Site.objects.create(domain='testwhitelabel.com', name='White Label')
|
||||
site_dict = {'id': white_label_site.id, 'domain': white_label_site.domain, 'name': white_label_site.name}
|
||||
with patch('email_marketing.signals._get_current_site') as mock_site_info:
|
||||
mock_site_info.return_value = site_dict
|
||||
update_sailthru(None, self.user, 'audit', self.course_id)
|
||||
self.assertFalse(mock_sailthru_purchase.called)
|
||||
self.assertFalse(mock_sailthru_api_post.called)
|
||||
self.assertFalse(mock_sailthru_api_get.called)
|
||||
|
||||
@patch('sailthru.sailthru_client.SailthruClient.purchase')
|
||||
def test_switch_is_disabled(self, mock_sailthru_purchase):
|
||||
"""Make sure sailthru purchase is not called when waffle switch is disabled"""
|
||||
|
||||
Reference in New Issue
Block a user