Skip to content

Commit

Permalink
Merge branch 'develop' into issue/97-accept-path-like-objects-for-fil…
Browse files Browse the repository at this point in the history
…e-uploads
  • Loading branch information
Thetwam committed Mar 24, 2021
2 parents 5a687d4 + 7788745 commit 6c9a83b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Run tests

on: [push]
on: [push, pull_request]

jobs:
build:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions canvasapi/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
20 changes: 20 additions & 0 deletions tests/test_canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
20 changes: 0 additions & 20 deletions tests/test_poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6c9a83b

Please sign in to comment.