Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_edit_assignment(self, m):
register_uris({"assignment": ["edit_assignment"]}, m)
name = "New Name"
edited_assignment = self.assignment.edit(assignment={"name": name})
self.assertIsInstance(edited_assignment, Assignment)
self.assertTrue(hasattr(edited_assignment, "name"))
self.assertEqual(edited_assignment.name, name)
def test_delete_assignments(self, m):
register_uris({"assignment": ["delete_assignment"]}, m)
deleted_assignment = self.assignment.delete()
self.assertIsInstance(deleted_assignment, Assignment)
def test_get_missing_submissions(self, m):
register_uris({"user": ["missing_sub", "missing_sub_p2"]}, m)
missing_assigments = self.user.get_missing_submissions()
assignment_list = [assignment for assignment in missing_assigments]
self.assertEqual(len(assignment_list), 4)
self.assertIsInstance(assignment_list[0], Assignment)
def test_get_assignment(self, m):
register_uris({"course": ["get_assignment_by_id"]}, m)
assignment_by_id = self.course.get_assignment(1)
self.assertIsInstance(assignment_by_id, Assignment)
self.assertTrue(hasattr(assignment_by_id, "name"))
assignment_by_obj = self.course.get_assignment(self.assignment)
self.assertIsInstance(assignment_by_obj, Assignment)
self.assertTrue(hasattr(assignment_by_obj, "name"))
:param user: The object or ID of the related user
:type user: :class:`canvasapi.user.User` or int
:rtype: :class:`canvasapi.submission.Submission`
"""
from canvasapi.assignment import Assignment
warnings.warn(
"`Course.get_submission()` is deprecated and will be removed in a "
"future version. Use `Assignment.get_submission()` instead",
DeprecationWarning,
)
assignment_id = obj_or_id(assignment, "assignment", (Assignment,))
assignment = Assignment(
self._requester, {"course_id": self.id, "id": assignment_id}
)
return assignment.get_submission(user, **kwargs)
:param assignment: The object or ID of the assignment.
:type assignment: :class:`canvasapi.assignment.Assignment` or int
:param user: The object or ID of the user.
:type user: :class:`canvasapi.user.User` or int or str
:rtype: :class:`canvasapi.submission.Submission`
"""
from canvasapi.assignment import Assignment
warnings.warn(
'Section.get_submission() is deprecated and will be removed '
'in the future. Use Assignment.get_submission() instead.',
DeprecationWarning
)
assignment_id = obj_or_id(assignment, "assignment", (Assignment,))
assignment = Assignment(self._requester, {
'course_id': self.course_id,
'section_id': self.id,
'id': assignment_id
})
return assignment.get_submission(user, **kwargs)
:type assignment: :class:`canvasapi.assignment.Assignment` or int
:rtype: :class:`canvasapi.paginated_list.PaginatedList` of
:class:`canvasapi.submission.Submission`
"""
from canvasapi.assignment import Assignment
warnings.warn(
"Course.list_submissions() is deprecated and will be removed in "
"the future. Use Assignment.get_submissions() instead.",
DeprecationWarning,
)
assignment_id = obj_or_id(assignment, "assignment", (Assignment,))
assignment = Assignment(
self._requester, {"course_id": self.id, "id": assignment_id}
)
return assignment.get_submissions(**kwargs)
:type assignment: :class:`canvasapi.assignment.Assignment` or int
:rtype: :class:`canvasapi.paginated_list.PaginatedList` of
:class:`canvasapi.user.UserDisplay`
"""
from canvasapi.assignment import Assignment
warnings.warn(
"`Course.list_gradeable_students()` is deprecated and will be "
"removed in a future version. Use "
"`Assignment.get_gradeable_students()` instead.",
DeprecationWarning,
)
assignment_id = obj_or_id(assignment, "assignment", (Assignment,))
assignment = Assignment(
self._requester, {"id": assignment_id, "course_id": self.id}
)
return assignment.get_gradeable_students(**kwargs)
def get_assignment_override(self, assignment, **kwargs):
"""
Return override for the specified assignment for this group.
:param assignment: The assignment to get an override for
:type assignment: :class:`canvasapi.assignment.Assignment` or int
:calls: `GET /api/v1/groups/:group_id/assignments/:assignment_id/override \
`_
:rtype: :class:`canvasapi.assignment.AssignmentOverride`
"""
from canvasapi.assignment import Assignment, AssignmentOverride
assignment_id = obj_or_id(assignment, "assignment", (Assignment,))
response = self._requester.request(
"GET", "groups/{}/assignments/{}/override".format(self.id, assignment_id)
)
response_json = response.json()
response_json.update({"course_id": self.course_id})
return AssignmentOverride(self._requester, response_json)
:calls: `GET /api/v1/users/:user_id/courses/:course_id/assignments \
`_
:param course: The object or ID of the course to retrieve.
:type course: :class:`canvasapi.course.Course` or int
:rtype: :class:`canvasapi.paginated_list.PaginatedList` of
:class:`canvasapi.assignment.Assignment`
"""
from canvasapi.assignment import Assignment
from canvasapi.course import Course
course_id = obj_or_id(course, "course", (Course,))
return PaginatedList(
Assignment,
self._requester,
"GET",
"users/{}/courses/{}/assignments".format(self.id, course_id),
_kwargs=combine_kwargs(**kwargs),
)