Repository: ucfopen/canvasapi (language: python)

Issue:
Add "list observers" endpoint coverage
**What resource needs additional coverage?**
User

**What endpoints need to be covered?**
GET /api/v1/users/:user_id/observers
https://canvas.instructure.com/doc/api/user_observees.html#method.user_observees.observers

The "list observees" already exists and it seems to be pretty easy to add support for "list observers" because it's almost identical to the existing function. I tested this and it works great, I just don't know how to write the tests for it to do a real contribution.

```
def get_observers(self, **kwargs):
        """
        List the users that are observing the given user.

        :calls:  `GET /api/v1/users/:user_id/observers \
        <https://canvas.instructure.com/doc/api/user_observees.html#method.user_observees.observers>`_

        :rtype: :class:`canvasapi.paginated_list.PaginatedList` of
            :class:`canvasapi.user.User`
        """

        return PaginatedList(
            User,
            self._requester,
            "GET",
            "users/{}/observers".format(self.id),
            _kwargs=combine_kwargs(**kwargs),
        )
```



Discussion / hints:

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3798213e..75663546 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,7 @@
 - Delete a Rubric (Thanks, [@ggarfink](https://github.com/ggarfink))
 - Grade Change Log for Assignments, Courses, and Users (Thanks, [@matthewf-ucsd](https://github.com/matthewf-ucsd))
 - Content Migrations: List items for selective import (Thanks, [@matthewf-ucsd](https://github.com/matthewf-ucsd))
+- List observers of a User (Thanks, [@bennettscience](https://github.com/bennettscience))
 
 ### General
 
diff --git a/canvasapi/user.py b/canvasapi/user.py
index 7f3f4f54..6804e65e 100644
--- a/canvasapi/user.py
+++ b/canvasapi/user.py
@@ -752,6 +752,25 @@ def get_observees(self, **kwargs):
             _kwargs=combine_kwargs(**kwargs),
         )
 
+    def get_observers(self, **kwargs):
+        """
+        List the users that are observing the given user.
+
+        :calls:  `GET /api/v1/users/:user_id/observers \
+        <https://canvas.instructure.com/doc/api/user_observees.html#method.user_observees.observers>`_
+
+        :rtype: :class:`canvasapi.paginated_list.PaginatedList` of
+            :class:`canvasapi.user.User`
+        """
+
+        return PaginatedList(
+            User,
+            self._requester,
+            "GET",
+            "users/{}/observers".format(self.id),
+            _kwargs=combine_kwargs(**kwargs),
+        )
+
     def get_open_poll_sessions(self, **kwargs):
         """
         Returns a paginated list of all opened poll sessions available to the current user.


Test patch:
diff --git a/tests/fixtures/user.json b/tests/fixtures/user.json
index 09e40e4b..babaff54 100644
--- a/tests/fixtures/user.json
+++ b/tests/fixtures/user.json
@@ -735,6 +735,21 @@
 		],
 		"status_code": 200
 	},
+	"list_observers": {
+		"method": "GET",
+		"endpoint": "users/1/observers",
+		"data": [
+			{
+				"id": 3,
+				"name": "User 3"
+			},
+			{
+				"id": 4,
+				"name": "User 4"
+			}
+		],
+		"status_code": 200
+	},
 	"add_observee_with_credentials": {
 		"method": "POST",
 		"endpoint": "users/1/observees",
diff --git a/tests/test_user.py b/tests/test_user.py
index fce4896c..f6574f5c 100644
--- a/tests/test_user.py
+++ b/tests/test_user.py
@@ -362,6 +362,16 @@ def test_get_observees(self, m):
         self.assertIsInstance(observees_list[0], User)
         self.assertEqual(len(observees_list), 4)
 
+    def test_get_observers(self, m):
+        requires = {"user": ["list_observers", "list_observers"]}
+        register_uris(requires, m)
+
+        response = self.user.get_observers()
+        observers_list = [observers for observers in response]
+
+        self.assertIsInstance(observers_list[0], User)
+        self.assertEqual(len(observers_list), 2)
+
     # add_observee_with_credentials()
     def test_add_observee_with_credentials(self, m):
         register_uris({"user": ["add_observee_with_credentials"]}, m)