Skip to content

Commit

Permalink
adding duplicate assignment endpoint coverage and tests for ucfopen#636
Browse files Browse the repository at this point in the history
  • Loading branch information
dsavransky committed Oct 2, 2023
1 parent 167d488 commit d8a7d90
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
17 changes: 17 additions & 0 deletions canvasapi/assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,23 @@ def delete(self, **kwargs):
)
return Assignment(self._requester, response.json())

def duplicate(self, **kwargs):
"""
Duplicate this assignment.
:calls: `POST /api/v1/courses/:course_id/assignments/:assignment_id/duplicate \
<https://canvas.instructure.com/doc/api/assignments.html#method.assignments_api.duplicate>`_
:rtype: :class:`canvasapi.assignment.Assignment`
"""

response = self._requester.request(
"POST",
"courses/{}/assignments/{}/duplicate".format(self.course_id, self.id),
_kwargs=combine_kwargs(**kwargs),
)
return Assignment(self._requester, response.json())

def edit(self, **kwargs):
"""
Modify this assignment.
Expand Down
11 changes: 11 additions & 0 deletions tests/fixtures/assignment.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,17 @@
},
"status_code": 200
},
"duplicate_assignment": {
"method": "POST",
"endpoint": "courses/1/assignments/1/duplicate",
"data": {
"id": 1,
"course_id": 1,
"name": "Assignment 1 Copy",
"description": "Duplicate assignment"
},
"status_code": 200
},
"edit_assignment": {
"method": "PUT",
"endpoint": "courses/1/assignments/1",
Expand Down
9 changes: 9 additions & 0 deletions tests/test_assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ def test_delete_assignments(self, m):

self.assertIsInstance(deleted_assignment, Assignment)

# duplicate()
def test_duplicate_assignments(self, m):
register_uris({"assignment": ["duplicate_assignment"]}, m)

duplicated_assignment = self.assignment.duplicate()

self.assertIsInstance(duplicated_assignment, Assignment)
self.assertTrue(duplicated_assignment.name == f"{self.assignment.name} Copy")

# edit()
def test_edit_assignment(self, m):
register_uris({"assignment": ["edit_assignment"]}, m)
Expand Down

0 comments on commit d8a7d90

Please sign in to comment.