Commit 52b6ef89 by Renzo Lucioni

Merge pull request #5976 from edx/hotfix-2014-11-17

disable "go to payment button" on click (ECOM-643)
parents 1a4ad061 4db5b311
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
"default": { "default": {
"ENGINE": "django.db.backends.mysql", "ENGINE": "django.db.backends.mysql",
"HOST": "localhost", "HOST": "localhost",
"NAME": "test", "NAME": "edxtest",
"PASSWORD": "", "PASSWORD": "",
"PORT": "3306", "PORT": "3306",
"USER": "root" "USER": "root"
......
...@@ -141,6 +141,20 @@ class TestCreateOrderView(ModuleStoreTestCase): ...@@ -141,6 +141,20 @@ class TestCreateOrderView(ModuleStoreTestCase):
self.assertIn('This course doesn\'t support verified certificates', response.content) self.assertIn('This course doesn\'t support verified certificates', response.content)
@patch.dict(settings.FEATURES, {'AUTOMATIC_VERIFY_STUDENT_IDENTITY_FOR_TESTING': True}) @patch.dict(settings.FEATURES, {'AUTOMATIC_VERIFY_STUDENT_IDENTITY_FOR_TESTING': True})
def test_create_order_fail_with_get(self):
"""
Test that create_order will not work if wrong http method used
"""
create_order_post_data = {
'contribution': 50,
'course_id': self.course_id,
'face_image': ',',
'photo_id_image': ','
}
response = self.client.get(reverse('verify_student_create_order'), create_order_post_data)
self.assertEqual(response.status_code, 405)
@patch.dict(settings.FEATURES, {'AUTOMATIC_VERIFY_STUDENT_IDENTITY_FOR_TESTING': True})
def test_create_order_success(self): def test_create_order_success(self):
""" """
Test that the order is created successfully when given valid data Test that the order is created successfully when given valid data
......
...@@ -167,6 +167,7 @@ class VerifiedView(View): ...@@ -167,6 +167,7 @@ class VerifiedView(View):
return render_to_response('verify_student/verified.html', context) return render_to_response('verify_student/verified.html', context)
@require_POST
@login_required @login_required
def create_order(request): def create_order(request):
""" """
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
"default": { "default": {
"ENGINE": "django.db.backends.mysql", "ENGINE": "django.db.backends.mysql",
"HOST": "localhost", "HOST": "localhost",
"NAME": "test", "NAME": "edxtest",
"PASSWORD": "", "PASSWORD": "",
"PORT": "3306", "PORT": "3306",
"USER": "root" "USER": "root"
......
...@@ -4,7 +4,7 @@ define(['backbone', 'jquery', 'js/verify_student/photocapture'], ...@@ -4,7 +4,7 @@ define(['backbone', 'jquery', 'js/verify_student/photocapture'],
describe("Photo Verification", function () { describe("Photo Verification", function () {
beforeEach(function () { beforeEach(function () {
setFixtures('<div id="order-error" style="display: none;"></div><input type="radio" name="contribution" value="35" id="contribution-35" checked="checked"><input type="radio" id="contribution-other" name="contribution" value=""><input type="text" size="9" name="contribution-other-amt" id="contribution-other-amt" value="30"><img id="face_image" src="src="data:image/png;base64,dummy"><img id="photo_id_image" src="src="data:image/png;base64,dummy">'); setFixtures('<div id="order-error" style="display: none;"></div><input type="radio" name="contribution" value="35" id="contribution-35" checked="checked"><input type="radio" id="contribution-other" name="contribution" value=""><input type="text" size="9" name="contribution-other-amt" id="contribution-other-amt" value="30"><img id="face_image" src="src="data:image/png;base64,dummy"><img id="photo_id_image" src="src="data:image/png;base64,dummy"><button id="pay_button">pay button</button>');
}); });
it('retake photo', function () { it('retake photo', function () {
...@@ -27,6 +27,7 @@ define(['backbone', 'jquery', 'js/verify_student/photocapture'], ...@@ -27,6 +27,7 @@ define(['backbone', 'jquery', 'js/verify_student/photocapture'],
}); });
submitToPaymentProcessing(); submitToPaymentProcessing();
expect(window.submitForm).toHaveBeenCalled(); expect(window.submitForm).toHaveBeenCalled();
expect($("#pay_button")).toHaveClass("is-disabled");
}); });
it('Error during process', function () { it('Error during process', function () {
...@@ -36,8 +37,18 @@ define(['backbone', 'jquery', 'js/verify_student/photocapture'], ...@@ -36,8 +37,18 @@ define(['backbone', 'jquery', 'js/verify_student/photocapture'],
spyOn($, "ajax").andCallFake(function (e) { spyOn($, "ajax").andCallFake(function (e) {
e.error({}); e.error({});
}); });
spyOn($.fn, "addClass").andCallThrough();
spyOn($.fn, "removeClass").andCallThrough();
submitToPaymentProcessing(); submitToPaymentProcessing();
expect(window.showSubmissionError).toHaveBeenCalled(); expect(window.showSubmissionError).toHaveBeenCalled();
// make sure the button isn't disabled
expect($("#pay_button")).not.toHaveClass("is-disabled");
// but also make sure that it was disabled during the ajax call
expect($.fn.addClass).toHaveBeenCalledWith("is-disabled");
expect($.fn.removeClass).toHaveBeenCalledWith("is-disabled");
}); });
}); });
......
...@@ -69,6 +69,7 @@ function refereshPageMessage() { ...@@ -69,6 +69,7 @@ function refereshPageMessage() {
} }
var submitToPaymentProcessing = function() { var submitToPaymentProcessing = function() {
$("#pay_button").addClass('is-disabled');
var contribution_input = $("input[name='contribution']:checked") var contribution_input = $("input[name='contribution']:checked")
var contribution = 0; var contribution = 0;
if(contribution_input.attr('id') == 'contribution-other') { if(contribution_input.attr('id') == 'contribution-other') {
...@@ -95,6 +96,7 @@ var submitToPaymentProcessing = function() { ...@@ -95,6 +96,7 @@ var submitToPaymentProcessing = function() {
} }
}, },
error:function(xhr,status,error) { error:function(xhr,status,error) {
$("#pay_button").removeClass('is-disabled');
showSubmissionError() showSubmissionError()
} }
}); });
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
<script type="text/javascript"> <script type="text/javascript">
var submitToPaymentProcessing = function(event) { var submitToPaymentProcessing = function(event) {
event.preventDefault(); event.preventDefault();
$("#pay_button").addClass("is-disabled");
var xhr = $.post( var xhr = $.post(
"${create_order_url}", "${create_order_url}",
{ {
...@@ -30,7 +31,9 @@ var submitToPaymentProcessing = function(event) { ...@@ -30,7 +31,9 @@ var submitToPaymentProcessing = function(event) {
.done(function(data) { .done(function(data) {
$("#pay_form").submit(); $("#pay_form").submit();
}) })
.fail(function(jqXhr,text_status, error_thrown) { alert(jqXhr.responseText); }); .fail(function(jqXhr,text_status, error_thrown) {
$("#pay_button").removeClass("is-disabled");
alert(jqXhr.responseText); });
} }
$(document).ready(function() { $(document).ready(function() {
$("#pay_button").click(submitToPaymentProcessing); $("#pay_button").click(submitToPaymentProcessing);
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
DB_CACHE_DIR="common/test/db_cache" DB_CACHE_DIR="common/test/db_cache"
# Ensure the test database exists. # Ensure the test database exists.
echo "CREATE DATABASE IF NOT EXISTS test;" | mysql -u root echo "CREATE DATABASE IF NOT EXISTS edxtest;" | mysql -u root
# Clear out the test database # Clear out the test database
./manage.py lms --settings bok_choy reset_db --traceback --noinput ./manage.py lms --settings bok_choy reset_db --traceback --noinput
...@@ -34,7 +34,7 @@ echo "CREATE DATABASE IF NOT EXISTS test;" | mysql -u root ...@@ -34,7 +34,7 @@ echo "CREATE DATABASE IF NOT EXISTS test;" | mysql -u root
if [[ -f $DB_CACHE_DIR/bok_choy_schema.sql && -f $DB_CACHE_DIR/bok_choy_data.json ]]; then if [[ -f $DB_CACHE_DIR/bok_choy_schema.sql && -f $DB_CACHE_DIR/bok_choy_data.json ]]; then
# Load the schema, then the data (including the migration history) # Load the schema, then the data (including the migration history)
mysql -u root test < $DB_CACHE_DIR/bok_choy_schema.sql mysql -u root edxtest < $DB_CACHE_DIR/bok_choy_schema.sql
./manage.py lms --settings bok_choy loaddata $DB_CACHE_DIR/bok_choy_data.json ./manage.py lms --settings bok_choy loaddata $DB_CACHE_DIR/bok_choy_data.json
# Re-run migrations to ensure we are up-to-date # Re-run migrations to ensure we are up-to-date
...@@ -52,6 +52,6 @@ else ...@@ -52,6 +52,6 @@ else
# Dump the schema and data to the cache # Dump the schema and data to the cache
./manage.py lms --settings bok_choy dumpdata > $DB_CACHE_DIR/bok_choy_data.json ./manage.py lms --settings bok_choy dumpdata > $DB_CACHE_DIR/bok_choy_data.json
mysqldump -u root --no-data --skip-comments --skip-dump-date test > $DB_CACHE_DIR/bok_choy_schema.sql mysqldump -u root --no-data --skip-comments --skip-dump-date edxtest > $DB_CACHE_DIR/bok_choy_schema.sql
fi fi
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