Update Quiz class methods to package request params consistently. #657
AlexHopkinsUCSD
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Primary Issue
CanvasAPI Version: 3.2.0
Python Version: 3.9.2
The documentation seen on the Canvas API docs specifies (vaguely) the requirement for Quiz POST and PUT requests to be structured with all parameters assigned to the key "quiz". This library is inconsistent in its handling of similar situations and lacks documentation clarifying when the library handles such situations and when it does not, resulting in unnecessary confusion and debugging.
As an example of this discrepancy, in Course.py we find this method:
Note the line
kwargs["quiz"] = quiz
is executed before being passed intoself._requester.request()
thus resulting in a properly formatted POST params to Canvas's Quiz creation endpoint.Now take a look at this example in Quiz.py:
Unlike the first example where we create a quiz, in the PUT handler for quizzes, there is no attempt to format the kwargs to match the required params for the Canvas endpoint. If your first inclination is to simply pass in something like
Quiz.edit(quiz_type="practice_quiz")
, not only will it not work, it also won't error, you will receive a 200 and a valid quiz object from Canvas, but with no change applied. You are required to pass a single argument named 'quiz' for this to work:Quiz.edit(quiz={"quiz_type": "practice_quiz"})
. As far as I can tell this is entirely undocumented and the only place to see an actual implementation of this method is in the tests, where the named argument 'quiz' is used.There are other examples of this as well, here and here, there may be other examples but these are the ones I've encountered so far. This is annoying and unclear what the problem is when it occurs.
Lazy Solution
Append
kwargs
to a dict with the key 'quiz' and add a more comprehensive docstringAs far as I can tell, this has the same
combine_kwargs()
output as passing the argumentQuiz.edit(quiz={"key": "val"})
to the existing method and would work for the other examples cited. If there is any reason why this wouldn't work that I'm unaware of or better ideas, I'm all ears, but even just a docstring showing the required arg format would be an improvement.Beta Was this translation helpful? Give feedback.
All reactions