Repository: ucfopen/canvasapi

Issue:
Files Resolve Path
#375 / #378 Added support for `GET /api/v1/courses/:course_id/folders/by_path/*full_path`, but there are several other related endpoints under the "Resolve Path" umbrella.

**What resource needs additional coverage?**
Files, Folders, "Resolve Path"

**What endpoints need to be covered?**

- [ ] `GET /api/v1/courses/:course_id/folders/by_path`
- [ ] `GET /api/v1/users/:user_id/folders/by_path/*full_path`
- [ ] `GET /api/v1/users/:user_id/folders/by_path`
- [ ] `GET /api/v1/groups/:group_id/folders/by_path/*full_path`
- [ ] `GET /api/v1/groups/:group_id/folders/by_path`

https://canvas.instructure.com/doc/api/files.html#method.folders.resolve_path


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

Coverage remained the same at 100.0% when pulling **3ccdda915d6e16a1750e2dc9894f52602c6b91a7 on dsavransky:resolvepath** into **44967b49f9847005a524305f508e071f35d37773 on ucfopen:develop**.


Patch:
diff --git a/.gitignore b/.gitignore
index 3cfe0c5..f6b23d7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,3 +20,4 @@
 .vscode/settings.json
 setup.sh
 .python-version
+.*.swp
diff --git a/canvasapi/course.py b/canvasapi/course.py
index 79786ef..d1177e0 100644
--- a/canvasapi/course.py
+++ b/canvasapi/course.py
@@ -2317,27 +2317,38 @@ class Course(CanvasObject):
         )
         return Course(self._requester, response.json())
 
-    def resolve_path(self, full_path, **kwargs):
+    def resolve_path(self, full_path=None, **kwargs):
         """
         Returns the paginated list of all of the folders in the given
-        path starting at the course root folder.
+        path starting at the course root folder. Returns root folder if called
+        with no arguments.
 
         :calls: `GET /api/v1/courses/:course_id/folders/by_path/*full_path \
         <https://canvas.instructure.com/doc/api/files.html#method.folders.resolve_path>`_
 
-        :param full_path: Full path to resolve, relative to course root
+        :param full_path: Full path to resolve, relative to course root.
         :type full_path: string
 
         :rtype: :class:`canvasapi.paginated_list.PaginatedList` of
             :class:`canvasapi.folder.Folder`
         """
-        return PaginatedList(
-            Folder,
-            self._requester,
-            "GET",
-            "courses/{0}/folders/by_path/{1}".format(self.id, full_path),
-            _kwargs=combine_kwargs(**kwargs),
-        )
+
+        if full_path:
+            return PaginatedList(
+                Folder,
+                self._requester,
+                "GET",
+                "courses/{0}/folders/by_path/{1}".format(self.id, full_path),
+                _kwargs=combine_kwargs(**kwargs),
+            )
+        else:
+            return PaginatedList(
+                Folder,
+                self._requester,
+                "GET",
+                "courses/{0}/folders/by_path".format(self.id),
+                _kwargs=combine_kwargs(**kwargs),
+            )
 
     def set_quiz_extensions(self, quiz_extensions, **kwargs):
         """
diff --git a/canvasapi/group.py b/canvasapi/group.py
index 558fa75..5baa608 100644
--- a/canvasapi/group.py
+++ b/canvasapi/group.py
@@ -827,6 +827,39 @@ class Group(CanvasObject):
 
         return response.json().get("reorder")
 
+    def resolve_path(self, full_path=None, **kwargs):
+        """
+        Returns the paginated list of all of the folders in the given
+        path starting at the group root folder. Returns root folder if called
+        with no arguments.
+
+        :calls: `GET /api/v1/groups/group_id/folders/by_path/*full_path \
+        <https://canvas.instructure.com/doc/api/files.html#method.folders.resolve_path>`_
+
+        :param full_path: Full path to resolve, relative to group root.
+        :type full_path: string
+
+        :rtype: :class:`canvasapi.paginated_list.PaginatedList` of
+            :class:`canvasapi.folder.Folder`
+        """
+
+        if full_path:
+            return PaginatedList(
+                Folder,
+                self._requester,
+                "GET",
+                "groups/{0}/folders/by_path/{1}".format(self.id, full_path),
+                _kwargs=combine_kwargs(**kwargs),
+            )
+        else:
+            return PaginatedList(
+                Folder,
+                self._requester,
+                "GET",
+                "groups/{0}/folders/by_path".format(self.id),
+                _kwargs=combine_kwargs(**kwargs),
+            )
+
     def set_usage_rights(self, **kwargs):
         """
         Changes the usage rights for specified files that are under the current group scope
diff --git a/canvasapi/user.py b/canvasapi/user.py
index 78f5a62..a8178b4 100644
--- a/canvasapi/user.py
+++ b/canvasapi/user.py
@@ -788,6 +788,39 @@ class User(CanvasObject):
 
         return response.json()
 
+    def resolve_path(self, full_path=None, **kwargs):
+        """
+        Returns the paginated list of all of the folders in the given
+        path starting at the user root folder. Returns root folder if called
+        with no arguments.
+
+        :calls: `GET /api/v1/users/:user_id/folders/by_path/*full_path \
+        <https://canvas.instructure.com/doc/api/files.html#method.folders.resolve_path>`_
+
+        :param full_path: Full path to resolve, relative to user root.
+        :type full_path: string
+
+        :rtype: :class:`canvasapi.paginated_list.PaginatedList` of
+            :class:`canvasapi.folder.Folder`
+        """
+
+        if full_path:
+            return PaginatedList(
+                Folder,
+                self._requester,
+                "GET",
+                "users/{0}/folders/by_path/{1}".format(self.id, full_path),
+                _kwargs=combine_kwargs(**kwargs),
+            )
+        else:
+            return PaginatedList(
+                Folder,
+                self._requester,
+                "GET",
+                "users/{0}/folders/by_path".format(self.id),
+                _kwargs=combine_kwargs(**kwargs),
+            )
+
     def set_usage_rights(self, **kwargs):
         """
         Changes the usage rights for specified files that are under the user scope


Test patch:
diff --git a/tests/fixtures/course.json b/tests/fixtures/course.json
index 9cfe312..8242170 100644
--- a/tests/fixtures/course.json
+++ b/tests/fixtures/course.json
@@ -2211,13 +2211,12 @@
 				"name": "course_files",
 				"full_name": "course_files"
 			},
-
 			{
 				"id": 3,
 				"files_count": 0,
 				"folders_count": 1,
 				"name": "Folder_Level_1",
-				"full_name": "course_files"
+				"full_name": "course_files/Folder_Level_1"
 			},
 			{
 				"id": 4,
@@ -2235,5 +2234,19 @@
 			}
 		],
 		"status_code": 200
+	},
+    "resolve_path_null": {
+		"method": "GET",
+		"endpoint": "courses/1/folders/by_path",
+		"data": [
+            {
+				"id": 2,
+				"files_count": 0,
+				"folders_count": 1,
+				"name": "course_files",
+				"full_name": "course_files"
+			}
+        ],
+		"status_code": 200
 	}
 }
diff --git a/tests/fixtures/group.json b/tests/fixtures/group.json
index 57af19e..c115946 100644
--- a/tests/fixtures/group.json
+++ b/tests/fixtures/group.json
@@ -983,5 +983,54 @@
 			}
 		],
 		"status_code": 200
+	},
+    "resolve_path": {
+		"method": "GET",
+		"endpoint": "groups/1/folders/by_path/Folder_Level_1/Folder_Level_2/Folder_Level_3",
+		"data": [
+            {
+				"id": 2,
+				"files_count": 0,
+				"folders_count": 1,
+				"name": "files",
+				"full_name": "files"
+			},
+			{
+				"id": 3,
+				"files_count": 0,
+				"folders_count": 1,
+				"name": "Folder_Level_1",
+				"full_name": "files/Folder_Level_1"
+			},
+			{
+				"id": 4,
+				"files_count": 0,
+				"folders_count": 1,
+				"name": "Folder_Level_2",
+				"full_name": "files/Folder_Level_1/Folder_Level_2"
+			},
+			{
+				"id": 5,
+				"files_count": 0,
+				"folders_count": 0,
+				"name": "Folder_Level_3",
+				"full_name": "files/Folder_Level_1/Folder_Level_2/Folder_Level_3"
+			}
+		],
+		"status_code": 200
+	},
+    "resolve_path_null": {
+		"method": "GET",
+		"endpoint": "groups/1/folders/by_path",
+		"data": [
+            {
+				"id": 2,
+				"files_count": 0,
+				"folders_count": 1,
+				"name": "files",
+				"full_name": "files"
+			}
+        ],
+		"status_code": 200
 	}
 }
diff --git a/tests/fixtures/user.json b/tests/fixtures/user.json
index 2a41536..b180fc6 100644
--- a/tests/fixtures/user.json
+++ b/tests/fixtures/user.json
@@ -972,5 +972,54 @@
 			}
 		],
 		"status_code": 200
+	},
+    "resolve_path": {
+		"method": "GET",
+		"endpoint": "users/1/folders/by_path/Folder_Level_1/Folder_Level_2/Folder_Level_3",
+		"data": [
+            {
+				"id": 2,
+				"files_count": 0,
+				"folders_count": 1,
+				"name": "my_files",
+				"full_name": "my_files"
+			},
+			{
+				"id": 3,
+				"files_count": 0,
+				"folders_count": 1,
+				"name": "Folder_Level_1",
+				"full_name": "my_files/Folder_Level_1"
+			},
+			{
+				"id": 4,
+				"files_count": 0,
+				"folders_count": 1,
+				"name": "Folder_Level_2",
+				"full_name": "my_files/Folder_Level_1/Folder_Level_2"
+			},
+			{
+				"id": 5,
+				"files_count": 0,
+				"folders_count": 0,
+				"name": "Folder_Level_3",
+				"full_name": "my_files/Folder_Level_1/Folder_Level_2/Folder_Level_3"
+			}
+		],
+		"status_code": 200
+	},
+    "resolve_path_null": {
+		"method": "GET",
+		"endpoint": "users/1/folders/by_path",
+		"data": [
+            {
+				"id": 2,
+				"files_count": 0,
+				"folders_count": 1,
+				"name": "my_files",
+				"full_name": "my_files"
+			}
+        ],
+		"status_code": 200
 	}
 }
diff --git a/tests/test_course.py b/tests/test_course.py
index 3cdc9a5..8c30035 100644
--- a/tests/test_course.py
+++ b/tests/test_course.py
@@ -1701,11 +1701,21 @@ class TestCourse(unittest.TestCase):
         folder_list = [folder for folder in folders]
         self.assertEqual(len(folder_list), 4)
         self.assertIsInstance(folder_list[0], Folder)
-        for folder_name, folder in zip(
-            ("course_files/" + full_path).split("/"), folders
-        ):
+        folder_names = ("course_files/" + full_path).split("/")
+        for folder_name, folder in zip(folder_names, folders):
             self.assertEqual(folder_name, folder.name)
 
+    # resolve_path() with null input
+    def test_resolve_path_null(self, m):
+        register_uris({"course": ["resolve_path_null"]}, m)
+
+        # test with null input
+        root_folder = self.course.resolve_path()
+        root_folder_list = [folder for folder in root_folder]
+        self.assertEqual(len(root_folder_list), 1)
+        self.assertIsInstance(root_folder_list[0], Folder)
+        self.assertEqual("course_files", root_folder_list[0].name)
+
 
 @requests_mock.Mocker()
 class TestCourseNickname(unittest.TestCase):
diff --git a/tests/test_group.py b/tests/test_group.py
index 5fa398a..705dff9 100644
--- a/tests/test_group.py
+++ b/tests/test_group.py
@@ -578,6 +578,30 @@ class TestGroup(unittest.TestCase):
 
         self.assertEqual(2, len(licenses))
 
+    # resolve_path()
+    def test_resolve_path(self, m):
+        register_uris({"group": ["resolve_path"]}, m)
+
+        full_path = "Folder_Level_1/Folder_Level_2/Folder_Level_3"
+        folders = self.group.resolve_path(full_path)
+        folder_list = [folder for folder in folders]
+        self.assertEqual(len(folder_list), 4)
+        self.assertIsInstance(folder_list[0], Folder)
+        folder_names = ("files/" + full_path).split("/")
+        for folder_name, folder in zip(folder_names, folders):
+            self.assertEqual(folder_name, folder.name)
+
+    # resolve_path() with null input
+    def test_resolve_path_null(self, m):
+        register_uris({"group": ["resolve_path_null"]}, m)
+
+        # test with null input
+        root_folder = self.group.resolve_path()
+        root_folder_list = [folder for folder in root_folder]
+        self.assertEqual(len(root_folder_list), 1)
+        self.assertIsInstance(root_folder_list[0], Folder)
+        self.assertEqual("files", root_folder_list[0].name)
+
 
 @requests_mock.Mocker()
 class TestGroupMembership(unittest.TestCase):
diff --git a/tests/test_user.py b/tests/test_user.py
index 90e4aea..d46e26f 100644
--- a/tests/test_user.py
+++ b/tests/test_user.py
@@ -540,6 +540,31 @@ class TestUser(unittest.TestCase):
 
         self.assertEqual(2, len(licenses))
 
+    # resolve_path()
+    def test_resolve_path(self, m):
+        register_uris({"user": ["resolve_path"]}, m)
+
+        full_path = "Folder_Level_1/Folder_Level_2/Folder_Level_3"
+        folders = self.user.resolve_path(full_path)
+        folder_list = [folder for folder in folders]
+        self.assertEqual(len(folder_list), 4)
+        self.assertIsInstance(folder_list[0], Folder)
+
+        folder_names = ("my_files/" + full_path).split("/")
+        for folder_name, folder in zip(folder_names, folders):
+            self.assertEqual(folder_name, folder.name)
+
+    # resolve_path() with null input
+    def test_resolve_path_null(self, m):
+        register_uris({"user": ["resolve_path_null"]}, m)
+
+        # test with null input
+        root_folder = self.user.resolve_path()
+        root_folder_list = [folder for folder in root_folder]
+        self.assertEqual(len(root_folder_list), 1)
+        self.assertIsInstance(root_folder_list[0], Folder)
+        self.assertEqual("my_files", root_folder_list[0].name)
+
 
 @requests_mock.Mocker()
 class TestUserDisplay(unittest.TestCase):