Repository: ucfopen/canvasapi
Pull request #458 (2021-01-11 21:32:15)

Fixes issue (#371) - Adds endpoint for file quota information
- This adds support for the file quota endpoint provided by the canvas API

coveralls: 
[![Coverage Status](https://coveralls.io/builds/36305066/badge)](https://coveralls.io/builds/36305066)

Coverage remained the same at 100.0% when pulling **2f4b39b6af6800dd2b22e977f261655be709d24f on deundrewilliams:issue/371-file-quota-info** into **6b9f09183d1c19bd6fb9b0fe91771ca50315551f on ucfopen:develop**.


Patch:
diff --git a/canvasapi/course.py b/canvasapi/course.py
index 77af6d0..34512f6 100644
--- a/canvasapi/course.py
+++ b/canvasapi/course.py
@@ -1312,6 +1312,24 @@ class Course(CanvasObject):
         )
         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.
diff --git a/canvasapi/group.py b/canvasapi/group.py
index a228748..2812da6 100644
--- a/canvasapi/group.py
+++ b/canvasapi/group.py
@@ -493,6 +493,24 @@ class Group(CanvasObject):
         )
         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.
diff --git a/canvasapi/user.py b/canvasapi/user.py
index e7612aa..0cfb8c7 100644
--- a/canvasapi/user.py
+++ b/canvasapi/user.py
@@ -552,6 +552,24 @@ class User(CanvasObject):
         )
         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.


Test patch:
diff --git a/tests/fixtures/course.json b/tests/fixtures/course.json
index 32db324..df2bc19 100644
--- a/tests/fixtures/course.json
+++ b/tests/fixtures/course.json
@@ -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",
@@ -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>"
 							}
 						]
@@ -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>"
 							}
 						]
diff --git a/tests/fixtures/group.json b/tests/fixtures/group.json
index c115946..638e106 100644
--- a/tests/fixtures/group.json
+++ b/tests/fixtures/group.json
@@ -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",
diff --git a/tests/fixtures/user.json b/tests/fixtures/user.json
index 11b77b1..5c49be5 100644
--- a/tests/fixtures/user.json
+++ b/tests/fixtures/user.json
@@ -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",
diff --git a/tests/test_course.py b/tests/test_course.py
index 2fca3dc..8f95829 100644
--- a/tests/test_course.py
+++ b/tests/test_course.py
@@ -766,6 +766,15 @@ class TestCourse(unittest.TestCase):
         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(
diff --git a/tests/test_group.py b/tests/test_group.py
index 576be82..f5248d9 100644
--- a/tests/test_group.py
+++ b/tests/test_group.py
@@ -255,6 +255,15 @@ class TestGroup(unittest.TestCase):
         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(
diff --git a/tests/test_user.py b/tests/test_user.py
index 0391d3a..2234e0a 100644
--- a/tests/test_user.py
+++ b/tests/test_user.py
@@ -273,6 +273,15 @@ class TestUser(unittest.TestCase):
         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)