Repository: ucfopen/canvasapi (language: python)

Issue:
Create Poll Incorrect Parameter
# Describe the bug

`Canvas.create_poll()` incorrectly requires `poll` instead of `polls`. If the user provides the required argument `poll`, Canvas responds with `{"errors":[{"message":"polls is missing"}]}`.

# To Reproduce

Steps to reproduce the behavior:

```python
canvas.create_poll(poll=[{"question": quest, "description": desc}])
```

# Expected behavior

`Canvas.create_poll` should require `polls` instead of `poll`.

# Environment information

<!--(please complete the following information)-->

- Python version (`python --version`)
any
- CanvasAPI version (`pip show canvasapi`)
2.1.0


Discussion / hints:

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 137c4ccb..181d4928 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,10 @@
 - Added `RateLimitExceeded` exception to distinguish between being rate limited and being otherwise forbidden from accesing a resource. It is a subclass of the `Forbidden` exception.
 - Set up GitHub Actions for running tests
 
+### Bugfixes
+
+- Fixed an issue where `Canvas.create_poll()` did not work due to an incorrect parameter.
+
 ## [2.1.0] - 2020-12-04
 
 ### New Endpoint Coverage
diff --git a/canvasapi/canvas.py b/canvasapi/canvas.py
index 4737f7b0..51b632ca 100644
--- a/canvasapi/canvas.py
+++ b/canvasapi/canvas.py
@@ -344,28 +344,28 @@ def create_planner_override(self, plannable_type, plannable_id, **kwargs):
         )
         return PlannerOverride(self.__requester, response.json())
 
-    def create_poll(self, poll, **kwargs):
+    def create_poll(self, polls, **kwargs):
         """
         Create a new poll for the current user.
 
         :calls: `POST /api/v1/polls \
         <https://canvas.instructure.com/doc/api/polls.html#method.polling/polls.create>`_
 
-        :param poll: List of polls to create. `'question'` key is required.
-        :type poll: list of dict
+        :param polls: List of polls to create. `'question'` key is required.
+        :type polls: list of dict
         :rtype: :class:`canvasapi.poll.Poll`
         """
         from canvasapi.poll import Poll
 
         if (
-            isinstance(poll, list)
-            and isinstance(poll[0], dict)
-            and "question" in poll[0]
+            isinstance(polls, list)
+            and isinstance(polls[0], dict)
+            and "question" in polls[0]
         ):
-            kwargs["poll"] = poll
+            kwargs["polls"] = polls
         else:
             raise RequiredFieldMissing(
-                "Dictionary with key 'question' and is required."
+                "List of dictionaries each with key 'question' is required."
             )
 
         response = self.__requester.request(


Test patch:
diff --git a/tests/test_canvas.py b/tests/test_canvas.py
index 2282d609..84be6e24 100644
--- a/tests/test_canvas.py
+++ b/tests/test_canvas.py
@@ -19,6 +19,7 @@
 from canvasapi.group import Group, GroupCategory
 from canvasapi.outcome import Outcome, OutcomeGroup
 from canvasapi.paginated_list import PaginatedList
+from canvasapi.poll import Poll
 from canvasapi.progress import Progress
 from canvasapi.section import Section
 from canvasapi.todo import Todo
@@ -93,6 +94,25 @@ def test_create_account(self, m):
         self.assertTrue(hasattr(account, "name"))
         self.assertEqual(account.name, name)
 
+    # create_poll()
+    def test_create_poll(self, m):
+        register_uris({"poll": ["create_poll"]}, m)
+
+        new_poll_q = self.canvas.create_poll([{"question": "Is this a question?"}])
+        self.assertIsInstance(new_poll_q, Poll)
+        self.assertTrue(hasattr(new_poll_q, "question"))
+
+        new_poll_q_d = self.canvas.create_poll(
+            [{"question": "Is this a question?"}, {"description": "This is a test."}]
+        )
+        self.assertIsInstance(new_poll_q_d, Poll)
+        self.assertTrue(hasattr(new_poll_q_d, "question"))
+        self.assertTrue(hasattr(new_poll_q_d, "description"))
+
+    def test_create_poll_fail(self, m):
+        with self.assertRaises(RequiredFieldMissing):
+            self.canvas.create_poll(polls={})
+
     # get_account()
     def test_get_account(self, m):
         register_uris({"account": ["get_by_id"]}, m)
diff --git a/tests/test_poll.py b/tests/test_poll.py
index 154bccca..da21776c 100644
--- a/tests/test_poll.py
+++ b/tests/test_poll.py
@@ -48,26 +48,6 @@ def test_get_poll(self, m):
         self.assertEqual(poll_by_obj.description, "This is a test.")
         self.assertEqual(poll_by_obj.created_at, "2014-01-07T13:10:19Z")
 
-    # create_poll()
-    def test_create_poll(self, m):
-        register_uris({"poll": ["create_poll"]}, m)
-
-        new_poll_q = self.canvas.create_poll([{"question": "Is this a question?"}])
-        self.assertIsInstance(new_poll_q, Poll)
-        self.assertTrue(hasattr(new_poll_q, "question"))
-
-        new_poll_q_d = self.canvas.create_poll(
-            [{"question": "Is this a question?"}, {"description": "This is a test."}]
-        )
-        self.assertIsInstance(new_poll_q_d, Poll)
-        self.assertTrue(hasattr(new_poll_q_d, "question"))
-        self.assertTrue(hasattr(new_poll_q_d, "description"))
-
-    # create_poll()
-    def test_create_poll_fail(self, m):
-        with self.assertRaises(RequiredFieldMissing):
-            self.canvas.create_poll(poll={})
-
     # update()
     def test_update(self, m):
         register_uris({"poll": ["update"]}, m)