def test_error_logging1(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)
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)
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.assertEquals(mock_sailthru.call_args[0][0], "user") userparms = mock_sailthru.call_args[0][1] self.assertEquals(userparms['key'], "email") self.assertEquals(userparms['id'], "*****@*****.**") self.assertEquals(userparms['keys']['email'], TEST_EMAIL)
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)
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(self.user.username, "*****@*****.**") 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"], "*****@*****.**") self.assertEquals(userparms["keys"]["email"], TEST_EMAIL)
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)
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)
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)
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)
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)