removed the discount value bug
check error handling if the discount value is not an integer
This commit is contained in:
committed by
Chris Dodge
parent
c139c2a516
commit
2d41ebe48f
@@ -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('<td>A2314</td>' in response.content)
|
||||
self.assertFalse('<td>111</td>' 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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
</li>
|
||||
<li class="field required text" id="add-coupon-modal-field-discount">
|
||||
<label for="coupon_discount" class="required text">${_("Percentage Discount")}</label>
|
||||
<input class="field required" id="coupon_discount" type="text" name="discount" value="" maxlength="5"
|
||||
<input class="field required" id="coupon_discount" type="text" name="discount" value="" maxlength="3"
|
||||
aria-required="true"/>
|
||||
</li>
|
||||
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
</li>
|
||||
<li class="field required text" id="edit-coupon-modal-field-discount">
|
||||
<label for="edit_coupon_discount" class="required">${_("Percentage Discount")}</label>
|
||||
<input class="field" id="edit_coupon_discount" type="text" name="discount" value="" maxlength="5"
|
||||
<input class="field" id="edit_coupon_discount" type="text" name="discount" value="" maxlength="3"
|
||||
aria-required="true"/>
|
||||
</li>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user