ENT-4095: Handle coupon expiration date scenario in LMS (#27539)

This commit is contained in:
Sameen Fatima
2021-05-19 12:47:11 +05:00
committed by GitHub
parent a3d1d1b87f
commit 9f2a72ad08
10 changed files with 193 additions and 32 deletions

View File

@@ -97,6 +97,8 @@ def refund_order_voucher(sender, course_enrollment, skip_refund=False, **kwargs)
return
if not course_enrollment.refundable():
return
if not course_enrollment.is_order_voucher_refundable():
return
if not EnterpriseCourseEnrollment.objects.filter(
enterprise_customer_user__user_id=course_enrollment.user_id,
course_id=str(course_enrollment.course.id)

View File

@@ -133,28 +133,42 @@ class EnterpriseSupportSignals(SharedModuleStoreTestCase):
return enrollment
@patch('common.djangoapps.student.models.CourseEnrollment.is_order_voucher_refundable')
@ddt.data(
(True, True, 2, False), # test if skip_refund
(False, True, 20, False), # test refundable time passed
(False, False, 2, False), # test not enterprise enrollment
(False, True, 2, True), # success: no skip_refund, is enterprise enrollment and still in refundable window.
(True, True, 2, True, False), # test if skip_refund
(False, True, 20, True, False), # test refundable time passed
(False, False, 2, True, False), # test not enterprise enrollment
(False, True, 2, False, False), # test order voucher expiration date has already passed
(False, True, 2, True, True), # success: no skip_refund, is enterprise enrollment, coupon voucher is refundable
# and is still in refundable window.
)
@ddt.unpack
def test_refund_order_voucher(self, skip_refund, enterprise_enrollment_exists, no_of_days_placed, api_called):
def test_refund_order_voucher(
self,
skip_refund,
enterprise_enrollment_exists,
no_of_days_placed,
order_voucher_refundable,
api_called,
mock_is_order_voucher_refundable
):
"""Test refund_order_voucher signal"""
mock_is_order_voucher_refundable.return_value = order_voucher_refundable
enrollment = self._create_enrollment_to_refund(no_of_days_placed, enterprise_enrollment_exists)
with patch('openedx.features.enterprise_support.signals.ecommerce_api_client') as mock_ecommerce_api_client:
enrollment.update_enrollment(is_active=False, skip_refund=skip_refund)
assert mock_ecommerce_api_client.called == api_called
@patch('common.djangoapps.student.models.CourseEnrollment.is_order_voucher_refundable')
@ddt.data(
(HttpClientError, 'INFO'),
(HttpServerError, 'ERROR'),
(Exception, 'ERROR'),
)
@ddt.unpack
def test_refund_order_voucher_with_client_errors(self, mock_error, log_level):
def test_refund_order_voucher_with_client_errors(self, mock_error, log_level, mock_is_order_voucher_refundable):
"""Test refund_order_voucher signal client_error"""
mock_is_order_voucher_refundable.return_value = True
enrollment = self._create_enrollment_to_refund()
with patch('openedx.features.enterprise_support.signals.ecommerce_api_client') as mock_ecommerce_api_client:
client_instance = mock_ecommerce_api_client.return_value