Commit 5903ec5b by Usman Khalid

Merge pull request #3417 from edx/usman/lms2518-refund-emails

Parameter from_email to send_mail() should be string
parents c51f7378 e33e9ff2
......@@ -478,19 +478,19 @@ class CertificateItem(OrderItem):
user_email=course_enrollment.user.email,
order_number=order_number)
to_email = [settings.PAYMENT_SUPPORT_EMAIL]
from_email = [microsite.get_value(
'payment_support_email',
settings.PAYMENT_SUPPORT_EMAIL
)]
from_email = microsite.get_value('payment_support_email', settings.PAYMENT_SUPPORT_EMAIL)
try:
send_mail(subject, message, from_email, to_email, fail_silently=False)
except (smtplib.SMTPException, BotoServerError):
err_str = 'Failed sending email to billing request a refund for verified certiciate (User {user}, Course {course}, CourseEnrollmentID {ce_id}, Order #{order})'
except Exception as exception: # pylint: disable=broad-except
err_str = ('Failed sending email to billing to request a refund for verified certificate'
' (User {user}, Course {course}, CourseEnrollmentID {ce_id}, Order #{order})\n{exception}')
log.error(err_str.format(
user=course_enrollment.user,
course=course_enrollment.course_id,
ce_id=course_enrollment.id,
order=order_number))
order=order_number,
exception=exception,
))
return target_cert
......
......@@ -405,6 +405,33 @@ class CertificateItemTest(ModuleStoreTestCase):
self.assertTrue(target_certs[0].refund_requested_time)
self.assertEquals(target_certs[0].order.status, 'refunded')
def test_refund_cert_callback_before_expiration_email(self):
""" Test that refund emails are being sent correctly. """
course_id = "refund_before_expiration/test/one"
many_days = datetime.timedelta(days=60)
CourseFactory.create(org='refund_before_expiration', number='test', run='course', display_name='one')
course_mode = CourseMode(course_id=course_id,
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_id, 'verified')
cart = Order.get_cart_for_user(user=self.user)
CertificateItem.add_to_order(cart, course_id, self.cost, 'verified')
cart.purchase()
mail.outbox = []
with patch('shoppingcart.models.log.error') as mock_error_logger:
CourseEnrollment.unenroll(self.user, course_id)
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)
@patch('shoppingcart.models.log.error')
def test_refund_cert_callback_before_expiration_email_error(self, error_logger):
# If there's an error sending an email to billing, we need to log this error
......@@ -426,7 +453,7 @@ class CertificateItemTest(ModuleStoreTestCase):
with patch('shoppingcart.models.send_mail', side_effect=smtplib.SMTPException):
CourseEnrollment.unenroll(self.user, course_id)
self.assertTrue(error_logger.called)
self.assertTrue(error_logger.call_args[0][0].startswith('Failed sending email'))
def test_refund_cert_callback_after_expiration(self):
# If the expiration date has passed, the user cannot get a refund
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment