From 4a3334f90c5a5c8bff6b4d7d7877916de6f6942a Mon Sep 17 00:00:00 2001 From: Kyle Hornberg Date: Fri, 1 Jun 2018 15:28:53 -0500 Subject: [PATCH 1/2] Bug Fix: Send boolean defaults --- src/octokit/__init__.py | 9 ++++++++- tests/test_methods.py | 9 +++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/octokit/__init__.py b/src/octokit/__init__.py index c8e8ac2..7961aae 100644 --- a/src/octokit/__init__.py +++ b/src/octokit/__init__.py @@ -55,9 +55,16 @@ def _form_url(self, values, _url, params): def _get_data(self, kwargs, params): for param, value in params.items(): if value.get('default') and not kwargs.get(param): - kwargs[param] = value.get('default') + kwargs[param] = self._get_parameter_for_type(value) return kwargs + def _get_parameter_for_type(self, param): + if param.get('type') == 'boolean' and param.get('default') == 'true': + return True + if param.get('type') == 'boolean' and param.get('default') == 'false': + return False + return param.get('default') + def _data(self, data_kwargs, params, method): data = self._get_data(data_kwargs, params) if method == 'get': diff --git a/tests/test_methods.py b/tests/test_methods.py index 951f83c..433b71b 100644 --- a/tests/test_methods.py +++ b/tests/test_methods.py @@ -86,6 +86,15 @@ def test_validate_enum_values(self): Octokit().issues.edit(owner='testUser', repo='testRepo', number=1, state='closeddddd') assert 'closeddddd is not a valid option for state; must be one of [\'open\', \'closed\']' == str(e.value) + def test_validate_boolean_values(self, mocker): + mocker.patch('requests.post') + Octokit().repos.create_deployment(owner='testUser', repo='testRepo', ref='abc123') + data = '{"auto_merge": true, "description": "\\"\\"", "environment": "none", "payload": "\\"\\"", "ref": "abc123", "task": "deploy"}' # noqa E501 + headers = {'Content-Type': 'application/json', 'accept': 'application/vnd.github.ant-man-preview+json'} + requests.post.assert_called_once_with( + 'https://api.github.com/repos/testUser/testRepo/deployments', data=data, headers=headers + ) + def test_non_default_params_not_in_the_url_for_get_requests_go_in_the_query_string(self, mocker): mocker.patch('requests.get') params = {'page': 2, 'per_page': '30'} From cf69c84f2a6e574472eeed15eebe06b81493a053 Mon Sep 17 00:00:00 2001 From: Kyle Hornberg Date: Fri, 1 Jun 2018 15:29:18 -0500 Subject: [PATCH 2/2] Version: 0.7.1 -> 0.7.2 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 6dcd732..f443820 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ def read(*names, **kwargs): setup( name='octokitpy', - version='0.7.1', + version='0.7.2', license='MIT license', description='Python client for GitHub API', long_description='%s\n%s' % (