Skip to content

Commit

Permalink
Merge pull request #29 from khornberg/bug/bools
Browse files Browse the repository at this point in the history
Version: 0.7.1 -> 0.7.2
  • Loading branch information
khornberg authored Jun 1, 2018
2 parents 0898c93 + cf69c84 commit ed89094
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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' % (
Expand Down
9 changes: 8 additions & 1 deletion src/octokit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
9 changes: 9 additions & 0 deletions tests/test_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'}
Expand Down

0 comments on commit ed89094

Please sign in to comment.