Beispiel #1
0
    def test_existing_user_not_in_basket(self):
        """Adding a user already in ET but not basket should preserve token."""
        email = '*****@*****.**'
        fxa_id = 'the fxa abides'
        token = 'hehe... you said **token**.'
        self.get_external_user_data.return_value = {
            'email': email,
            'token': token,
            'lang': 'de',
            'format': '',
        }
        tasks.update_fxa_info(email, 'de', fxa_id)
        sub = models.Subscriber.objects.get(email=email)
        self.assertEqual(sub.fxa_id, fxa_id)
        self.assertEqual(sub.token, token)

        self.apply_updates.assert_called_once_with(settings.EXACTTARGET_DATA, {
            'EMAIL_ADDRESS_': email,
            'TOKEN': token,
            'FXA_ID': fxa_id,
            'MODIFIED_DATE_': ANY,
        })
        self.get_external_user_data.assert_called_with(email=email)
        self.send_message.assert_called_with('de_{0}'.format(tasks.FXACCOUNT_WELCOME),
                                             email, sub.token, '')
Beispiel #2
0
    def test_new_user(self):
        """Adding a new user should add fxa_id."""
        email = '*****@*****.**'
        fxa_id = 'the fxa abides'

        tasks.update_fxa_info(email, 'de', fxa_id)

        self.apply_updates.assert_called_once_with(
            'Firefox_Account_ID', {
                'EMAIL_ADDRESS_': email,
                'FXA_ID': fxa_id,
                'FXA_LANGUAGE_ISO2': 'de',
                'CREATED_DATE_': ANY,
            })
Beispiel #3
0
    def test_existing_user_no_lang(self):
        """Adding a fxa_id to an existing user should update lang only if not set."""
        email = '*****@*****.**'
        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, '')
Beispiel #4
0
    def test_skip_welcome(self):
        """Passing skip_welcome should add user but not send welcome."""
        self.get_external_user_data.return_value = None
        email = '*****@*****.**'
        fxa_id = 'the fxa abides'

        tasks.update_fxa_info(email, 'de', fxa_id, skip_welcome=True)
        self.apply_updates.assert_called_once_with(settings.EXACTTARGET_DATA, {
            'EMAIL_ADDRESS_': email,
            'TOKEN': ANY,
            'FXA_ID': fxa_id,
            'FXA_LANGUAGE_ISO2': 'de',
            'SOURCE_URL': 'https://accounts.firefox.com',
            'MODIFIED_DATE_': ANY,
        })
        self.get_external_user_data.assert_called_with(email=email)
        self.assertFalse(self.send_message.delay.called)
Beispiel #5
0
    def test_new_user(self):
        """Adding a new user should add fxa_id."""
        self.get_external_user_data.return_value = None
        email = '*****@*****.**'
        fxa_id = 'the fxa abides'

        tasks.update_fxa_info(email, 'de', fxa_id)

        self.apply_updates.assert_called_once_with(settings.EXACTTARGET_DATA, {
            'EMAIL_ADDRESS_': email,
            'TOKEN': ANY,
            'FXA_ID': fxa_id,
            'FXA_LANGUAGE_ISO2': 'de',
            'SOURCE_URL': 'https://accounts.firefox.com',
            'MODIFIED_DATE_': ANY,
        })
        self.get_external_user_data.assert_called_with(email=email)
        self.send_message.delay.assert_called_with('de_{0}'.format(tasks.FXACCOUNT_WELCOME),
                                                   email, ANY, 'H')
Beispiel #6
0
    def test_existing_user(self):
        """Adding a fxa_id to an existing user shouldn't modify other things."""
        email = "*****@*****.**"
        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": "de", "format": "T"}
        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,
                "FXA_LANGUAGE_ISO2": "de",
            },
        )
        self.send_message.delay.assert_called_with("de_{0}_T".format(tasks.FXACCOUNT_WELCOME), email, sub.token, "T")
Beispiel #7
0
    def test_user_in_et_not_basket(self):
        """A user could exist in basket but not ET, should still work."""
        self.get_external_user_data.return_value = None
        email = '*****@*****.**'
        fxa_id = 'the fxa abides'

        models.Subscriber.objects.create(email=email)
        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': sub.token,
            'FXA_ID': fxa_id,
            'LANGUAGE_ISO2': 'de',
            'SOURCE_URL': 'https://accounts.firefox.com',
            'MODIFIED_DATE_': ANY,
        })
        self.get_external_user_data.assert_called_with(email=email)
        self.send_message.assert_called_with('de_{0}'.format(tasks.FXACCOUNT_WELCOME),
                                             email, sub.token, 'H')
Beispiel #8
0
    def test_existing_user(self):
        """Adding a fxa_id to an existing user shouldn't modify other things."""
        email = '*****@*****.**'
        fxa_id = 'the fxa abides'
        token = 'the dudes token, man'
        self.get_external_user_data.return_value = {
            'email': email,
            'token': token,
            'lang': 'de',
            'format': 'T',
        }
        tasks.update_fxa_info(email, 'de', fxa_id)

        self.apply_updates.assert_called_once_with(settings.EXACTTARGET_DATA, {
            'EMAIL_ADDRESS_': email,
            'TOKEN': token,
            'FXA_ID': fxa_id,
            'MODIFIED_DATE_': ANY,
            'FXA_LANGUAGE_ISO2': 'de',
        })
        self.send_message.delay.assert_called_with('de_{0}_T'.format(tasks.FXACCOUNT_WELCOME),
                                                   email, token, 'T')
Beispiel #9
0
    def test_skip_welcome(self):
        """Passing skip_welcome should add user but not send welcome."""
        self.get_external_user_data.return_value = None
        email = "*****@*****.**"
        fxa_id = "the fxa abides"

        tasks.update_fxa_info(email, "de", fxa_id, skip_welcome=True)
        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": sub.token,
                "FXA_ID": fxa_id,
                "FXA_LANGUAGE_ISO2": "de",
                "SOURCE_URL": "https://accounts.firefox.com",
                "MODIFIED_DATE_": ANY,
            },
        )
        self.get_external_user_data.assert_called_with(email=email)
        self.assertFalse(self.send_message.delay.called)
Beispiel #10
0
    def test_new_user(self):
        """Adding a new user to the DB should add fxa_id."""
        self.get_external_user_data.return_value = None
        email = "*****@*****.**"
        fxa_id = "the fxa abides"

        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": sub.token,
                "FXA_ID": fxa_id,
                "FXA_LANGUAGE_ISO2": "de",
                "SOURCE_URL": "https://accounts.firefox.com",
                "MODIFIED_DATE_": ANY,
            },
        )
        self.get_external_user_data.assert_called_with(email=email)
        self.send_message.delay.assert_called_with("de_{0}".format(tasks.FXACCOUNT_WELCOME), email, sub.token, "H")
Beispiel #11
0
    def test_existing_user_not_in_basket(self):
        """Adding a user already in ET but not basket should preserve token."""
        email = "*****@*****.**"
        fxa_id = "the fxa abides"
        token = "hehe... you said **token**."
        self.get_external_user_data.return_value = {"email": email, "token": token, "lang": "de", "format": ""}
        tasks.update_fxa_info(email, "de", fxa_id)
        sub = models.Subscriber.objects.get(email=email)
        self.assertEqual(sub.fxa_id, fxa_id)
        self.assertEqual(sub.token, token)

        self.apply_updates.assert_called_once_with(
            settings.EXACTTARGET_DATA,
            {
                "EMAIL_ADDRESS_": email,
                "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.delay.assert_called_with("de_{0}".format(tasks.FXACCOUNT_WELCOME), email, sub.token, "")