Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Commit

Permalink
Merge pull request #104 from pmclanahan/fxa-lang-new-field-1066655
Browse files Browse the repository at this point in the history
Fix bug 1066655: FxA registration should update FxA specific lang field.
  • Loading branch information
pmac committed Sep 12, 2014
2 parents a9a52bd + f931026 commit 0f804ff
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 58 deletions.
17 changes: 8 additions & 9 deletions news/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,27 +288,26 @@ def update_fxa_info(email, lang, fxa_id, source_url=None):
'EMAIL_ADDRESS_': email,
'FXA_ID': fxa_id,
'MODIFIED_DATE_': gmttime(),
'FXA_LANGUAGE_ISO2': lang,
}
if user:
format = user['format']
welcome_format = user['format']
token = user['token']
Subscriber.objects.get_and_sync(email, token, fxa_id)
record['TOKEN'] = token
if not user['lang']:
record['LANGUAGE_ISO2'] = lang
else:
sub, created = Subscriber.objects.get_or_create(email=email, defaults={'fxa_id': fxa_id})
if not created:
sub.fxa_id = fxa_id
sub.save()
format = 'H'
welcome_format = 'H'
token = sub.token
record['TOKEN'] = token
record['LANGUAGE_ISO2'] = lang
# only want source url for first contact
record['SOURCE_URL'] = source_url or 'https://accounts.firefox.com'

welcome = mogrify_message_id(FXACCOUNT_WELCOME, lang, format)
send_message(welcome, email, token, format)
record['TOKEN'] = token

welcome = mogrify_message_id(FXACCOUNT_WELCOME, lang, welcome_format)
send_message(welcome, email, token, welcome_format)
apply_updates(settings.EXACTTARGET_DATA, record)


Expand Down
53 changes: 4 additions & 49 deletions news/tests/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_new_user(self):
'EMAIL_ADDRESS_': email,
'TOKEN': sub.token,
'FXA_ID': fxa_id,
'LANGUAGE_ISO2': 'de',
'FXA_LANGUAGE_ISO2': 'de',
'SOURCE_URL': 'https://accounts.firefox.com',
'MODIFIED_DATE_': ANY,
})
Expand All @@ -65,7 +65,7 @@ def test_user_in_et_not_basket(self):
'EMAIL_ADDRESS_': email,
'TOKEN': sub.token,
'FXA_ID': fxa_id,
'LANGUAGE_ISO2': 'de',
'FXA_LANGUAGE_ISO2': 'de',
'SOURCE_URL': 'https://accounts.firefox.com',
'MODIFIED_DATE_': ANY,
})
Expand Down Expand Up @@ -94,6 +94,7 @@ def test_existing_user_not_in_basket(self):
'TOKEN': token,
'FXA_ID': fxa_id,
'MODIFIED_DATE_': ANY,
'FXA_LANGUAGE_ISO2': 'de',
})
self.get_external_user_data.assert_called_with(email=email)
self.send_message.assert_called_with('de_{0}'.format(tasks.FXACCOUNT_WELCOME),
Expand All @@ -119,57 +120,11 @@ def test_existing_user(self):
'TOKEN': old_sub.token,
'FXA_ID': fxa_id,
'MODIFIED_DATE_': ANY,
'FXA_LANGUAGE_ISO2': 'de',
})
self.send_message.assert_called_with('de_{0}_T'.format(tasks.FXACCOUNT_WELCOME),
email, sub.token, 'T')

def test_existing_user_no_lang(self):
"""Adding a fxa_id to an existing user should update lang only if not set."""
email = 'dude@example.com'
fxa_id = 'the fxa abides'
old_sub = models.Subscriber.objects.create(email=email)
self.get_external_user_data.return_value = {
'email': email,
'token': old_sub.token,
'lang': '',
'format': '',
}
tasks.update_fxa_info(email, 'de', fxa_id)
sub = models.Subscriber.objects.get(email=email)
self.assertEqual(sub.fxa_id, fxa_id)

self.apply_updates.assert_called_once_with(settings.EXACTTARGET_DATA, {
'EMAIL_ADDRESS_': email,
'TOKEN': old_sub.token,
'FXA_ID': fxa_id,
'LANGUAGE_ISO2': 'de',
'MODIFIED_DATE_': ANY,
})
self.send_message.assert_called_with('de_{0}'.format(tasks.FXACCOUNT_WELCOME),
email, sub.token, '')

self.apply_updates.reset_mock()
self.send_message.reset_mock()
self.get_external_user_data.reset_mock()
self.get_external_user_data.return_value = {
'email': email,
'token': old_sub.token,
'lang': 'es',
'format': '',
}
tasks.update_fxa_info(email, 'de', fxa_id)
sub = models.Subscriber.objects.get(email=email)
self.assertEqual(sub.fxa_id, fxa_id)

self.apply_updates.assert_called_once_with(settings.EXACTTARGET_DATA, {
'EMAIL_ADDRESS_': email,
'TOKEN': old_sub.token,
'FXA_ID': fxa_id,
'MODIFIED_DATE_': ANY,
})
self.send_message.assert_called_with('de_{0}'.format(tasks.FXACCOUNT_WELCOME),
email, sub.token, '')


class DebugUserTest(TestCase):
def setUp(self):
Expand Down

0 comments on commit 0f804ff

Please sign in to comment.