diff --git a/lms/djangoapps/instructor/tests/test_ecommerce.py b/lms/djangoapps/instructor/tests/test_ecommerce.py
index 8cb4b1435a..dcfcc253b8 100644
--- a/lms/djangoapps/instructor/tests/test_ecommerce.py
+++ b/lms/djangoapps/instructor/tests/test_ecommerce.py
@@ -84,7 +84,7 @@ class TestECommerceDashboardViews(ModuleStoreTestCase):
data = {
'code': 'A2314', 'course_id': self.course.id.to_deprecated_string(),
- 'description': 'asdsasda', 'created_by': self.instructor, 'discount': 111
+ 'description': 'asdsasda', 'created_by': self.instructor, 'discount': 99
}
response = self.client.post(add_coupon_url, data)
self.assertTrue("coupon with the coupon code ({code}) already exist".format(code='A2314') in response.content)
@@ -94,6 +94,17 @@ class TestECommerceDashboardViews(ModuleStoreTestCase):
self.assertTrue('
A2314
' in response.content)
self.assertFalse('
111
' in response.content)
+ data = {
+ 'code': 'A2345314', 'course_id': self.course.id.to_deprecated_string(),
+ 'description': 'asdsasda', 'created_by': self.instructor, 'discount': 199
+ }
+ response = self.client.post(add_coupon_url, data)
+ self.assertTrue("Please Enter the Coupon Discount Value Less than or Equal to 100" in response.content)
+
+ data['discount'] = '25%'
+ response = self.client.post(add_coupon_url, data=data)
+ self.assertTrue('Please Enter the Integer Value for Coupon Discount' in response.content)
+
def test_delete_coupon(self):
"""
Test Delete Coupon Scenarios. Handle all the HttpResponses return by remove_coupon view
@@ -179,6 +190,15 @@ class TestECommerceDashboardViews(ModuleStoreTestCase):
response = self.client.post(update_coupon_url, data=data)
self.assertTrue('coupon with the coupon id ({coupon_id}) DoesNotExist'.format(coupon_id=1000) in response.content)
+ data['coupon_id'] = coupon.id
+ data['discount'] = 123
+ response = self.client.post(update_coupon_url, data=data)
+ self.assertTrue('Please Enter the Coupon Discount Value Less than or Equal to 100' in response.content)
+
+ data['discount'] = '25%'
+ response = self.client.post(update_coupon_url, data=data)
+ self.assertTrue('Please Enter the Integer Value for Coupon Discount' in response.content)
+
data['coupon_id'] = '' # Coupon id is not provided
response = self.client.post(update_coupon_url, data=data)
self.assertTrue('coupon id not found' in response.content)
diff --git a/lms/djangoapps/instructor/views/coupons.py b/lms/djangoapps/instructor/views/coupons.py
index 7251e470c5..2b0650d31b 100644
--- a/lms/djangoapps/instructor/views/coupons.py
+++ b/lms/djangoapps/instructor/views/coupons.py
@@ -61,7 +61,12 @@ def add_coupon(request, course_id): # pylint: disable=W0613
description = request.POST.get('description')
course_id = request.POST.get('course_id')
- discount = request.POST.get('discount')
+ try:
+ discount = int(request.POST.get('discount'))
+ except ValueError:
+ return HttpResponseNotFound(_("Please Enter the Integer Value for Coupon Discount"))
+ if discount > 100:
+ return HttpResponseNotFound(_("Please Enter the Coupon Discount Value Less than or Equal to 100"))
coupon = Coupon(
code=code, description=description, course_id=course_id,
percentage_discount=discount, created_by_id=request.user.id
@@ -93,7 +98,12 @@ def update_coupon(request, course_id): # pylint: disable=W0613
description = request.POST.get('description')
course_id = request.POST.get('course_id')
- discount = request.POST.get('discount')
+ try:
+ discount = int(request.POST.get('discount'))
+ except ValueError:
+ return HttpResponseNotFound(_("Please Enter the Integer Value for Coupon Discount"))
+ if discount > 100:
+ return HttpResponseNotFound(_("Please Enter the Coupon Discount Value Less than or Equal to 100"))
coupon.code = code
coupon.description = description
coupon.course_id = course_id
diff --git a/lms/templates/instructor/instructor_dashboard_2/add_coupon_modal.html b/lms/templates/instructor/instructor_dashboard_2/add_coupon_modal.html
index 8befb90f10..c832d1f94d 100644
--- a/lms/templates/instructor/instructor_dashboard_2/add_coupon_modal.html
+++ b/lms/templates/instructor/instructor_dashboard_2/add_coupon_modal.html
@@ -34,7 +34,7 @@
-
diff --git a/lms/templates/instructor/instructor_dashboard_2/e-commerce.html b/lms/templates/instructor/instructor_dashboard_2/e-commerce.html
index 90ec854828..061ca5dcac 100644
--- a/lms/templates/instructor/instructor_dashboard_2/e-commerce.html
+++ b/lms/templates/instructor/instructor_dashboard_2/e-commerce.html
@@ -142,6 +142,12 @@
$("#update_coupon_button").removeAttr('disabled');
return false;
}
+ if (parseInt(coupon_discount) > 100) {
+ $('#edit_coupon_form #coupon_form_error').attr('style', 'display: block !important');
+ $('#edit_coupon_form #coupon_form_error').text("${_('Please Enter the Coupon Discount Value Less than or Equal to 100')}");
+ $("#update_coupon_button").removeAttr('disabled');
+ return false;
+ }
if (!$.isNumeric(coupon_discount)) {
$('#edit_coupon_form #coupon_form_error').attr('style', 'display: block !important');
$('#edit_coupon_form #coupon_form_error').text("${_('Please Enter the Coupon Discount Value Greater than 0')}");
@@ -171,6 +177,12 @@
$("#add_coupon_button").removeAttr('disabled');
return false;
}
+ if (parseInt(coupon_discount) > 100) {
+ $('#add_coupon_form #coupon_form_error').attr('style', 'display: block !important');
+ $('#add_coupon_form #coupon_form_error').text("${_('Please Enter the Coupon Discount Value Less than or Equal to 100')}");
+ $("#add_coupon_button").removeAttr('disabled');
+ return false;
+ }
if (!$.isNumeric(coupon_discount)) {
$("#add_coupon_button").removeAttr('disabled');
$('#add_coupon_form #coupon_form_error').attr('style', 'display: block !important');
diff --git a/lms/templates/instructor/instructor_dashboard_2/edit_coupon_modal.html b/lms/templates/instructor/instructor_dashboard_2/edit_coupon_modal.html
index 2d292abf12..11bd44a2a1 100644
--- a/lms/templates/instructor/instructor_dashboard_2/edit_coupon_modal.html
+++ b/lms/templates/instructor/instructor_dashboard_2/edit_coupon_modal.html
@@ -34,7 +34,7 @@