-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Begin adding coverage for New Quizzes (WIP) * Finish New Quizzes endpoints
- Loading branch information
Showing
8 changed files
with
318 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from canvasapi.canvas_object import CanvasObject | ||
from canvasapi.util import combine_kwargs | ||
|
||
|
||
class NewQuiz(CanvasObject): | ||
def __str__(self): | ||
return "{} ({})".format(self.title, self.id) | ||
|
||
def delete(self, **kwargs): | ||
""" | ||
Delete a single new quiz. | ||
:calls: `DELETE /api/quiz/v1/courses/:course_id/quizzes/:assignment_id \ | ||
<https://canvas.instructure.com/doc/api/new_quizzes.html#method.new_quizzes/quizzes_api.destroy>`_ | ||
:returns: The deleted New Quiz object | ||
:rtype: :class:`canvasapi.new_quiz.NewQuiz` | ||
""" | ||
endpoint = "courses/{}/quizzes/{}".format(self.course_id, self.id) | ||
|
||
response = self._requester.request( | ||
"DELETE", | ||
endpoint, | ||
_url=self._requester.original_url + "/api/quiz/v1/" + endpoint, | ||
_kwargs=combine_kwargs(**kwargs), | ||
) | ||
response_json = response.json() | ||
response_json.update({"course_id": self.course_id}) | ||
|
||
return NewQuiz(self._requester, response_json) | ||
|
||
def update(self, **kwargs): | ||
""" | ||
Update a single New Quiz for the course. | ||
:calls: `PATCH /api/quiz/v1/courses/:course_id/quizzes/:assignment_id \ | ||
<https://canvas.instructure.com/doc/api/new_quizzes.html#method.new_quizzes/quizzes_api.update>`_ | ||
:returns: The updated New Quiz object | ||
:rtype: :class:`canvasapi.new_quiz.NewQuiz` | ||
""" | ||
endpoint = "courses/{}/quizzes/{}".format(self.course_id, self.id) | ||
|
||
response = self._requester.request( | ||
"PATCH", | ||
endpoint, | ||
_url=self._requester.original_url + "/api/quiz/v1/" + endpoint, | ||
_kwargs=combine_kwargs(**kwargs), | ||
) | ||
response_json = response.json() | ||
response_json.update({"course_id": self.course_id}) | ||
|
||
return NewQuiz(self._requester, response_json) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{ | ||
"create_new_quiz": { | ||
"method": "POST", | ||
"endpoint": "courses/1/quizzes", | ||
"data": { | ||
"id": 1, | ||
"title": "New Quiz One", | ||
"instructions": "<p>This is the first New Quiz. Good luck!</p>" | ||
}, | ||
"status_code": 200 | ||
}, | ||
"delete_new_quiz": { | ||
"method": "DELETE", | ||
"endpoint": "courses/1/quizzes/1", | ||
"data": { | ||
"id": 1, | ||
"title": "New Quiz One", | ||
"instructions": "<p>This is the first New Quiz. Good luck!</p>" | ||
}, | ||
"status_code": 200 | ||
}, | ||
"get_new_quiz": { | ||
"method": "GET", | ||
"endpoint": "courses/1/quizzes/1", | ||
"data": { | ||
"id": 1, | ||
"title": "New Quiz One", | ||
"instructions": "<p>This is the first New Quiz. Good luck!</p>" | ||
}, | ||
"status_code": 200 | ||
}, | ||
"get_new_quizzes": { | ||
"method": "GET", | ||
"endpoint": "courses/1/quizzes", | ||
"data": [ | ||
{ | ||
"id": 1, | ||
"title": "New Quiz One", | ||
"instructions": "<p>This is the first New Quiz. Good luck!</p>" | ||
}, | ||
{ | ||
"id": 2, | ||
"title": "New Quiz Two", | ||
"instructions": "<p>This is the second New Quiz. Good luck!</p>" | ||
} | ||
], | ||
"status_code": 200 | ||
}, | ||
"update_new_quiz": { | ||
"method": "PATCH", | ||
"endpoint": "courses/1/quizzes/1", | ||
"data": { | ||
"id": 1, | ||
"title": "New Quiz One - Updated!", | ||
"instructions": "<p>This is the updated New Quiz. You got this!</p>" | ||
}, | ||
"status_code": 200 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.