Repository: ucfopen/canvasapi

Issue:
Course sections coverage
Add coverage for course sections

https://canvas.instructure.com/doc/api/sections.html#method.sections.index

Also improve course section coverage to support the `include` parameter

https://canvas.instructure.com/doc/api/sections.html#method.sections.show

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

Coverage remained the same at 100.0% when pulling **482ea1d76add02887435faf7f61e5f4125af43a4 on andrew-gardener:issue/154-course-sections-converage** into **5a3b536d9cff7d79df58203f64531cf649a6d942 on ucfopen:develop**.

Thetwam: Hey @andrew-gardener, thanks for the pull request!

I believe we already cover this endpoint as [`Course.list_sections()`](http://canvasapi.readthedocs.io/en/latest/course-ref.html#canvasapi.course.Course.list_sections) ([here in the repo](https://github.com/ucfopen/canvasapi/blob/fec74692326591055df97451dd1fc24ff6e4dd0c/canvasapi/course.py#L673)). 

Internally, we have been talking about standardizing methods to always use the prefix `get_` rather than `list_` to avoid confusion. This seems like a good opportunity to change `list_sections` to `get_sections` for clarity. I've opened an issue for us to go through the library and change all `get_` to `list_` (#156), but for now we'll just do sections.

Your changes to `Course.get_section()` looks good! Good catch.

Would you like to handle the changing of `list_sections` to `get_sections`?
andrew-gardener: @Thetwam my bad! I didn't realize that it existed as `list_sections`

I've updated the PR to with the deprecation warning.

Patch:
diff --git a/canvasapi/course.py b/canvasapi/course.py
index e06fd8c..df55c63 100644
--- a/canvasapi/course.py
+++ b/canvasapi/course.py
@@ -1,5 +1,6 @@
 from __future__ import absolute_import, division, print_function, unicode_literals
-from warnings import warn
+
+import warnings
 
 from six import python_2_unicode_compatible, text_type
 
@@ -17,6 +18,8 @@ from canvasapi.user import UserDisplay
 from canvasapi.util import combine_kwargs, is_multivalued, obj_or_id
 from canvasapi.rubric import Rubric
 
+warnings.simplefilter('always', DeprecationWarning)
+
 
 @python_2_unicode_compatible
 class Course(CanvasObject):
@@ -541,12 +544,32 @@ class Course(CanvasObject):
             _kwargs=combine_kwargs(**kwargs)
         )
 
-    def get_section(self, section):
+    def get_sections(self, **kwargs):
+        """
+        List all sections in a course.
+
+        :calls: `GET /api/v1/courses/:course_id/sections \
+        <https://canvas.instructure.com/doc/api/sections.html#method.sections.index>`_
+
+        :rtype: :class:`canvasapi.paginated_list.PaginatedList` of
+            :class:`canvasapi.section.Section`
+        """
+        from canvasapi.section import Section
+
+        return PaginatedList(
+            Section,
+            self._requester,
+            'GET',
+            'courses/{}/sections'.format(self.id),
+            _kwargs=combine_kwargs(**kwargs)
+        )
+
+    def get_section(self, section, **kwargs):
         """
         Retrieve a section.
 
         :calls: `GET /api/v1/courses/:course_id/sections/:id \
-        <https://canvas.instructure.com/doc/api/sections.html#method.sections.index>`_
+        <https://canvas.instructure.com/doc/api/sections.html#method.sections.show>`_
 
         :param section: The object or ID of the section to retrieve.
         :type section: :class:`canvasapi.section.Section` or int
@@ -559,7 +582,8 @@ class Course(CanvasObject):
 
         response = self._requester.request(
             'GET',
-            'courses/{}/sections/{}'.format(self.id, section_id)
+            'courses/{}/sections/{}'.format(self.id, section_id),
+            _kwargs=combine_kwargs(**kwargs)
         )
         return Section(self._requester, response.json())
 
@@ -680,14 +704,12 @@ class Course(CanvasObject):
         :rtype: :class:`canvasapi.paginated_list.PaginatedList` of
             :class:`canvasapi.section.Section`
         """
-        from canvasapi.section import Section
-        return PaginatedList(
-            Section,
-            self._requester,
-            'GET',
-            'courses/{}/sections'.format(self.id),
-            _kwargs=combine_kwargs(**kwargs)
+        warnings.warn(
+            "`list_sections` is being deprecated and will be removed in a future version."
+            " Use `get_sections` instead",
+            DeprecationWarning
         )
+        return self.get_sections(**kwargs)
 
     def create_course_section(self, **kwargs):
         """
@@ -1202,7 +1224,7 @@ class Course(CanvasObject):
             :class:`canvasapi.submission.Submission`
         """
         if 'grouped' in kwargs:
-            warn('The `grouped` parameter must be empty. Removing kwarg `grouped`.')
+            warnings.warn('The `grouped` parameter must be empty. Removing kwarg `grouped`.')
             del kwargs['grouped']
 
         return PaginatedList(


Test patch:
diff --git a/tests/fixtures/course.json b/tests/fixtures/course.json
index 1aa9eb8..fa235c6 100644
--- a/tests/fixtures/course.json
+++ b/tests/fixtures/course.json
@@ -346,6 +346,43 @@
 		},
 		"status_code": 200
 	},
+	"get_sections": {
+		"method": "GET",
+		"endpoint": "courses/1/sections",
+		"data": [
+            {
+                "id": 1,
+                "name": "Section 1",
+                "course_id": 1
+            },
+            {
+                "id": 2,
+                "name": "Section 2",
+                "course_id": 1
+            }
+		],
+		"headers": {
+			"Link": "<http://example.com/api/v1/courses/1/sections?page=2&per_page=2>; rel=\"next\""
+		},
+		"status_code": 200
+	},
+	"get_sections_p2": {
+		"method": "GET",
+		"endpoint": "courses/1/sections?page=2&per_page=2",
+		"data": [
+            {
+                "id": 3,
+                "name": "Section 3",
+                "course_id": 1
+            },
+            {
+                "id": 4,
+                "name": "Section 4",
+                "course_id": 1
+            }
+		],
+		"status_code": 200
+	},
 	"get_user": {
 		"method": "GET",
 		"endpoint": "courses/1/users/1",
@@ -872,39 +909,6 @@
 		},
 		"status_code": 200
 	},
-	"list_sections": {
-		"method": "GET",
-		"endpoint": "courses/1/sections",
-		"data": [
-			{
-				"id": 1,
-				"name": "Section 1"
-			},
-			{
-				"id": 2,
-				"name": "Section 2"
-			}
-		],
-		"status_code": 200,
-		"headers": {
-			"Link": "<http://example.com/api/v1/courses/1/list_sections?page=2&per_page=2>; rel=\"next\""
-		}
-	},
-	"list_sections2": {
-		"method": "GET",
-		"endpoint": "courses/1/list_sections?page=2&per_page=2",
-		"data": [
-			{
-				"id": 3,
-				"name": "Section 3"
-			},
-			{
-				"id": 4,
-				"name": "Section 4"
-			}
-		],
-		"status_code": 200
-	},
 	"create_section": {
 		"method": "POST",
 		"endpoint": "courses/1/sections",
diff --git a/tests/test_course.py b/tests/test_course.py
index 888ca59..04aa27b 100644
--- a/tests/test_course.py
+++ b/tests/test_course.py
@@ -302,6 +302,16 @@ class TestCourse(unittest.TestCase):
         self.assertEqual(len(enrollment_list), 4)
         self.assertIsInstance(enrollment_list[0], Enrollment)
 
+    # get_sections()
+    def test_get_sections(self, m):
+        register_uris({'course': ['get_sections', 'get_sections_p2']}, m)
+
+        sections = self.course.get_sections()
+        section_list = [section for section in sections]
+
+        self.assertEqual(len(section_list), 4)
+        self.assertIsInstance(section_list[0], Section)
+
     # get_section
     def test_get_section(self, m):
         register_uris({'course': ['get_section']}, m)
@@ -434,13 +444,15 @@ class TestCourse(unittest.TestCase):
         self.assertEqual(len(tool_list), 4)
 
     def test_list_sections(self, m):
-        register_uris({'course': ['list_sections', 'list_sections2']}, m)
+        register_uris({'course': ['get_sections', 'get_sections_p2']}, m)
 
-        sections = self.course.list_sections()
-        section_list = [sect for sect in sections]
+        with warnings.catch_warnings(record=True) as w:
+            sections = self.course.list_sections()
+            section_list = [sect for sect in sections]
 
-        self.assertIsInstance(section_list[0], Section)
-        self.assertEqual(len(section_list), 4)
+            self.assertEqual(len(section_list), 4)
+            self.assertIsInstance(section_list[0], Section)
+            self.assertTrue(issubclass(w[0].category, DeprecationWarning))
 
     def test_create_course_section(self, m):
         register_uris({'course': ['create_section']}, m)