From 107f100173f903e18f39f23f6066ee1ca73ae02f Mon Sep 17 00:00:00 2001 From: Zeinab Awada Date: Thu, 24 Apr 2025 20:48:18 -0400 Subject: [PATCH] Quiz now auto-saves after creating questions (#681) --- canvasapi/quiz.py | 2 ++ tests/test_quiz.py | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/canvasapi/quiz.py b/canvasapi/quiz.py index 1602fb0f..b002d8ab 100644 --- a/canvasapi/quiz.py +++ b/canvasapi/quiz.py @@ -68,6 +68,8 @@ def create_question(self, **kwargs): response_json = response.json() response_json.update({"course_id": self.course_id}) + self.edit(quiz={"published": getattr(self, "published", False)}) + return QuizQuestion(self._requester, response_json) def create_question_group(self, quiz_groups, **kwargs): diff --git a/tests/test_quiz.py b/tests/test_quiz.py index 94ae9454..1c50c04e 100644 --- a/tests/test_quiz.py +++ b/tests/test_quiz.py @@ -149,7 +149,7 @@ def test_create_question_group_incorrect_dict(self, m): # create_question() def test_create_question(self, m): - register_uris({"quiz": ["create_question"]}, m) + register_uris({"quiz": ["create_question", "edit"]}, m) question_dict = { "question_name": "Pick Correct Answer", @@ -165,6 +165,25 @@ def test_create_question(self, m): self.assertTrue(hasattr(question, "question_name")) self.assertEqual(question.question_name, question_dict["question_name"]) + + def test_create_question_autosaves(self, m): + register_uris({"quiz": ["create_question", "edit"]}, m) + + question_dict = { + "question_name": "Pick Correct Answer", + "question_type": "multiple_choice_question", + "question_text": "What is the right answer?", + "points_possible": 10, + "correct_comments": "That's correct!", + "incorrect_comments": "That's wrong!", + } + + question = self.quiz.create_question(question=question_dict) + + self.assertIsInstance(question, QuizQuestion) + self.assertEqual(question.question_name, question_dict["question_name"]) + + # get_question() def test_get_question(self, m): register_uris({"quiz": ["get_question"]}, m)