Esempio n. 1
0
 def test_get_sailthru_list(self, mock_sailthru_client):
     """Test fetch list data from sailthru"""
     mock_sailthru_client.api_get.return_value = \
         SailthruResponse(JsonResponse({'lists': [{'name': 'test1_user_list'}]}))
     self.assertEqual(
         _get_list_from_email_marketing_provider(mock_sailthru_client),
         {'test1_user_list': {
             'name': 'test1_user_list'
         }})
     mock_sailthru_client.api_get.assert_called_with("list", {})
Esempio n. 2
0
 def test_user_activation(self, mock_sailthru_get, mock_sailthru_post):
     """
     test send of activation template
     """
     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({}, self.user.email, new_user=True, activation=True)
     # look for call args for 2nd call
     self.assertEquals(mock_sailthru_post.call_args[0][0], "send")
     userparms = mock_sailthru_post.call_args[0][1]
     self.assertEquals(userparms['email'], TEST_EMAIL)
     self.assertEquals(userparms['template'], "Activation")
Esempio n. 3
0
 def test_add_user(self, mock_sailthru_get, mock_sailthru_post, mock_log_error):
     """
     test async method in tasks that actually updates Sailthru
     """
     site_dict = {'id': self.site.id, 'domain': self.site.domain, 'name': self.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': '******', 'activated': 1}, TEST_EMAIL, site_dict, new_user=True
     )
     self.assertFalse(mock_log_error.called)
     self.assertEquals(mock_sailthru_post.call_args[0][0], "user")
     userparms = mock_sailthru_post.call_args[0][1]
     self.assertEquals(userparms['key'], "email")
     self.assertEquals(userparms['id'], TEST_EMAIL)
     self.assertEquals(userparms['vars']['gender'], "m")
     self.assertEquals(userparms['vars']['username'], "test")
     self.assertEquals(userparms['vars']['activated'], 1)
     self.assertEquals(userparms['lists']['new list'], 1)
Esempio n. 4
0
    def test_drop_cookie_error_path(self, mock_sailthru):
        """
        test that error paths return no cookie
        """
        response = JsonResponse({
            "success": True,
            "redirect_url": 'test.com/test',
        })
        mock_sailthru.return_value = SailthruResponse(JsonResponse({'keys': {'cookiexx': 'test_cookie'}}))
        add_email_marketing_cookies(None, response=response, user=self.user)
        self.assertFalse('sailthru_hid' in response.cookies)

        mock_sailthru.return_value = SailthruResponse(JsonResponse({'error': "error", "errormsg": "errormsg"}))
        add_email_marketing_cookies(None, response=response, user=self.user)
        self.assertFalse('sailthru_hid' in response.cookies)

        mock_sailthru.side_effect = SailthruClientError
        add_email_marketing_cookies(None, response=response, user=self.user)
        self.assertFalse('sailthru_hid' in response.cookies)
Esempio n. 5
0
 def test_user_activation(self, mock_sailthru_get, mock_sailthru_post):
     """
     Test that welcome template not sent if not new user.
     """
     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({}, self.user.email, new_user=False)
     # look for call args for 2nd call
     self.assertEquals(mock_sailthru_post.call_args[0][0], "user")
     userparms = mock_sailthru_post.call_args[0][1]
     self.assertIsNone(userparms.get('email'))
     self.assertIsNone(userparms.get('template'))
Esempio n. 6
0
    def test_get_or_create_sailthru_list(self, mock_sailthru_client):
        """
        Test the task the create sailthru lists.
        """
        mock_sailthru_client.api_get.return_value = SailthruResponse(
            JsonResponse({'lists': []}))
        _get_or_create_user_list(mock_sailthru_client, 'test1_user_list')
        mock_sailthru_client.api_get.assert_called_with("list", {})
        mock_sailthru_client.api_post.assert_called_with(
            "list", {
                'list': 'test1_user_list',
                'primary': 0,
                'public_name': 'test1_user_list'
            })

        # test existing user list
        mock_sailthru_client.api_get.return_value = \
            SailthruResponse(JsonResponse({'lists': [{'name': 'test1_user_list'}]}))
        _get_or_create_user_list(mock_sailthru_client, 'test2_user_list')
        mock_sailthru_client.api_get.assert_called_with("list", {})
        mock_sailthru_client.api_post.assert_called_with(
            "list", {
                'list': 'test2_user_list',
                'primary': 0,
                'public_name': 'test2_user_list'
            })

        # test get error from Sailthru
        mock_sailthru_client.api_get.return_value = \
            SailthruResponse(JsonResponse({'error': 43, 'errormsg': 'Got an error'}))
        self.assertEqual(
            _get_or_create_user_list(mock_sailthru_client, 'test1_user_list'),
            None)

        # test post error from Sailthru
        mock_sailthru_client.api_post.return_value = \
            SailthruResponse(JsonResponse({'error': 43, 'errormsg': 'Got an error'}))
        mock_sailthru_client.api_get.return_value = SailthruResponse(
            JsonResponse({'lists': []}))
        self.assertEqual(
            _get_or_create_user_list(mock_sailthru_client, 'test2_user_list'),
            None)
Esempio n. 7
0
    def test_update_unenrolled_list(self, mock_sailthru_client):
        """
        test routine which updates the unenrolled list in Sailthru
        """

        # test a new unenroll
        mock_sailthru_client.api_get.return_value = \
            SailthruResponse(JsonResponse({'vars': {'unenrolled': ['course_u1']}}))
        self.assertTrue(_update_unenrolled_list(mock_sailthru_client, TEST_EMAIL,
                                                self.course_url, True))
        mock_sailthru_client.api_get.assert_called_with("user", {"id": TEST_EMAIL, "fields": {"vars": 1}})
        mock_sailthru_client.api_post.assert_called_with('user',
                                                         {'vars': {'unenrolled': ['course_u1', self.course_url]},
                                                          'id': TEST_EMAIL, 'key': 'email'})

        # test an enroll of a previously unenrolled course
        mock_sailthru_client.api_get.return_value = \
            SailthruResponse(JsonResponse({'vars': {'unenrolled': [self.course_url]}}))
        self.assertTrue(_update_unenrolled_list(mock_sailthru_client, TEST_EMAIL,
                                                self.course_url, False))
        mock_sailthru_client.api_post.assert_called_with('user',
                                                         {'vars': {'unenrolled': []},
                                                          'id': TEST_EMAIL, 'key': 'email'})

        # test get error from Sailthru
        mock_sailthru_client.api_get.return_value = \
            SailthruResponse(JsonResponse({'error': 43, 'errormsg': 'Got an error'}))
        self.assertFalse(_update_unenrolled_list(mock_sailthru_client, TEST_EMAIL,
                                                 self.course_url, False))

        # test post error from Sailthru
        mock_sailthru_client.api_post.return_value = \
            SailthruResponse(JsonResponse({'error': 43, 'errormsg': 'Got an error'}))
        mock_sailthru_client.api_get.return_value = \
            SailthruResponse(JsonResponse({'vars': {'unenrolled': [self.course_url]}}))
        self.assertFalse(_update_unenrolled_list(mock_sailthru_client, TEST_EMAIL,
                                                 self.course_url, False))

        # test exception
        mock_sailthru_client.api_get.side_effect = SailthruClientError
        self.assertFalse(_update_unenrolled_list(mock_sailthru_client, TEST_EMAIL,
                                                 self.course_url, False))
Esempio n. 8
0
 def test_create_sailthru_list(self, mock_sailthru_client):
     """Test create list in sailthru"""
     mock_sailthru_client.api_post.return_value = SailthruResponse(
         JsonResponse({'ok': True}))
     assert _create_user_list(mock_sailthru_client,
                              'test_list_name') is True
     assert mock_sailthru_client.api_post.call_args[0][0] == 'list'
     listparms = mock_sailthru_client.api_post.call_args[0][1]
     assert listparms['list'] == 'test_list_name'
     assert listparms['primary'] == 0
     assert listparms['public_name'] == 'test_list_name'
Esempio n. 9
0
 def test_create_sailthru_list(self, mock_sailthru_client):
     """Test create list in sailthru"""
     mock_sailthru_client.api_post.return_value = SailthruResponse(
         JsonResponse({'ok': True}))
     self.assertEqual(
         _create_user_list(mock_sailthru_client, 'test_list_name'), True)
     self.assertEqual(mock_sailthru_client.api_post.call_args[0][0], "list")
     listparms = mock_sailthru_client.api_post.call_args[0][1]
     self.assertEqual(listparms['list'], 'test_list_name')
     self.assertEqual(listparms['primary'], 0)
     self.assertEqual(listparms['public_name'], 'test_list_name')
Esempio n. 10
0
 def test_change_email(self, mock_sailthru):
     """
     test async method in task that changes email in Sailthru
     """
     mock_sailthru.return_value = SailthruResponse(JsonResponse({'ok': True}))
     update_user_email.delay(TEST_EMAIL, "*****@*****.**")
     self.assertEqual(mock_sailthru.call_args[0][0], "user")
     userparms = mock_sailthru.call_args[0][1]
     self.assertEqual(userparms['key'], "email")
     self.assertEqual(userparms['id'], "*****@*****.**")
     self.assertEqual(userparms['keys']['email'], TEST_EMAIL)
Esempio n. 11
0
    def test_error_logging(self, mock_sailthru, mock_log_error):
        """
        Ensure that error returned from Sailthru api is logged
        """
        mock_sailthru.return_value = SailthruResponse(JsonResponse({'error': 100, 'errormsg': 'Got an error'}))
        update_user_email.delay(self.user.username, "*****@*****.**")
        self.assertTrue(mock_log_error.called)

        mock_sailthru.side_effect = SailthruClientError
        update_user_email.delay(self.user.username, "*****@*****.**")
        self.assertTrue(mock_log_error.called)
Esempio n. 12
0
 def test_error_logging(self, mock_sailthru, mock_log_error):
     """
     Ensure that error returned from Sailthru api is logged
     """
     mock_sailthru.return_value = SailthruResponse(
         JsonResponse({
             'error': 100,
             'errormsg': 'Got an error'
         }))
     update_user.delay(self.user.username)
     self.assertTrue(mock_log_error.called)
Esempio n. 13
0
 def test_change_email(self, mock_sailthru):
     """
     test async method in task that changes email in Sailthru
     """
     mock_sailthru.return_value = SailthruResponse(
         JsonResponse({'ok': True}))
     update_user_email.delay(TEST_EMAIL, "*****@*****.**")
     assert mock_sailthru.call_args[0][0] == 'user'
     userparms = mock_sailthru.call_args[0][1]
     assert userparms['key'] == 'email'
     assert userparms['id'] == '*****@*****.**'
     assert userparms['keys']['email'] == TEST_EMAIL
 def test_user_activation(self, mock_sailthru):
     """
     test send of activation template
     """
     mock_sailthru.return_value = SailthruResponse(
         JsonResponse({'ok': True}))
     update_user.delay(self.user.username, new_user=True, activation=True)
     # look for call args for 2nd call
     self.assertEquals(mock_sailthru.call_args[0][0], "send")
     userparms = mock_sailthru.call_args[0][1]
     self.assertEquals(userparms['email'], TEST_EMAIL)
     self.assertEquals(userparms['template'], "Activation")
Esempio n. 15
0
 def test_email_not_sent_to_enterprise_learners(self, mock_sailthru_post):
     """
     tests that welcome email is not sent to the enterprise learner
     """
     mock_sailthru_post.return_value = SailthruResponse(
         JsonResponse({'ok': True}))
     update_user.delay(sailthru_vars={
         'is_enterprise_learner': True,
         'enterprise_name': 'test name',
     },
                       email=self.user.email)
     self.assertNotEqual(mock_sailthru_post.call_args[0][0], "send")
Esempio n. 16
0
 def test_update_user_error_nonretryable(self, mock_sailthru,
                                         mock_log_error, mock_retry):
     """
     Ensure that non-retryable error is not retried
     """
     mock_sailthru.return_value = SailthruResponse(
         JsonResponse({
             'error': 1,
             'errormsg': 'Got an error'
         }))
     update_user.delay({}, self.user.email)
     self.assertTrue(mock_log_error.called)
     self.assertFalse(mock_retry.called)
Esempio n. 17
0
    def test_get_course_content(self, mock_sailthru_client):
        """
        test routine which fetches data from Sailthru content api
        """
        mock_sailthru_client.api_get.return_value = SailthruResponse(JsonResponse({"title": "The title"}))
        response_json = _get_course_content('course:123', mock_sailthru_client, EmailMarketingConfiguration.current())
        self.assertEquals(response_json, {"title": "The title"})
        mock_sailthru_client.api_get.assert_called_with('content', {'id': 'course:123'})

        # test second call uses cache
        response_json = _get_course_content('course:123', mock_sailthru_client, EmailMarketingConfiguration.current())
        self.assertEquals(response_json, {"title": "The title"})
        mock_sailthru_client.api_get.assert_not_called()

        # test error from Sailthru
        mock_sailthru_client.api_get.return_value = \
            SailthruResponse(JsonResponse({'error': 100, 'errormsg': 'Got an error'}))
        self.assertEquals(_get_course_content('course:124', mock_sailthru_client, EmailMarketingConfiguration.current()), {})

        # test exception
        mock_sailthru_client.api_get.side_effect = SailthruClientError
        self.assertEquals(_get_course_content('course:125', mock_sailthru_client, EmailMarketingConfiguration.current()), {})
Esempio n. 18
0
 def test_update_user_error_retryable(self, mock_sailthru, mock_log_error,
                                      mock_retry):
     """
     Ensure that retryable error is retried
     """
     mock_sailthru.return_value = SailthruResponse(
         JsonResponse({
             'error': 43,
             'errormsg': 'Got an error'
         }))
     update_user.delay({}, self.user.email)
     assert mock_log_error.called
     assert mock_retry.called
Esempio n. 19
0
    def test_update_user_error_logging(self, mock_sailthru, mock_log_error):
        """
        Ensure that error returned from Sailthru api is logged
        """
        mock_sailthru.return_value = SailthruResponse(
            JsonResponse({
                'error': 100,
                'errormsg': 'Got an error'
            }))
        update_user.delay({}, self.user.email)
        self.assertTrue(mock_log_error.called)

        # force Sailthru API exception
        mock_log_error.reset_mock()
        mock_sailthru.side_effect = SailthruClientError
        update_user.delay({}, self.user.email, self.site_domain)
        self.assertTrue(mock_log_error.called)

        # force Sailthru API exception on 2nd call
        mock_log_error.reset_mock()
        mock_sailthru.side_effect = [
            SailthruResponse(JsonResponse({'ok': True})), SailthruClientError
        ]
        update_user.delay({}, self.user.email, activation=True)
        self.assertTrue(mock_log_error.called)

        # force Sailthru API error return on 2nd call
        mock_log_error.reset_mock()
        mock_sailthru.side_effect = [
            SailthruResponse(JsonResponse({'ok': True})),
            SailthruResponse(
                JsonResponse({
                    'error': 100,
                    'errormsg': 'Got an error'
                }))
        ]
        update_user.delay({}, self.user.email, activation=True)
        self.assertTrue(mock_log_error.called)
Esempio n. 20
0
 def test_user_activation(self, mock_sailthru_get, mock_sailthru_post):
     """
     test send of activation template
     """
     mock_sailthru_post.return_value = SailthruResponse(
         JsonResponse({'ok': True}))
     mock_sailthru_get.return_value = SailthruResponse(
         JsonResponse({
             'lists': [{
                 'name': 'new list'
             }],
             'ok': True
         }))
     expected_schedule = datetime.datetime.utcnow() + datetime.timedelta(
         seconds=600)
     update_user.delay({}, self.user.email, new_user=True, activation=True)
     # look for call args for 2nd call
     self.assertEquals(mock_sailthru_post.call_args[0][0], "send")
     userparms = mock_sailthru_post.call_args[0][1]
     self.assertEquals(userparms['email'], TEST_EMAIL)
     self.assertEquals(userparms['template'], "Activation")
     self.assertEquals(userparms['schedule_time'],
                       expected_schedule.strftime('%Y-%m-%dT%H:%M:%SZ'))
Esempio n. 21
0
 def test_modify_field_with_sso(self, send_welcome_email, mock_get_current_request,
                                mock_pipeline_get, mock_registry_get_from_pipeline, mock_sailthru_post):
     """
     Test that welcome email is sent appropriately in the context of SSO registration
     """
     mock_get_current_request.return_value = self.request
     mock_pipeline_get.return_value = 'saml-idp'
     mock_registry_get_from_pipeline.return_value = Mock(send_welcome_email=send_welcome_email)
     mock_sailthru_post.return_value = SailthruResponse(JsonResponse({'ok': True}))
     email_marketing_user_field_changed(None, self.user, table='auth_user', setting='is_active', new_value=True)
     if send_welcome_email:
         self.assertEqual(mock_sailthru_post.call_args[0][0], "send")
     else:
         self.assertNotEqual(mock_sailthru_post.call_args[0][0], "send")
Esempio n. 22
0
 def test_add_user_list_existing_domain(self, mock_sailthru_get,
                                        mock_sailthru_post):
     """
     test non existing domain name updates Sailthru user lists with default list
     """
     # Set template to empty string to disable 2nd post call to Sailthru
     update_email_marketing_config(template='')
     existing_site = Site.objects.create(domain='testing.com',
                                         name='testing.com')
     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': '******',
         '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)
Esempio n. 23
0
 def test_add_user(self, mock_sailthru_get, mock_sailthru_post,
                   mock_log_error):
     """
     test async method in tasks that actually updates Sailthru
     """
     site_dict = {
         'id': self.site.id,
         'domain': self.site.domain,
         'name': self.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': '******',
         'activated': 1
     },
                       TEST_EMAIL,
                       site_dict,
                       new_user=True)
     assert not mock_log_error.called
     assert mock_sailthru_post.call_args[0][0] == 'user'
     userparms = mock_sailthru_post.call_args[0][1]
     assert userparms['key'] == 'email'
     assert userparms['id'] == TEST_EMAIL
     assert userparms['vars']['gender'] == 'm'
     assert userparms['vars']['username'] == 'test'
     assert userparms['vars']['activated'] == 1
     assert userparms['lists']['new list'] == 1
Esempio n. 24
0
 def test_add_user(self, mock_sailthru, mock_log_error):
     """
     test async method in tasks that actually updates Sailthru
     """
     mock_sailthru.return_value = SailthruResponse(JsonResponse({'ok': True}))
     update_user.delay({'gender': 'm', 'username': '******', 'activated': 1}, TEST_EMAIL, new_user=True)
     self.assertFalse(mock_log_error.called)
     self.assertEquals(mock_sailthru.call_args[0][0], "user")
     userparms = mock_sailthru.call_args[0][1]
     self.assertEquals(userparms['key'], "email")
     self.assertEquals(userparms['id'], TEST_EMAIL)
     self.assertEquals(userparms['vars']['gender'], "m")
     self.assertEquals(userparms['vars']['username'], "test")
     self.assertEquals(userparms['vars']['activated'], 1)
     self.assertEquals(userparms['lists']['new list'], 1)
    def test_update_user_error_logging(self, mock_sailthru, mock_log_error):
        """
        Ensure that error returned from Sailthru api is logged
        """
        mock_sailthru.return_value = SailthruResponse(
            JsonResponse({
                'error': 100,
                'errormsg': 'Got an error'
            }))
        update_user.delay(self.user.username)
        self.assertTrue(mock_log_error.called)

        # force Sailthru API exception
        mock_sailthru.side_effect = SailthruClientError
        update_user.delay(self.user.username)
        self.assertTrue(mock_log_error.called)

        # force Sailthru API exception on 2nd call
        mock_sailthru.side_effect = [None, SailthruClientError]
        mock_sailthru.return_value = SailthruResponse(
            JsonResponse({'ok': True}))
        update_user.delay(self.user.username, new_user=True)
        self.assertTrue(mock_log_error.called)

        # force Sailthru API error return on 2nd call
        mock_sailthru.side_effect = None
        mock_sailthru.return_value = [
            SailthruResponse(JsonResponse({'ok': True})),
            SailthruResponse(
                JsonResponse({
                    'error': 100,
                    'errormsg': 'Got an error'
                }))
        ]
        update_user.delay(self.user.username, new_user=True)
        self.assertTrue(mock_log_error.called)
Esempio n. 26
0
 def test_add_user(self, mock_sailthru_get, mock_sailthru_post,
                   mock_log_error):
     """
     test async method in tasks that actually updates Sailthru and send Welcome template.
     """
     site_dict = {
         'id': self.site.id,
         'domain': self.site.domain,
         'name': self.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': '******',
         'activated': 1
     },
                       TEST_EMAIL,
                       site_dict,
                       new_user=True)
     expected_schedule = datetime.datetime.utcnow() + datetime.timedelta(
         seconds=600)
     self.assertFalse(mock_log_error.called)
     self.assertEquals(mock_sailthru_post.call_args[0][0], "send")
     userparms = mock_sailthru_post.call_args[0][1]
     self.assertEquals(userparms['email'], TEST_EMAIL)
     self.assertEquals(userparms['template'], "Welcome")
     self.assertEquals(userparms['schedule_time'],
                       expected_schedule.strftime('%Y-%m-%dT%H:%M:%SZ'))
Esempio n. 27
0
 def test_sailthru_with_email_changed(self, mock_sailthru, mock_log_error):
     mock_sailthru.return_value = SailthruResponse(JsonResponse({'ok': True}))
     force_unsubscribe_all(sender=self.__class__, email=self.user.email, new_email='*****@*****.**')
     mock_sailthru.assert_called_with("user", {
         "id": self.user.email,
         "optout_email": "all",
         "keys": {
             "email": "*****@*****.**"
         },
         "fields": {
             "optout_email": 1,
             "keys": 1
         },
         "keysconflict": "merge"
     })
     self.assertFalse(mock_log_error.called)
Esempio n. 28
0
    def test_drop_cookie(self, mock_sailthru, mock_get_current_request):
        """
        Test add_email_marketing_cookies
        """
        response = JsonResponse({
            "success": True,
            "redirect_url": 'test.com/test',
        })
        self.request.COOKIES['anonymous_interest'] = 'cookie_content'
        mock_get_current_request.return_value = self.request

        cookies = {'cookie': 'test_cookie'}
        mock_sailthru.return_value = SailthruResponse(
            JsonResponse({'keys': cookies}))

        with LogCapture(LOGGER_NAME, level=logging.INFO) as logger:
            add_email_marketing_cookies(None,
                                        response=response,
                                        user=self.user)
            logger.check((
                LOGGER_NAME, 'INFO',
                'Started at {start} and ended at {end}, time spent:{delta} milliseconds'
                .format(start=datetime.datetime.now().isoformat(' '),
                        end=datetime.datetime.now().isoformat(' '),
                        delta=0)
            ), (LOGGER_NAME, 'INFO',
                'sailthru_hid cookie:{cookies[cookie]} successfully retrieved for user {user}'
                .format(cookies=cookies, user=TEST_EMAIL)))
        mock_sailthru.assert_called_with(
            'user', {
                'fields': {
                    'keys': 1
                },
                'cookies': {
                    'anonymous_interest': 'cookie_content'
                },
                'id': TEST_EMAIL,
                'vars': {
                    'last_login_date': ANY
                }
            })
        self.assertTrue('sailthru_hid' in response.cookies)
        self.assertEquals(response.cookies['sailthru_hid'].value,
                          "test_cookie")
Esempio n. 29
0
 def test_drop_cookie(self, mock_sailthru, mock_get_current_request):
     """
     Test add_email_marketing_cookies
     """
     response = JsonResponse({
         "success": True,
         "redirect_url": 'test.com/test',
     })
     self.request.COOKIES['sailthru_content'] = 'cookie_content'
     mock_get_current_request.return_value = self.request
     mock_sailthru.return_value = SailthruResponse(JsonResponse({'keys': {'cookie': 'test_cookie'}}))
     add_email_marketing_cookies(None, response=response, user=self.user)
     mock_sailthru.assert_called_with('user',
                                      {'fields': {'keys': 1},
                                       'cookies': {'sailthru_content': 'cookie_content'},
                                       'id': TEST_EMAIL,
                                       'vars': {'last_login_date': ANY}})
     self.assertTrue('sailthru_hid' in response.cookies)
     self.assertEquals(response.cookies['sailthru_hid'].value, "test_cookie")
Esempio n. 30
0
    def test_get_cookies_via_sailthu(self, mock_sailthru):

        cookies = {'cookie': 'test_cookie'}
        mock_sailthru.return_value = SailthruResponse(JsonResponse({'keys': cookies}))

        post_parms = {
            'id': self.user.email,
            'fields': {'keys': 1},
            'vars': {'last_login_date': datetime.datetime.now().strftime("%Y-%m-%d")},
            'cookies': {'anonymous_interest': 'cookie_content'}
        }
        expected_cookie = get_email_cookies_via_sailthru.delay(self.user.email, post_parms)

        mock_sailthru.assert_called_with('user',
                                         {'fields': {'keys': 1},
                                          'cookies': {'anonymous_interest': 'cookie_content'},
                                          'id': TEST_EMAIL,
                                          'vars': {'last_login_date': ANY}})

        self.assertEqual(cookies['cookie'], expected_cookie.result)