Skip to content

Commit edbcb2e

Browse files
committed
implement: Carry question metadata through to JSON (t4)
1 parent 2fe3566 commit edbcb2e

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

‎docs/source/quickstart.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,6 @@ Click on a set in teacher mode. The arrow next to the "Add Question" button allo
7979

8080
Choose the zip file you wish to upload, and the question should appear! 🎉
8181

82-
Imported questions arrive published, with the final answer, worked solution, structured tutorial and chatbot shown to students. The Python API can set each of these per question.
82+
Imported questions arrive published with every display setting on, and the set's own visibility settings still apply. The Python API can set each of these per question.
8383

8484
![Importing Question from file in Teacher Mode](_static/images/import-teacher.png)

‎tests/test_exports.py‎

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def test_written_keys_exist_in_export(export_dir: Path, tmp_path: Path) -> None:
113113

114114

115115
def test_question_settings_are_written(tmp_path: Path) -> None:
116-
"""A question's settings reach its JSON, and unset optional ones are left out."""
116+
"""A question's settings reach its JSON, are left out when unset, and reload."""
117117
question_set = Set(_name="Settings")
118118
question_set.questions = [
119119
Question(
@@ -123,6 +123,9 @@ def test_question_settings_are_written(tmp_path: Path) -> None:
123123
duration_lower_bound=5,
124124
duration_upper_bound=10,
125125
publish=False,
126+
display_final_answer=False,
127+
display_worked_solution=False,
128+
display_structured_tutorial=False,
126129
display_chatbot=False,
127130
),
128131
Question(title="Default"),
@@ -139,6 +142,8 @@ def test_question_settings_are_written(tmp_path: Path) -> None:
139142
"durationUpperBound",
140143
"publish",
141144
"displayFinalAnswer",
145+
"displayWorkedSolution",
146+
"displayStructuredTutorial",
142147
"displayChatbot",
143148
]
144149
} == {
@@ -147,7 +152,9 @@ def test_question_settings_are_written(tmp_path: Path) -> None:
147152
"durationLowerBound": 5,
148153
"durationUpperBound": 10,
149154
"publish": False,
150-
"displayFinalAnswer": True,
155+
"displayFinalAnswer": False,
156+
"displayWorkedSolution": False,
157+
"displayStructuredTutorial": False,
151158
"displayChatbot": False,
152159
}
153160

@@ -158,6 +165,26 @@ def test_question_settings_are_written(tmp_path: Path) -> None:
158165
default
159166
)
160167

168+
# Only the settings are compared: a question written without parts reloads with
169+
# the template's placeholder part.
170+
def settings(question: Question) -> list:
171+
return [
172+
question.skill,
173+
question.guidance,
174+
question.duration_lower_bound,
175+
question.duration_upper_bound,
176+
question.publish,
177+
question.display_final_answer,
178+
question.display_worked_solution,
179+
question.display_structured_tutorial,
180+
question.display_chatbot,
181+
]
182+
183+
reloaded = Set.from_json(str(written)).questions
184+
assert [settings(q) for q in reloaded] == [
185+
settings(q) for q in question_set.questions
186+
]
187+
161188

162189
def test_from_json_rejects_folder_without_set(tmp_path: Path) -> None:
163190
"""A folder with no set file is refused with an error that says where it looked."""

0 commit comments

Comments
 (0)