Commit 33e077d4 by Waheed Ahmed

Add activation_key var to user profile in SailThru.

As an email marketer, I would like to send an account activation reminder to learners who haven't activated
their accounts to increase their chances of coming back and engaging with our platform. Each user profile in
SailThru will have a var with the correct activation_key originally assigned to the user.

LEARNER-2110
parent acc208b6
......@@ -145,7 +145,7 @@ REGISTRATION_UTM_PARAMETERS = {
}
REGISTRATION_UTM_CREATED_AT = 'registration_utm_created_at'
# used to announce a registration
REGISTER_USER = Signal(providing_args=["user", "profile"])
REGISTER_USER = Signal(providing_args=["user", "registration"])
# Disable this warning because it doesn't make sense to completely refactor tests to appease Pylint
# pylint: disable=logging-format-interpolation
......@@ -2022,7 +2022,7 @@ def create_account_with_params(request, params):
)
# Announce registration
REGISTER_USER.send(sender=None, user=user, profile=profile)
REGISTER_USER.send(sender=None, user=user, registration=registration)
create_comments_service_user(user)
......
......@@ -90,7 +90,7 @@ def add_email_marketing_cookies(sender, response=None, user=None,
@receiver(REGISTER_USER)
def email_marketing_register_user(sender, user=None, profile=None,
def email_marketing_register_user(sender, user, registration,
**kwargs): # pylint: disable=unused-argument
"""
Called after user created and saved
......@@ -98,7 +98,7 @@ def email_marketing_register_user(sender, user=None, profile=None,
Args:
sender: Not used
user: The user object for the user being changed
profile: The user profile for the user being changed
registration: The user registration profile to activate user account
kwargs: Not used
"""
email_config = EmailMarketingConfiguration.current()
......@@ -110,9 +110,8 @@ def email_marketing_register_user(sender, user=None, profile=None,
return
# perform update asynchronously
update_user.delay(
_create_sailthru_user_vars(user, user.profile), user.email, site=_get_current_site(), new_user=True
)
update_user.delay(_create_sailthru_user_vars(user, user.profile, registration=registration), user.email,
site=_get_current_site(), new_user=True)
@receiver(USER_FIELD_CHANGED)
......@@ -161,7 +160,7 @@ def email_marketing_user_field_changed(sender, user=None, table=None, setting=No
update_user_email.delay(user.email, old_value)
def _create_sailthru_user_vars(user, profile):
def _create_sailthru_user_vars(user, profile, registration=None):
"""
Create sailthru user create/update vars from user + profile.
"""
......@@ -181,6 +180,9 @@ def _create_sailthru_user_vars(user, profile):
sailthru_vars['year_of_birth'] = profile.year_of_birth
sailthru_vars['country'] = unicode(profile.country.code)
if registration:
sailthru_vars['activation_key'] = registration.activation_key
return sailthru_vars
......
......@@ -30,6 +30,7 @@ from email_marketing.tasks import (
get_email_cookies_via_sailthru
)
from openedx.core.djangoapps.lang_pref import LANGUAGE_KEY
from student.models import Registration
from student.tests.factories import UserFactory, UserProfileFactory
from util.json_request import JsonResponse
......@@ -70,9 +71,8 @@ class EmailMarketingTests(TestCase):
update_email_marketing_config(enabled=False)
self.request_factory = RequestFactory()
self.user = UserFactory.create(username='test', email=TEST_EMAIL)
self.profile = self.user.profile
self.profile.year_of_birth = 1980
self.profile.save()
self.registration = Registration()
self.registration.register(self.user)
self.request = self.request_factory.get("foo")
update_email_marketing_config(enabled=True)
......@@ -308,14 +308,14 @@ class EmailMarketingTests(TestCase):
add_email_marketing_cookies(None)
self.assertFalse(mock_log_error.called)
email_marketing_register_user(None)
email_marketing_register_user(None, None, None)
self.assertFalse(mock_log_error.called)
update_email_marketing_config(enabled=True)
# test anonymous users
anon = AnonymousUser()
email_marketing_register_user(None, user=anon)
email_marketing_register_user(None, anon, None)
self.assertFalse(mock_log_error.called)
email_marketing_user_field_changed(None, user=anon)
......@@ -443,19 +443,21 @@ class EmailMarketingTests(TestCase):
@patch('lms.djangoapps.email_marketing.tasks.update_user.delay')
def test_register_user(self, mock_update_user, mock_get_current_request):
"""
make sure register user call invokes update_user
make sure register user call invokes update_user and includes activation_key
"""
mock_get_current_request.return_value = self.request
email_marketing_register_user(None, user=self.user, profile=self.profile)
email_marketing_register_user(None, user=self.user, registration=self.registration)
self.assertTrue(mock_update_user.called)
self.assertEqual(mock_update_user.call_args[0][0]['activation_key'], self.registration.activation_key)
@patch('lms.djangoapps.email_marketing.tasks.update_user.delay')
def test_register_user_no_request(self, mock_update_user):
"""
make sure register user call invokes update_user
make sure register user call invokes update_user and includes activation_key
"""
email_marketing_register_user(None, user=self.user, profile=self.profile)
email_marketing_register_user(None, user=self.user, registration=self.registration)
self.assertTrue(mock_update_user.called)
self.assertEqual(mock_update_user.call_args[0][0]['activation_key'], self.registration.activation_key)
@patch('lms.djangoapps.email_marketing.tasks.update_user.delay')
def test_register_user_language_preference(self, mock_update_user):
......@@ -464,12 +466,12 @@ class EmailMarketingTests(TestCase):
"""
# If the user hasn't set an explicit language preference, we should send the application's default.
self.assertIsNone(self.user.preferences.model.get_value(self.user, LANGUAGE_KEY))
email_marketing_register_user(None, user=self.user, profile=self.profile)
email_marketing_register_user(None, user=self.user, registration=self.registration)
self.assertEqual(mock_update_user.call_args[0][0]['ui_lang'], settings.LANGUAGE_CODE)
# If the user has set an explicit language preference, we should send it.
self.user.preferences.create(key=LANGUAGE_KEY, value='es-419')
email_marketing_register_user(None, user=self.user, profile=self.profile)
email_marketing_register_user(None, user=self.user, registration=self.registration)
self.assertEqual(mock_update_user.call_args[0][0]['ui_lang'], 'es-419')
@patch('email_marketing.signals.crum.get_current_request')
......
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