'Test that refund emails are being sent correctly.'

@patch('student.models.CourseEnrollment.refund_cutoff_date')
def test_refund_cert_callback_before_expiration_email(self, cutoff_date):

    course = CourseFactory.create()
    course_key = course.id
    many_days = datetime.timedelta(days=60)
    course_mode = CourseMode(course_id=course_key, mode_slug='verified', mode_display_name='verified    cert', min_price=self.cost, expiration_datetime=(datetime.datetime.now(pytz.utc) + many_days))
    course_mode.save()
    CourseEnrollment.enroll(self.user, course_key, 'verified')
    cart = Order.get_cart_for_user(user=self.user)
    CertificateItem.add_to_order(cart, course_key, self.cost, 'verified')
    cart.purchase()
    mail.outbox = []
    cutoff_date.return_value = (datetime.datetime.now(pytz.UTC) + datetime.timedelta(days=1))
    with patch('shoppingcart.models.log.error') as mock_error_logger:
        CourseEnrollment.unenroll(self.user, course_key)
        self.assertFalse(mock_error_logger.called)
        self.assertEquals(len(mail.outbox), 1)
        self.assertEquals('[Refund]    User-Requested    Refund', mail.outbox[0].subject)
        self.assertEquals(settings.PAYMENT_SUPPORT_EMAIL, mail.outbox[0].from_email)
        self.assertIn('has    requested    a    refund    on    Order', mail.outbox[0].body)
