Commit 2c932441 by Gabe Mulley

Allow problem type to change to multiple choice

Before this patch, changing a problem from anything to a multiple choice question would cause failures since the most recent submissions would indicate that all past submissions should contain monikers, when in fact they won't. The answer distribution output for this scenario will definitely be wierd, but all bets are off when you modify a problem like this.

Change-Id: Ib72439c37fbe178f2320f7c48cc8bbd687ed7f02
parent 84c200f2
......@@ -299,8 +299,11 @@ class AnswerDistributionPerCourseMixin(object):
# the code should be returned as such. If this
# particular answer did not have 'submission'
# information, it may not have an answer_value, so
# we flag it.
value_id = answer['answer_value_id']
# we flag it. The problem type may have changed as
# well, so previous answers to this problem may not
# actually have an answer_value_id even though the
# most recent one does.
value_id = answer.get('answer_value_id', '')
answer_value = answer.get('answer', UNKNOWN_ANSWER_VALUE)
else:
# There should be no value_id returned. If the
......
......@@ -639,6 +639,26 @@ class AnswerDistributionPerCourseReduceTest(unittest.TestCase):
expected_output_2 = self._get_expected_output(answer_data_2)
self._check_output([input_data_1, input_data_2], (expected_output_1, expected_output_2))
def test_problem_type_changed_to_multi_choice(self):
answer_data_1 = self._get_answer_data(
answer=u'First Ch\u014dice',
response_type='optionresponse',
)
answer_data_2 = self._get_answer_data(
answer_value_id=['choice_1', 'choice_2', 'choice_4'],
answer=[u'First Ch\u014dice', u'Second Ch\u014dice', u'Fourth Ch\u014dice'],
response_type="multiplechoiceresponse",
)
input_data_1 = (self.earlier_timestamp, json.dumps(answer_data_1))
input_data_2 = (self.timestamp, json.dumps(answer_data_2))
expected_output_1 = self._get_expected_output(answer_data_1)
expected_output_2 = self._get_expected_output(
answer_data_2,
ValueID='[choice_1|choice_2|choice_4]',
AnswerValue=u'[First Ch\u014dice|Second Ch\u014dice|Fourth Ch\u014dice]'
)
self._check_output([input_data_1, input_data_2], (expected_output_1, expected_output_2))
def _load_metadata(self, **kwargs):
"""Defines some metadata for test answer."""
metadata_dict = {
......
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