Commit d7f2d4b7 by Diana Huang

Merge pull request #1876 from MITx/diana/matlab-input-updates

Make updates to the MatlabInput InputType
parents a1360a27 32881ed2
......@@ -668,6 +668,8 @@ class MatlabInput(CodeInput):
# Check if problem has been queued
self.queuename = 'matlab'
self.queue_msg = ''
# this is only set if we don't have a graded response
# the graded response takes precedence
if 'queue_msg' in self.input_state and self.status in ['queued', 'incomplete', 'unsubmitted']:
self.queue_msg = self.input_state['queue_msg']
if 'queuestate' in self.input_state and self.input_state['queuestate'] == 'queued':
......@@ -712,11 +714,23 @@ class MatlabInput(CodeInput):
self.input_state['queuestate'] = None
self.input_state['queuekey'] = None
def button_enabled(self):
""" Return whether or not we want the 'Test Code' button visible
Right now, we only want this button to show up when a problem has not been
checked.
"""
if self.status in ['correct', 'incorrect']:
return False
else:
return True
def _extra_context(self):
''' Set up additional context variables'''
extra_context = {
'queue_len': str(self.queue_len),
'queue_msg': self.queue_msg
'queue_msg': self.queue_msg,
'button_enabled': self.button_enabled(),
}
return extra_context
......@@ -766,10 +780,6 @@ class MatlabInput(CodeInput):
lms_key=queuekey,
queue_name=self.queuename)
# save the input state
self.input_state['queuekey'] = queuekey
self.input_state['queuestate'] = 'queued'
# construct xqueue body
student_info = {'anonymous_student_id': anonymous_student_id,
'submission_time': qtime}
......@@ -779,6 +789,10 @@ class MatlabInput(CodeInput):
(error, msg) = qinterface.send_to_queue(header=xheader,
body=json.dumps(contents))
# save the input state if successful
if error == 0:
self.input_state['queuekey'] = queuekey
self.input_state['queuestate'] = 'queued'
return {'success': error == 0, 'message': msg}
......
......@@ -33,9 +33,11 @@
${queue_msg|n}
</div>
% if button_enabled:
<div class="plot-button">
<input type="button" class="save" name="plot-button" id="plot_${id}" value="Plot" />
<input type="button" class="save" name="plot-button" id="plot_${id}" value="Run Code" />
</div>
%endif
<script>
// Note: We need to make the area follow the CodeMirror for this to work.
......@@ -91,7 +93,7 @@
window.location.reload();
}
else {
gentle_alert(problem_elt, msg);
gentle_alert(problem_elt, response.message);
}
}
......@@ -102,7 +104,7 @@
{'submission': submission}, plot_callback);
}
else {
gentle_alert(problem_elt, msg);
gentle_alert(problem_elt, response.message);
}
}
......
......@@ -384,6 +384,7 @@ class MatlabTest(unittest.TestCase):
'linenumbers': 'true',
'hidden': '',
'tabsize': int(self.tabsize),
'button_enabled': True,
'queue_len': '3'}
self.assertEqual(context, expected)
......@@ -409,10 +410,37 @@ class MatlabTest(unittest.TestCase):
'linenumbers': 'true',
'hidden': '',
'tabsize': int(self.tabsize),
'button_enabled': True,
'queue_len': '3'}
self.assertEqual(context, expected)
def test_rendering_when_completed(self):
for status in ['correct', 'incorrect']:
state = {'value': 'print "good evening"',
'status': status,
'input_state': {},
}
elt = etree.fromstring(self.xml)
the_input = self.input_class(test_system, elt, state)
context = the_input._get_render_context()
expected = {'id': 'prob_1_2',
'value': 'print "good evening"',
'status': status,
'msg': '',
'mode': self.mode,
'rows': self.rows,
'cols': self.cols,
'queue_msg': '',
'linenumbers': 'true',
'hidden': '',
'tabsize': int(self.tabsize),
'button_enabled': False,
'queue_len': '0'}
self.assertEqual(context, expected)
def test_rendering_while_queued(self):
state = {'value': 'print "good evening"',
'status': 'incomplete',
......@@ -433,6 +461,7 @@ class MatlabTest(unittest.TestCase):
'linenumbers': 'true',
'hidden': '',
'tabsize': int(self.tabsize),
'button_enabled': True,
'queue_len': '1'}
self.assertEqual(context, expected)
......@@ -447,6 +476,17 @@ class MatlabTest(unittest.TestCase):
self.assertTrue(self.the_input.input_state['queuekey'] is not None)
self.assertEqual(self.the_input.input_state['queuestate'], 'queued')
def test_plot_data_failure(self):
get = {'submission': 'x = 1234;'}
error_message = 'Error message!'
test_system.xqueue['interface'].send_to_queue.return_value = (1, error_message)
response = self.the_input.handle_ajax("plot", get)
self.assertFalse(response['success'])
self.assertEqual(response['message'], error_message)
self.assertTrue('queuekey' not in self.the_input.input_state)
self.assertTrue('queuestate' not in self.the_input.input_state)
test_system.xqueue['interface'].send_to_queue.return_value = (0, 'Success!')
def test_ungraded_response_success(self):
queuekey = 'abcd'
input_state = {'queuekey': queuekey, 'queuestate': 'queued'}
......@@ -583,7 +623,6 @@ class ImageInputTest(unittest.TestCase):
self.check('[12 13 14]', 0, 0)
class CrystallographyTest(unittest.TestCase):
'''
Check that crystallography inputs work
......@@ -613,8 +652,7 @@ class CrystallographyTest(unittest.TestCase):
'status': 'unsubmitted',
'msg': '',
'width': width,
'height': height,
}
'height': height}
self.assertEqual(context, expected)
......@@ -654,13 +692,11 @@ class VseprTest(unittest.TestCase):
'width': width,
'height': height,
'molecules': molecules,
'geometries': geometries,
}
'geometries': geometries}
self.assertEqual(context, expected)
class ChemicalEquationTest(unittest.TestCase):
'''
Check that chemical equation inputs work.
......@@ -674,7 +710,6 @@ class ChemicalEquationTest(unittest.TestCase):
state = {'value': 'H2OYeah', }
self.the_input = lookup_tag('chemicalequationinput')(test_system, element, state)
def test_rendering(self):
''' Verify that the render context matches the expected render context'''
context = self.the_input._get_render_context()
......@@ -688,10 +723,8 @@ class ChemicalEquationTest(unittest.TestCase):
}
self.assertEqual(context, expected)
def test_chemcalc_ajax_sucess(self):
''' Verify that using the correct dispatch and valid data produces a valid response'''
data = {'formula': "H"}
response = self.the_input.handle_ajax("preview_chemcalc", data)
......@@ -700,9 +733,6 @@ class ChemicalEquationTest(unittest.TestCase):
self.assertEqual(response['error'], "")
class DragAndDropTest(unittest.TestCase):
'''
Check that drag and drop inputs work
......
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