Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#150 Lowercase boolean values #151

Merged
merged 3 commits into from
Feb 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion canvasapi/requester.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,12 @@ def request(
for i, kwarg in enumerate(_kwargs):
kw, arg = kwarg

# Convert boolean objects to a lowercase string.
if isinstance(arg, bool):
_kwargs[i] = (kw, str(arg).lower())

# Convert any datetime objects into ISO 8601 formatted strings.
if isinstance(arg, datetime):
elif isinstance(arg, datetime):
_kwargs[i] = (kw, arg.isoformat())

# Determine the appropriate request method.
Expand Down
18 changes: 18 additions & 0 deletions tests/test_requester.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,24 @@ def test_request_cache_clear_after_5(self, m):
self.assertLessEqual(len(self.requester._cache), 5)
self.assertEqual(response, self.requester._cache[0])

def test_request_lowercase_boolean(self, m):
def custom_matcher(request):
match_text = 'test=true&test2=false'
if request.text == match_text:
resp = requests.Response()
resp.status_code = 200
return resp

m.add_matcher(custom_matcher)

response = self.requester.request(
'POST',
'test',
test=True,
test2=False
)
self.assertEqual(response.status_code, 200)

def test_request_400(self, m):
register_uris({'requests': ['400']}, m)

Expand Down