Skip to content

Commit

Permalink
Merge branch 'develop' into issue/439-highlight-canvasapi-projects
Browse files Browse the repository at this point in the history
  • Loading branch information
Thetwam committed Jan 26, 2021
2 parents ab48916 + 6e8b81a commit 4a6b018
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 9 deletions.
18 changes: 18 additions & 0 deletions canvasapi/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,24 @@ def get_file(self, file, **kwargs):
)
return File(self._requester, response.json())

def get_file_quota(self, **kwargs):
"""
Returns the total and used storage quota for the course.
:calls: `GET /api/v1/courses/:course_id/files/quota \
<https://canvas.instructure.com/doc/api/files.html#method.files.api_quota>`_
:rtype: dict
"""

response = self._requester.request(
"GET",
"courses/{}/files/quota".format(self.id),
_kwargs=combine_kwargs(**kwargs),
)

return response.json()

def get_files(self, **kwargs):
"""
Returns the paginated list of files for the course.
Expand Down
18 changes: 18 additions & 0 deletions canvasapi/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,24 @@ def get_file(self, file, **kwargs):
)
return File(self._requester, response.json())

def get_file_quota(self, **kwargs):
"""
Returns the total and used storage quota for the group.
:calls: `GET /api/v1/groups/:group_id/files/quota \
<https://canvas.instructure.com/doc/api/files.html#method.files.api_quota>`_
:rtype: dict
"""

response = self._requester.request(
"GET",
"groups/{}/files/quota".format(self.id),
_kwargs=combine_kwargs(**kwargs),
)

return response.json()

def get_files(self, **kwargs):
"""
Returns the paginated list of files for the group.
Expand Down
18 changes: 18 additions & 0 deletions canvasapi/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,24 @@ def get_file(self, file, **kwargs):
)
return File(self._requester, response.json())

def get_file_quota(self, **kwargs):
"""
Returns the total and used storage quota for the user.
:calls: `GET /api/v1/users/:user_id/files/quota \
<https://canvas.instructure.com/doc/api/files.html#method.files.api_quota>`_
:rtype: dict
"""

response = self._requester.request(
"GET",
"users/{}/files/quota".format(self.id),
_kwargs=combine_kwargs(**kwargs),
)

return response.json()

def get_files(self, **kwargs):
"""
Returns the paginated list of files for the user.
Expand Down
23 changes: 16 additions & 7 deletions tests/fixtures/course.json
Original file line number Diff line number Diff line change
Expand Up @@ -1334,7 +1334,16 @@
"size": 2048
},
"status_code": 200
},
},
"get_file_quota": {
"method": "GET",
"endpoint": "courses/1/files/quota",
"data": {
"quota": 524288000,
"quota_used": 402653184
},
"status_code": 200
},
"get_full_discussion_topic": {
"method": "GET",
"endpoint": "courses/1/discussion_topics/1/view",
Expand Down Expand Up @@ -1831,11 +1840,11 @@
"date": "2018-08-09",
"graders": [
{
"name": "John Smith",
"id": 49,
"name": "John Smith",
"id": 49,
"assignments":[
{
"id": 44,
"id": 44,
"description": "<p>homework1</p>"
}
]
Expand All @@ -1846,11 +1855,11 @@
"date": "2019-10-24",
"graders": [
{
"name": "Sara Hanks",
"id": 32,
"name": "Sara Hanks",
"id": 32,
"assignments":[
{
"id": 19,
"id": 19,
"description": "<p>homework2</p>"
}
]
Expand Down
11 changes: 10 additions & 1 deletion tests/fixtures/group.json
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,16 @@
"size": 4096
},
"status_code": 200
},
},
"get_file_quota": {
"method": "GET",
"endpoint": "groups/1/files/quota",
"data": {
"quota": 777648912,
"quota_used": 567864213
},
"status_code": 200
},
"get_full_discussion_topic": {
"method": "GET",
"endpoint": "groups/1/discussion_topics/1/view",
Expand Down
11 changes: 10 additions & 1 deletion tests/fixtures/user.json
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,16 @@
"size": 1024
},
"status_code": 200
},
},
"get_file_quota": {
"method": "GET",
"endpoint": "users/1/files/quota",
"data": {
"quota": 889234510,
"quota_used": 476231098
},
"status_code": 200
},
"get_folder": {
"method": "GET",
"endpoint": "users/1/folders/1",
Expand Down
9 changes: 9 additions & 0 deletions tests/test_course.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,15 @@ def test_get_file(self, m):
self.assertEqual(file_by_obj.display_name, "Course_File.docx")
self.assertEqual(file_by_obj.size, 2048)

# get_file_quota()
def test_get_file_quota(self, m):
register_uris({"course": ["get_file_quota"]}, m)

file_quota = self.course.get_file_quota()
self.assertIsInstance(file_quota, dict)
self.assertEqual(file_quota["quota"], 524288000)
self.assertEqual(file_quota["quota_used"], 402653184)

# get_full_discussion_topic()
def test_get_full_discussion_topic(self, m):
register_uris(
Expand Down
9 changes: 9 additions & 0 deletions tests/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,15 @@ def test_get_file(self, m):
self.assertEqual(file_by_obj.display_name, "Group_File.docx")
self.assertEqual(file_by_obj.size, 4096)

# get_file_quota()
def test_get_file_quota(self, m):
register_uris({"group": ["get_file_quota"]}, m)

file_quota = self.group.get_file_quota()
self.assertIsInstance(file_quota, dict)
self.assertEqual(file_quota["quota"], 777648912)
self.assertEqual(file_quota["quota_used"], 567864213)

# get_full_discussion_topic
def test_get_full_discussion_topic(self, m):
register_uris(
Expand Down
9 changes: 9 additions & 0 deletions tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,15 @@ def test_get_file(self, m):
self.assertEqual(file_by_obj.display_name, "User_File.docx")
self.assertEqual(file_by_obj.size, 1024)

# get_file_quota()
def test_get_file_quota(self, m):
register_uris({"user": ["get_file_quota"]}, m)

file_quota = self.user.get_file_quota()
self.assertIsInstance(file_quota, dict)
self.assertEqual(file_quota["quota"], 889234510)
self.assertEqual(file_quota["quota_used"], 476231098)

# get_folder()
def test_get_folder(self, m):
register_uris({"user": ["get_folder"]}, m)
Expand Down

0 comments on commit 4a6b018

Please sign in to comment.