Skip to content

Commit be09ab3

Browse files
authored
Merge pull request #5408 from rtibbles/free_response
Ensure free response questions can be answered
2 parents 9d8ecf4 + 647ba85 commit be09ab3

File tree

2 files changed

+53
-5
lines changed

2 files changed

+53
-5
lines changed

contentcuration/contentcuration/tests/utils/test_exercise_creation.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,6 +1517,52 @@ def test_free_response_question(self):
15171517
self._normalize_xml(actual_item_xml),
15181518
)
15191519

1520+
def test_free_response_question_no_answers(self):
1521+
assessment_id = "fedcba0987654321fedcba0987654321"
1522+
item = self._create_assessment_item(
1523+
exercises.FREE_RESPONSE,
1524+
"What is the capital of France?",
1525+
[],
1526+
assessment_id=assessment_id,
1527+
)
1528+
1529+
exercise_data = {
1530+
"mastery_model": exercises.M_OF_N,
1531+
"randomize": True,
1532+
"n": 1,
1533+
"m": 1,
1534+
"all_assessment_items": [item.assessment_id],
1535+
"assessment_mapping": {item.assessment_id: exercises.FREE_RESPONSE},
1536+
}
1537+
1538+
self._create_qti_zip(exercise_data)
1539+
exercise_file = self.exercise_node.files.get(preset_id=format_presets.QTI_ZIP)
1540+
zip_file = self._validate_qti_zip_structure(exercise_file)
1541+
1542+
# Check the QTI XML for text entry specifics
1543+
expected_item_file = "items/K_ty6CYdlQyH-3LoJh2VDIQ.xml"
1544+
actual_item_xml = zip_file.read(expected_item_file).decode("utf-8")
1545+
1546+
# Expected QTI item XML content for text entry
1547+
expected_item_xml = """<?xml version="1.0" encoding="UTF-8"?>
1548+
<qti-assessment-item xmlns="http://www.imsglobal.org/xsd/imsqtiasi_v3p0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.imsglobal.org/xsd/imsqtiasi_v3p0 https://purl.imsglobal.org/spec/qti/v3p0/schema/xsd/imsqti_asiv3p0p1_v1p0.xsd" identifier="K_ty6CYdlQyH-3LoJh2VDIQ" title="Test QTI Exercise 1" adaptive="false" time-dependent="false" language="en-US" tool-name="kolibri" tool-version="0.1">
1549+
<qti-response-declaration identifier="RESPONSE" cardinality="single" base-type="string" />
1550+
<qti-outcome-declaration identifier="SCORE" cardinality="single" base-type="float" />
1551+
<qti-item-body>
1552+
<div>
1553+
<p>What is the capital of France?</p>
1554+
<p><qti-text-entry-interaction response-identifier="RESPONSE" expected-length="50" placeholder-text="Enter your answer here" /></p>
1555+
</div>
1556+
</qti-item-body>
1557+
<qti-response-processing template="https://purl.imsglobal.org/spec/qti/v3p0/rptemplates/match_correct" />
1558+
</qti-assessment-item>"""
1559+
1560+
# Compare normalized XML
1561+
self.assertEqual(
1562+
self._normalize_xml(expected_item_xml),
1563+
self._normalize_xml(actual_item_xml),
1564+
)
1565+
15201566
def test_free_response_question_with_maths(self):
15211567
assessment_id = "fedcba0987654321fedcba0987654321"
15221568
item = self._create_assessment_item(

contentcuration/contentcuration/utils/assessment/qti/archive.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,17 @@ def _create_text_entry_interaction_and_response(
152152
prompt.append(interaction_element)
153153
interaction = Div(children=prompt)
154154

155-
float_answer = True
156155
correct_values = []
156+
values_float = []
157157
for answer in processed_data["answers"]:
158158
if answer["correct"]:
159159
correct_values.append(Value(value=str(answer["answer"])))
160-
try:
161-
float(answer["answer"])
162-
except ValueError:
163-
float_answer = False
160+
try:
161+
float(answer["answer"])
162+
values_float.append(True)
163+
except ValueError:
164+
values_float.append(False)
165+
float_answer = bool(values_float) and all(values_float)
164166

165167
response_declaration = ResponseDeclaration(
166168
identifier="RESPONSE",

0 commit comments

Comments
 (0)