def test_not_authorized_warning(self, mock_log_warning): """ Ensure that expected authorization issues are logged as warnings. """ with mock_create_refund(status=403): refund_seat(self.course_enrollment, UserFactory()) self.assertTrue(mock_log_warning.called)
def test_notification_no_refund(self, mock_send_notification): """ Ensure the notification function is NOT triggered when no refunds are initiated """ with mock_create_refund(status=200, response=[]): self.send_signal() self.assertFalse(mock_send_notification.called)
def test_notification(self, mock_send_notification): """ Ensure the notification function is triggered when refunds are initiated """ with mock_create_refund(status=200, response=[1, 2, 3]): self.send_signal() self.assertTrue(mock_send_notification.called)
def test_error_logging(self, mock_log_exception): """ Ensure that unexpected Exceptions are logged as errors (but do not break program flow). """ with mock_create_refund(status=500): self.send_signal() self.assertTrue(mock_log_exception.called)
def test_notification_error(self, mock_log_warning, mock_send_notification): """ Ensure an error occuring during notification does not break program flow, but a warning is logged. """ with mock_create_refund(status=200, response=[1, 2, 3]): self.send_signal() self.assertTrue(mock_send_notification.called) self.assertTrue(mock_log_warning.called)
def test_notification_not_verified(self, mode, mock_send_notification): """ Ensure the notification function is NOT triggered when the unenrollment is for any mode other than verified (i.e. any mode other than one for which refunds are presently supported). See the TODO associated with XCOM-371 in the signals module in the commerce package for more information. """ self.course_enrollment.mode = mode with mock_create_refund(status=200, response=[1, 2, 3]): self.send_signal() self.assertFalse(mock_send_notification.called)
def test_notification_if_automatic_approval_disabled(self, mock_send_notification): """ Ensure the notification is always sent if the automatic approval functionality is disabled. """ refund_id = 1 self.config.enable_automatic_refund_approval = False self.config.save() with mock_create_refund(status=201, response=[refund_id]): self.send_signal() self.assertTrue(mock_send_notification.called) mock_send_notification.assert_called_with(self.course_enrollment, [refund_id])
def test_no_notification_after_approval(self, mock_send_notification): """ Ensure the notification function is triggered when refunds are initiated, and cannot be automatically approved. """ refund_id = 1 with mock_create_refund(status=201, response=[refund_id]): with mock_process_refund(refund_id, reset_on_exit=False): self.send_signal() self.assertFalse(mock_send_notification.called) last_request = httpretty.last_request() self.assertDictEqual(json.loads(last_request.body), {'action': 'approve_payment_only'})
def test_notification_when_approval_fails(self, mock_send_notification): """ Ensure the notification function is triggered when refunds are initiated, and cannot be automatically approved. """ refund_id = 1 failed_refund_id = 2 with mock_create_refund(status=201, response=[refund_id, failed_refund_id]): with mock_process_refund(refund_id, reset_on_exit=False): with mock_process_refund(failed_refund_id, status=500, reset_on_exit=False): self.send_signal() self.assertTrue(mock_send_notification.called) mock_send_notification.assert_called_with(self.course_enrollment, [failed_refund_id])
def test_notification_if_automatic_approval_disabled( self, mock_send_notification): """ Ensure the notification is always sent if the automatic approval functionality is disabled. """ refund_id = 1 self.config.enable_automatic_refund_approval = False self.config.save() with mock_create_refund(status=201, response=[refund_id]): self.send_signal() self.assertTrue(mock_send_notification.called) mock_send_notification.assert_called_with(self.course_enrollment, [refund_id])
def test_notification_when_approval_fails(self, mock_send_notification): """ Ensure the notification function is triggered when refunds are initiated, and cannot be automatically approved. """ refund_id = 1 failed_refund_id = 2 with mock_create_refund(status=201, response=[refund_id, failed_refund_id]): with mock_process_refund(refund_id, reset_on_exit=False): with mock_process_refund(failed_refund_id, status=500, reset_on_exit=False): self.send_signal() self.assertTrue(mock_send_notification.called) mock_send_notification.assert_called_with( self.course_enrollment, [failed_refund_id])