예제 #1
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)
예제 #2
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)
     self.assertTrue(mock_log_error.called)
     self.assertTrue(mock_retry.called)
예제 #3
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)
예제 #4
0
def update_email_marketing_user_with_enterprise_flag(sender, instance, **kwargs):  # pylint: disable=unused-argument, invalid-name
    """
    Enable the is_enterprise_learner flag in SailThru vars.
    """
    user = User.objects.get(id=instance.user_id)

    # perform update asynchronously
    update_user.delay(sailthru_vars={'is_enterprise_learner': True}, email=user.email)
예제 #5
0
 def test_add_user_list_not_called_on_white_label_domain(self, mock_sailthru_post):
     """
     test user is not added to Sailthru user lists if registered from a whitel labe site
     """
     existing_site = Site.objects.create(domain='testwhitelabel.com', name='White Label')
     site_dict = {'id': existing_site.id, 'domain': existing_site.domain, 'name': existing_site.name}
     update_user.delay(
         {'gender': 'm', 'username': '******', 'activated': 1}, TEST_EMAIL, site=site_dict, new_user=True
     )
     self.assertFalse(mock_sailthru_post.called)
예제 #6
0
    def test_update_user_error_logging_bad_user(self, mock_sailthru, mock_log_error):
        """
        Test update_user with invalid user
        """
        update_user.delay("baduser")
        self.assertTrue(mock_log_error.called)
        self.assertFalse(mock_sailthru.called)

        update_user_email.delay("baduser", "*****@*****.**")
        self.assertTrue(mock_log_error.called)
        self.assertFalse(mock_sailthru.called)
예제 #7
0
 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")
예제 #8
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")
예제 #9
0
 def test_just_return(self, mock_sailthru, mock_log_error):
     """
     Ensure that disabling Sailthru just returns
     """
     update_email_marketing_config(enabled=False)
     update_user.delay(self.user.username)
     self.assertFalse(mock_log_error.called)
     self.assertFalse(mock_sailthru.called)
     update_user_email.delay(self.user.username, "*****@*****.**")
     self.assertFalse(mock_log_error.called)
     self.assertFalse(mock_sailthru.called)
     update_email_marketing_config(enabled=True)
예제 #10
0
 def test_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")
예제 #11
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")
예제 #12
0
def update_email_marketing_user_with_enterprise_vars(sender, instance,
                                                     **kwargs):  # pylint: disable=unused-argument, invalid-name
    """
    Update the SailThru user with enterprise-related vars.
    """
    user = User.objects.get(id=instance.user_id)

    # perform update asynchronously
    update_user.delay(sailthru_vars={
        'is_enterprise_learner': True,
        'enterprise_name': instance.enterprise_customer.name,
    },
                      email=user.email)
예제 #13
0
 def test_email_not_sent_to_white_label(self, mock_sailthru_get, mock_sailthru_post, mock_log_error):
     """
     tests that welcome email is not sent to the white-label site learner
     """
     white_label_site = Site.objects.create(domain='testwhitelabel.com', name='White Label')
     site_dict = {'id': white_label_site.id, 'domain': white_label_site.domain, 'name': white_label_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.assertNotEqual(mock_sailthru_post.call_args[0][0], "send")
예제 #14
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")
예제 #15
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)
예제 #16
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.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)
예제 #17
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'))
예제 #18
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)
예제 #19
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"))
예제 #20
0
def update_email_marketing_user_with_enterprise_vars(sender, instance, **kwargs):  # pylint: disable=unused-argument, invalid-name
    """
    Update the SailThru user with enterprise-related vars.
    """
    user = User.objects.get(id=instance.user_id)

    # perform update asynchronously
    update_user.delay(
        sailthru_vars={
            'is_enterprise_learner': True,
            'enterprise_name': instance.enterprise_customer.name,
        },
        email=user.email
    )
예제 #21
0
    def test_just_return_tasks(self, mock_sailthru, mock_log_error):
        """
        Ensure that disabling Sailthru just returns
        """
        update_email_marketing_config(enabled=False)

        update_user.delay(self.user.username)
        self.assertFalse(mock_log_error.called)
        self.assertFalse(mock_sailthru.called)

        update_user_email.delay(self.user.username, "*****@*****.**")
        self.assertFalse(mock_log_error.called)
        self.assertFalse(mock_sailthru.called)

        update_email_marketing_config(enabled=True)
예제 #22
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)
예제 #23
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(self.user.username, 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)
예제 #24
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
     """
     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)
예제 #25
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
     """
     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)
예제 #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
     """
     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)
예제 #27
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")
예제 #28
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)
예제 #29
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'))
예제 #30
0
    def test_just_return_tasks(self, mock_sailthru, mock_log_error):
        """
        Ensure that disabling Sailthru just returns
        """
        update_email_marketing_config(enabled=False)

        update_user.delay(self.user.username)
        self.assertFalse(mock_log_error.called)
        self.assertFalse(mock_sailthru.called)

        update_user_email.delay(self.user.username, "*****@*****.**")
        self.assertFalse(mock_log_error.called)
        self.assertFalse(mock_sailthru.called)

        update_course_enrollment.delay(self.user.username, TEST_EMAIL, 'http://course',
                                       EnrollStatusChange.enroll, 'audit')
        self.assertFalse(mock_log_error.called)
        self.assertFalse(mock_sailthru.called)

        update_email_marketing_config(enabled=True)
예제 #31
0
 def test_add_user_list_not_called_on_white_label_domain(
         self, mock_sailthru_post):
     """
     test user is not added to Sailthru user lists if registered from a whitel labe site
     """
     existing_site = Site.objects.create(domain='testwhitelabel.com',
                                         name='White Label')
     site_dict = {
         'id': existing_site.id,
         'domain': existing_site.domain,
         'name': existing_site.name
     }
     update_user.delay({
         'gender': 'm',
         'username': '******',
         'activated': 1
     },
                       TEST_EMAIL,
                       site=site_dict,
                       new_user=True)
     self.assertFalse(mock_sailthru_post.called)
예제 #32
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'))
    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)