Commit a6249bc1 by David Ormsbee

Fix broken XML parsing tests.

parent b4808a54
...@@ -154,9 +154,9 @@ def rubric_from_dict(rubric_dict): ...@@ -154,9 +154,9 @@ def rubric_from_dict(rubric_dict):
rubric = Rubric.objects.get(content_hash=content_hash) rubric = Rubric.objects.get(content_hash=content_hash)
except Rubric.DoesNotExist: except Rubric.DoesNotExist:
rubric_dict["content_hash"] = content_hash rubric_dict["content_hash"] = content_hash
for crit_idx, criterion in enumerate(rubric_dict["criteria"]): for crit_idx, criterion in enumerate(rubric_dict.get("criteria", {})):
criterion["order_num"] = crit_idx criterion["order_num"] = crit_idx
for opt_idx, option in enumerate(criterion["options"]): for opt_idx, option in enumerate(criterion.get("options", {})):
option["order_num"] = opt_idx option["order_num"] = opt_idx
rubric_serializer = RubricSerializer(data=rubric_dict) rubric_serializer = RubricSerializer(data=rubric_dict)
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
"criteria": [ "criteria": [
{ {
"order_num": 0, "order_num": 0,
"name": "realistic",
"prompt": "Is the deadline realistic?", "prompt": "Is the deadline realistic?",
"options": [ "options": [
{ {
...@@ -27,6 +28,7 @@ ...@@ -27,6 +28,7 @@
}, },
{ {
"order_num": 1, "order_num": 1,
"name": "architecture",
"prompt": "Describe the architecture.", "prompt": "Describe the architecture.",
"options": [ "options": [
{ {
......
...@@ -24,8 +24,8 @@ class TestScenarioParser(TestCase): ...@@ -24,8 +24,8 @@ class TestScenarioParser(TestCase):
def test_get_rubric(self): def test_get_rubric(self):
"""Given a <rubric> tree, return a instructions and a list of criteria""" """Given a <rubric> tree, return a instructions and a list of criteria"""
rubric_instructions_text = "This text is general instructions relating to this rubric. There should only be one set of instructions for the rubric." rubric_prompt_text = "This text is general instructions relating to this rubric. There should only be one set of instructions for the rubric."
criterion_instructions_text = "This text is instructions for this criterion. There can be multiple criteria, but each one should only have one set of instructions." criterion_prompt_text = "This text is instructions for this criterion. There can be multiple criteria, but each one should only have one set of instructions."
criterion_option_explain_text = "And this explains what the label for this option means. There can be only one explanation per label." criterion_option_explain_text = "And this explains what the label for this option means. There can be only one explanation per label."
rubric_text = """<rubric> rubric_text = """<rubric>
{rit} {rit}
...@@ -39,27 +39,26 @@ class TestScenarioParser(TestCase): ...@@ -39,27 +39,26 @@ class TestScenarioParser(TestCase):
</explain> </explain>
</option> </option>
</criterion> </criterion>
</rubric>""".format(rit=rubric_instructions_text, </rubric>""".format(rit=rubric_prompt_text,
cit=criterion_instructions_text, cit=criterion_prompt_text,
coet=criterion_option_explain_text) coet=criterion_option_explain_text)
rubric_xml = etree.fromstring(rubric_text) rubric_xml = etree.fromstring(rubric_text)
rubric_instructions, rubric_criteria = self.test_parser.get_rubric(rubric_xml) rubric_prompt, rubric_criteria = self.test_parser.get_rubric(rubric_xml)
# Basic shape of the rubric: instructions and criteria # Basic shape of the rubric: prompt and criteria
self.assertEqual(rubric_instructions, rubric_instructions_text) self.assertEqual(rubric_prompt, rubric_prompt_text)
self.assertEqual(len(rubric_criteria), 1) self.assertEqual(len(rubric_criteria), 1)
# Look inside the criterion to make sure it's shaped correctly # Look inside the criterion to make sure it's shaped correctly
criterion = rubric_criteria[0] criterion = rubric_criteria[0]
self.assertEqual(criterion['name'], 'myCrit') self.assertEqual(criterion['name'], 'myCrit')
self.assertEqual(criterion['instructions'], criterion_instructions_text) self.assertEqual(criterion['prompt'], criterion_prompt_text)
self.assertEqual(criterion['total_value'], 99)
self.assertEqual(len(criterion['options']), 1) self.assertEqual(len(criterion['options']), 1)
# And within the criterion, check that options appear to come out well-formed # And within the criterion, check that options appear to come out well-formed
criterion_option_value, criterion_option, criterion_explanation = criterion['options'][0] option = criterion['options'][0]
self.assertEqual(int(criterion_option_value), 99) self.assertEqual(option['points'], 99)
self.assertEqual(criterion_explanation, criterion_option_explain_text) self.assertEqual(option['explanation'], criterion_option_explain_text)
def test_get_assessments(self): def test_get_assessments(self):
"""Given an <assessments> list, return a list of assessment modules.""" """Given an <assessments> list, return a list of assessment modules."""
......
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