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_copy_file(self, m):
register_uris({'folder': ['copy_file']}, m)
new_file = self.folder.copy_file(1)
self.assertIsInstance(new_file, File)
self.assertEqual(new_file.display_name, 'Dummy File-1')
self.assertEqual(new_file.id, 1)
def test_get_file(self, m):
register_uris({"file": ["get_by_id"]}, m)
file_by_id = self.canvas.get_file(1)
self.assertIsInstance(file_by_id, File)
self.assertEqual(file_by_id.display_name, "File.docx")
self.assertEqual(file_by_id.size, 6144)
file_by_obj = self.canvas.get_file(file_by_id)
self.assertIsInstance(file_by_obj, File)
self.assertEqual(file_by_obj.display_name, "File.docx")
self.assertEqual(file_by_obj.size, 6144)
def test_get_files(self, m):
register_uris({"user": ["get_user_files", "get_user_files2"]}, m)
files = self.user.get_files()
file_list = [file for file in files]
self.assertEqual(len(file_list), 4)
self.assertIsInstance(file_list[0], File)
def test_get_files(self, m):
register_uris({"course": ["list_course_files", "list_course_files2"]}, m)
files = self.course.get_files()
file_list = [file for file in files]
self.assertEqual(len(file_list), 4)
self.assertIsInstance(file_list[0], File)
def test_get_files(self, m):
register_uris({"group": ["list_group_files", "list_group_files2"]}, m)
files = self.group.get_files()
file_list = [file for file in files]
self.assertEqual(len(file_list), 4)
self.assertIsInstance(file_list[0], File)
def test_get_file(self, m):
register_uris({"course": ["get_file"]}, m)
file_by_id = self.course.get_file(1)
self.assertIsInstance(file_by_id, File)
self.assertEqual(file_by_id.display_name, "Course_File.docx")
self.assertEqual(file_by_id.size, 2048)
file_by_obj = self.course.get_file(file_by_id)
self.assertIsInstance(file_by_obj, File)
self.assertEqual(file_by_obj.display_name, "Course_File.docx")
self.assertEqual(file_by_obj.size, 2048)
Return the standard attachment json object for a file.
:calls: `GET /api/v1/files/:id \
`_
:param file: The object or ID of the file to retrieve.
:type file: :class:`canvasapi.file.File` or int
:rtype: :class:`canvasapi.file.File`
"""
file_id = obj_or_id(file, "file", (File,))
response = self.__requester.request(
"GET", "files/{}".format(file_id), _kwargs=combine_kwargs(**kwargs)
)
return File(self.__requester, response.json())
:param file: The object or ID of the file to retrieve.
:type file: :class:`canvasapi.file.File` or int
:rtype: :class:`canvasapi.file.File`
"""
from canvasapi.file import File
file_id = obj_or_id(file, "file", (File,))
response = self._requester.request(
"GET",
"courses/{}/files/{}".format(self.id, file_id),
_kwargs=combine_kwargs(**kwargs),
)
return File(self._requester, response.json())
def get_files(self, **kwargs):
"""
Returns the paginated list of files for the group.
:calls: `GET /api/v1/groups/:group_id/files \
`_
:rtype: :class:`canvasapi.paginated_list.PaginatedList` of
:class:`canvasapi.file.File`
"""
from canvasapi.file import File
return PaginatedList(
File,
self._requester,
"GET",
"groups/{}/files".format(self.id),
_kwargs=combine_kwargs(**kwargs),
)
def get_files(self, **kwargs):
"""
Returns the paginated list of files for the folder.
:calls: `GET /api/v1/folders/:id/files \
`_
:rtype: :class:`canvasapi.paginated_list.PaginatedList` of
:class:`canvasapi.file.File`
"""
from canvasapi.file import File
return PaginatedList(
File,
self._requester,
'GET',
'folders/{}/files'.format(self.id),
_kwargs=combine_kwargs(**kwargs)
)