Commit a6249bc1 by David Ormsbee

Fix broken XML parsing tests.

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