Example #1
0
 def test_subscriptions(self):
     """
     look_for_user returns the right list of subscribed newsletters
     """
     Newsletter.objects.create(slug='n1', vendor_id='NEWSLETTER1')
     Newsletter.objects.create(slug='n2', vendor_id='NEWSLETTER2')
     fields = ['NEWSLETTER1_FLG', 'NEWSLETTER2_FLG']
     with patch('news.utils.sfmc') as sfmc_mock:
         sfmc_mock.get_row.return_value = {
             'EMAIL_ADDRESS_': '*****@*****.**',
             'EMAIL_FORMAT_': 'HTML',
             'COUNTRY_': 'us',
             'LANGUAGE_ISO2': 'en',
             'TOKEN': 'asdf',
             'CREATED_DATE_': 'Yesterday',
             'NEWSLETTER1_FLG': 'Y',
             'NEWSLETTER2_FLG': 'Y',
         }
         result = look_for_user(database='DUMMY', email='EMAIL',
                                token='TOKEN', fields=fields)
     expected_result = {
         'newsletters': [u'n1', u'n2'],
         'status': 'ok',
         'country': 'us',
         'lang': 'en',
         'token': 'asdf',
         'created-date': 'Yesterday',
         'email': '*****@*****.**',
         'format': 'HTML',
     }
     self.assertEqual(expected_result, result)
Example #2
0
 def test_unset_lang(self):
     """
     If lang is not set in ET, look_for_user returns '', not None.
     """
     # ET returns None if the database has NULL.
     Newsletter.objects.create(slug='n1', vendor_id='NEWSLETTER1')
     Newsletter.objects.create(slug='n2', vendor_id='NEWSLETTER2')
     fields = ['NEWSLETTER1_FLG', 'NEWSLETTER2_FLG']
     with patch('news.utils.sfmc') as sfmc_mock:
         sfmc_mock.get_row.return_value = {
             'EMAIL_ADDRESS_': '*****@*****.**',
             'EMAIL_FORMAT_': 'HTML',
             'COUNTRY_': 'us',
             'LANGUAGE_ISO2': None,
             'TOKEN': 'asdf',
             'CREATED_DATE_': 'Yesterday',
             'NEWSLETTER1_FLG': 'Y',
             'NEWSLETTER2_FLG': 'Y',
         }
         result = look_for_user(database='DUMMY', email='EMAIL',
                                token='TOKEN', fields=fields)
     expected_result = {
         'newsletters': [u'n1', u'n2'],
         'status': 'ok',
         'country': 'us',
         'lang': '',
         'token': 'asdf',
         'created-date': 'Yesterday',
         'email': '*****@*****.**',
         'format': 'HTML',
     }
     self.assertEqual(expected_result, result)
Example #3
0
 def test_unset_lang(self):
     """
     If lang is not set in ET, look_for_user returns '', not None.
     """
     # ET returns None if the database has NULL.
     Newsletter.objects.create(slug="n1", vendor_id="NEWSLETTER1")
     Newsletter.objects.create(slug="n2", vendor_id="NEWSLETTER2")
     fields = ["NEWSLETTER1_FLG", "NEWSLETTER2_FLG"]
     with patch("news.utils.ExactTargetDataExt") as et_ext:
         data_ext = et_ext()
         data_ext.get_record.return_value = {
             "EMAIL_ADDRESS_": "*****@*****.**",
             "EMAIL_FORMAT_": "HTML",
             "COUNTRY_": "us",
             "LANGUAGE_ISO2": None,
             "TOKEN": "asdf",
             "CREATED_DATE_": "Yesterday",
             "NEWSLETTER1_FLG": "Y",
             "NEWSLETTER2_FLG": "Y",
         }
         result = look_for_user(database="DUMMY", email="EMAIL", token="TOKEN", fields=fields)
     expected_result = {
         "newsletters": [u"n1", u"n2"],
         "status": "ok",
         "country": "us",
         "lang": "",
         "token": "asdf",
         "created-date": "Yesterday",
         "email": "*****@*****.**",
         "format": "HTML",
     }
     self.assertEqual(expected_result, result)