Commit 181eebc9 by Diana Huang

Miscellaneous updates and fixes.

* Hide "Test Code" button after we check the problem
* Only set the state of the problem to 'queued' if we have successfully
queued the problem
* Unit tests for bugs and new functionality
parent 03daefb9
...@@ -668,6 +668,8 @@ class MatlabInput(CodeInput): ...@@ -668,6 +668,8 @@ class MatlabInput(CodeInput):
# Check if problem has been queued # Check if problem has been queued
self.queuename = 'matlab' self.queuename = 'matlab'
self.queue_msg = '' 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']: if 'queue_msg' in self.input_state and self.status in ['queued', 'incomplete', 'unsubmitted']:
self.queue_msg = self.input_state['queue_msg'] self.queue_msg = self.input_state['queue_msg']
if 'queuestate' in self.input_state and self.input_state['queuestate'] == 'queued': if 'queuestate' in self.input_state and self.input_state['queuestate'] == 'queued':
...@@ -712,11 +714,23 @@ class MatlabInput(CodeInput): ...@@ -712,11 +714,23 @@ class MatlabInput(CodeInput):
self.input_state['queuestate'] = None self.input_state['queuestate'] = None
self.input_state['queuekey'] = 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): def _extra_context(self):
''' Set up additional context variables''' ''' Set up additional context variables'''
extra_context = { extra_context = {
'queue_len': str(self.queue_len), 'queue_len': str(self.queue_len),
'queue_msg': self.queue_msg 'queue_msg': self.queue_msg,
'button_enabled': self.button_enabled(),
} }
return extra_context return extra_context
...@@ -766,10 +780,6 @@ class MatlabInput(CodeInput): ...@@ -766,10 +780,6 @@ class MatlabInput(CodeInput):
lms_key=queuekey, lms_key=queuekey,
queue_name=self.queuename) queue_name=self.queuename)
# save the input state
self.input_state['queuekey'] = queuekey
self.input_state['queuestate'] = 'queued'
# construct xqueue body # construct xqueue body
student_info = {'anonymous_student_id': anonymous_student_id, student_info = {'anonymous_student_id': anonymous_student_id,
'submission_time': qtime} 'submission_time': qtime}
...@@ -779,6 +789,10 @@ class MatlabInput(CodeInput): ...@@ -779,6 +789,10 @@ class MatlabInput(CodeInput):
(error, msg) = qinterface.send_to_queue(header=xheader, (error, msg) = qinterface.send_to_queue(header=xheader,
body=json.dumps(contents)) 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} return {'success': error == 0, 'message': msg}
......
...@@ -33,9 +33,11 @@ ...@@ -33,9 +33,11 @@
${queue_msg|n} ${queue_msg|n}
</div> </div>
% if button_enabled:
<div class="plot-button"> <div class="plot-button">
<input type="button" class="save" name="plot-button" id="plot_${id}" value="Test Code" /> <input type="button" class="save" name="plot-button" id="plot_${id}" value="Test Code" />
</div> </div>
%endif
<script> <script>
// Note: We need to make the area follow the CodeMirror for this to work. // Note: We need to make the area follow the CodeMirror for this to work.
...@@ -91,7 +93,7 @@ ...@@ -91,7 +93,7 @@
window.location.reload(); window.location.reload();
} }
else { else {
gentle_alert(problem_elt, msg); gentle_alert(problem_elt, response.message);
} }
} }
...@@ -102,7 +104,7 @@ ...@@ -102,7 +104,7 @@
{'submission': submission}, plot_callback); {'submission': submission}, plot_callback);
} }
else { else {
gentle_alert(problem_elt, msg); gentle_alert(problem_elt, response.message);
} }
} }
......
...@@ -384,6 +384,7 @@ class MatlabTest(unittest.TestCase): ...@@ -384,6 +384,7 @@ class MatlabTest(unittest.TestCase):
'linenumbers': 'true', 'linenumbers': 'true',
'hidden': '', 'hidden': '',
'tabsize': int(self.tabsize), 'tabsize': int(self.tabsize),
'button_enabled': True,
'queue_len': '3'} 'queue_len': '3'}
self.assertEqual(context, expected) self.assertEqual(context, expected)
...@@ -409,10 +410,37 @@ class MatlabTest(unittest.TestCase): ...@@ -409,10 +410,37 @@ class MatlabTest(unittest.TestCase):
'linenumbers': 'true', 'linenumbers': 'true',
'hidden': '', 'hidden': '',
'tabsize': int(self.tabsize), 'tabsize': int(self.tabsize),
'button_enabled': True,
'queue_len': '3'} 'queue_len': '3'}
self.assertEqual(context, expected) 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): def test_rendering_while_queued(self):
state = {'value': 'print "good evening"', state = {'value': 'print "good evening"',
'status': 'incomplete', 'status': 'incomplete',
...@@ -433,6 +461,7 @@ class MatlabTest(unittest.TestCase): ...@@ -433,6 +461,7 @@ class MatlabTest(unittest.TestCase):
'linenumbers': 'true', 'linenumbers': 'true',
'hidden': '', 'hidden': '',
'tabsize': int(self.tabsize), 'tabsize': int(self.tabsize),
'button_enabled': True,
'queue_len': '1'} 'queue_len': '1'}
self.assertEqual(context, expected) self.assertEqual(context, expected)
...@@ -447,6 +476,17 @@ class MatlabTest(unittest.TestCase): ...@@ -447,6 +476,17 @@ class MatlabTest(unittest.TestCase):
self.assertTrue(self.the_input.input_state['queuekey'] is not None) self.assertTrue(self.the_input.input_state['queuekey'] is not None)
self.assertEqual(self.the_input.input_state['queuestate'], 'queued') 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): def test_ungraded_response_success(self):
queuekey = 'abcd' queuekey = 'abcd'
input_state = {'queuekey': queuekey, 'queuestate': 'queued'} input_state = {'queuekey': queuekey, 'queuestate': 'queued'}
...@@ -583,7 +623,6 @@ class ImageInputTest(unittest.TestCase): ...@@ -583,7 +623,6 @@ class ImageInputTest(unittest.TestCase):
self.check('[12 13 14]', 0, 0) self.check('[12 13 14]', 0, 0)
class CrystallographyTest(unittest.TestCase): class CrystallographyTest(unittest.TestCase):
''' '''
Check that crystallography inputs work Check that crystallography inputs work
...@@ -613,8 +652,7 @@ class CrystallographyTest(unittest.TestCase): ...@@ -613,8 +652,7 @@ class CrystallographyTest(unittest.TestCase):
'status': 'unsubmitted', 'status': 'unsubmitted',
'msg': '', 'msg': '',
'width': width, 'width': width,
'height': height, 'height': height}
}
self.assertEqual(context, expected) self.assertEqual(context, expected)
...@@ -654,13 +692,11 @@ class VseprTest(unittest.TestCase): ...@@ -654,13 +692,11 @@ class VseprTest(unittest.TestCase):
'width': width, 'width': width,
'height': height, 'height': height,
'molecules': molecules, 'molecules': molecules,
'geometries': geometries, 'geometries': geometries}
}
self.assertEqual(context, expected) self.assertEqual(context, expected)
class ChemicalEquationTest(unittest.TestCase): class ChemicalEquationTest(unittest.TestCase):
''' '''
Check that chemical equation inputs work. Check that chemical equation inputs work.
...@@ -674,7 +710,6 @@ class ChemicalEquationTest(unittest.TestCase): ...@@ -674,7 +710,6 @@ class ChemicalEquationTest(unittest.TestCase):
state = {'value': 'H2OYeah', } state = {'value': 'H2OYeah', }
self.the_input = lookup_tag('chemicalequationinput')(test_system, element, state) self.the_input = lookup_tag('chemicalequationinput')(test_system, element, state)
def test_rendering(self): def test_rendering(self):
''' Verify that the render context matches the expected render context''' ''' Verify that the render context matches the expected render context'''
context = self.the_input._get_render_context() context = self.the_input._get_render_context()
...@@ -688,10 +723,8 @@ class ChemicalEquationTest(unittest.TestCase): ...@@ -688,10 +723,8 @@ class ChemicalEquationTest(unittest.TestCase):
} }
self.assertEqual(context, expected) self.assertEqual(context, expected)
def test_chemcalc_ajax_sucess(self): def test_chemcalc_ajax_sucess(self):
''' Verify that using the correct dispatch and valid data produces a valid response''' ''' Verify that using the correct dispatch and valid data produces a valid response'''
data = {'formula': "H"} data = {'formula': "H"}
response = self.the_input.handle_ajax("preview_chemcalc", data) response = self.the_input.handle_ajax("preview_chemcalc", data)
...@@ -700,9 +733,6 @@ class ChemicalEquationTest(unittest.TestCase): ...@@ -700,9 +733,6 @@ class ChemicalEquationTest(unittest.TestCase):
self.assertEqual(response['error'], "") self.assertEqual(response['error'], "")
class DragAndDropTest(unittest.TestCase): class DragAndDropTest(unittest.TestCase):
''' '''
Check that drag and drop inputs work 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