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(self, m):
register_uris({"submission": ["edit"]}, m)
self.assertFalse(hasattr(self.submission_course, "excused"))
self.submission_course.edit(submission={"excuse": True})
self.assertIsInstance(self.submission_course, Submission)
self.assertTrue(hasattr(self.submission_course, "excused"))
self.assertTrue(self.submission_course.excused)
def test_submit_assignment(self, m):
register_uris(
{
'assignment': ['submit'],
'submission': ['get_by_id_section'],
'user': ['get_by_id', 'get_user_assignments']
}, m)
assignment_id = 1
sub_type = "online_upload"
sub_dict = {'submission_type': sub_type}
with warnings.catch_warnings(record=True) as warning_list:
assignment_by_id = self.section.submit_assignment(assignment_id, sub_dict)
self.assertIsInstance(assignment_by_id, Submission)
self.assertTrue(hasattr(assignment_by_id, 'submission_type'))
self.assertEqual(assignment_by_id.submission_type, sub_type)
self.assertEqual(len(warning_list), 1)
self.assertEqual(warning_list[-1].category, DeprecationWarning)
user_obj = self.canvas.get_user(1)
assignments_obj = user_obj.get_assignments(1)
sub_type = "online_upload"
sub_dict = {'submission_type': sub_type}
with warnings.catch_warnings(record=True) as warning_list:
assignment_by_obj = self.section.submit_assignment(assignments_obj[0], sub_dict)
self.assertIsInstance(assignment_by_obj, Submission)
self.assertTrue(hasattr(assignment_by_obj, 'submission_type'))
self.assertEqual(assignment_by_obj.submission_type, sub_type)
def test_submit_assignment(self, m):
register_uris({"assignment": ["submit"]}, m)
with warnings.catch_warnings(record=True) as warning_list:
assignment_id = 1
sub_type = "online_upload"
sub_dict = {"submission_type": sub_type}
submission_by_id = self.course.submit_assignment(assignment_id, sub_dict)
self.assertIsInstance(submission_by_id, Submission)
self.assertTrue(hasattr(submission_by_id, "submission_type"))
self.assertEqual(submission_by_id.submission_type, sub_type)
self.assertEqual(len(warning_list), 1)
self.assertEqual(warning_list[-1].category, DeprecationWarning)
with warnings.catch_warnings(record=True) as warning_list:
submission_by_obj = self.course.submit_assignment(self.assignment, sub_dict)
self.assertIsInstance(submission_by_obj, Submission)
self.assertTrue(hasattr(submission_by_obj, "submission_type"))
self.assertEqual(submission_by_obj.submission_type, sub_type)
self.assertEqual(len(warning_list), 1)
self.assertEqual(warning_list[-1].category, DeprecationWarning)
:rtype: :class:`canvasapi.submission.Submission`
"""
from canvasapi.assignment import Assignment
from canvasapi.user import User
warnings.warn(
"`Course.update_submission()` is deprecated and will be removed in a "
"future version. Use `Submission.edit()` instead",
DeprecationWarning,
)
assignment_id = obj_or_id(assignment, "assignment", (Assignment,))
user_id = obj_or_id(user, "user", (User,))
submission = Submission(
self._requester,
{"course_id": self.id, "assignment_id": assignment_id, "user_id": user_id},
)
return submission.edit(**kwargs)
:rtype: `bool`
"""
from canvasapi.assignment import Assignment
from canvasapi.user import User
warnings.warn(
'Section.mark_submission_as_read() is deprecated and will be '
'removed in the future. Use Submission.mark_read() instead.',
DeprecationWarning
)
assignment_id = obj_or_id(assignment, "assignment", (Assignment,))
user_id = obj_or_id(user, "user", (User,))
submission = Submission(self._requester, {
'course_id': self.course_id,
'assignment_id': assignment_id,
'user_id': user_id
})
return submission.mark_read(**kwargs)
:rtype: `bool`
"""
from canvasapi.assignment import Assignment
from canvasapi.user import User
warnings.warn(
'Section.mark_submission_as_unread() is deprecated and will be '
'removed in the future. Use Submission.mark_unread() instead.',
DeprecationWarning
)
assignment_id = obj_or_id(assignment, "assignment", (Assignment,))
user_id = obj_or_id(user, "user", (User,))
submission = Submission(self._requester, {
'course_id': self.course_id,
'assignment_id': assignment_id,
'user_id': user_id
})
return submission.mark_unread(**kwargs)
def __init__(self, requester, attributes):
try:
self.submissions = [
Submission(requester, submission)
for submission in attributes["submissions"]
]
del attributes["submissions"]
except KeyError:
self.submissions = list()
super(GroupedSubmission, self).__init__(requester, attributes)
:rtype: `bool`
"""
from canvasapi.assignment import Assignment
from canvasapi.user import User
warnings.warn(
"`Course.mark_submission_as_read()` is deprecated and will be "
"removed in a future version. Use `Submission.mark_read()` instead.",
DeprecationWarning,
)
assignment_id = obj_or_id(assignment, "assignment", (Assignment,))
user_id = obj_or_id(user, "user", (User,))
submission = Submission(
self._requester,
{"course_id": self.id, "assignment_id": assignment_id, "user_id": user_id},
)
return submission.mark_read(**kwargs)
List submissions for multiple assignments.
Get all existing submissions for a given set of students and assignments.
:calls: `GET /api/v1/courses/:course_id/students/submissions \
`_
:rtype: :class:`canvasapi.paginated_list.PaginatedList` of
:class:`canvasapi.submission.Submission`
"""
is_grouped = kwargs.get("grouped", False)
if normalize_bool(is_grouped, "grouped"):
cls = GroupedSubmission
else:
cls = Submission
return PaginatedList(
cls,
self._requester,
"GET",
"courses/{}/students/submissions".format(self.id),
{"course_id": self.id},
_kwargs=combine_kwargs(**kwargs),
)
:calls: `PUT /api/v1/courses/:course_id/assignments/:assignment_id/submissions/:user_id \
`_
:rtype: :class:`canvasapi.submission.Submission`
"""
response = self._requester.request(
"PUT",
"courses/{}/assignments/{}/submissions/{}".format(
self.course_id, self.assignment_id, self.user_id
),
_kwargs=combine_kwargs(**kwargs),
)
response_json = response.json()
response_json.update(course_id=self.course_id)
super(Submission, self).set_attributes(response_json)
return self