diff options
author | Marcin Kuzminski <marcin@python-works.com> | 2013-01-16 00:20:45 +0100 |
---|---|---|
committer | Marcin Kuzminski <marcin@python-works.com> | 2013-01-16 00:20:45 +0100 |
commit | d1c7aade661ca5184e5f53ddab248091cc333736 (patch) | |
tree | cee5530b33041499591cfe726ee16cc0c214091c | |
parent | 8611e3d91e54260fa7726382f72ff16cad4e3f8b (diff) |
fixes issue #702 API methods without arguments fail when "args":null
--HG--
branch : beta
-rw-r--r-- | rhodecode/controllers/api/__init__.py | 4 | ||||
-rw-r--r-- | rhodecode/tests/api/api_base.py | 28 |
2 files changed, 32 insertions, 0 deletions
diff --git a/rhodecode/controllers/api/__init__.py b/rhodecode/controllers/api/__init__.py index c4d6c11f..2f4e1416 100644 --- a/rhodecode/controllers/api/__init__.py +++ b/rhodecode/controllers/api/__init__.py @@ -132,6 +132,9 @@ class JSONRPCController(WSGIController): self._req_id = json_body['id'] self._req_method = json_body['method'] self._request_params = json_body['args'] + if not isinstance(self._request_params, dict): + self._request_params = {} + log.debug( 'method: %s, params: %s' % (self._req_method, self._request_params) @@ -212,6 +215,7 @@ class JSONRPCController(WSGIController): ) self._rpc_args = {USER_SESSION_ATTR: u} + self._rpc_args.update(self._request_params) self._rpc_args['action'] = self._req_method diff --git a/rhodecode/tests/api/api_base.py b/rhodecode/tests/api/api_base.py index 92d702d5..5e290582 100644 --- a/rhodecode/tests/api/api_base.py +++ b/rhodecode/tests/api/api_base.py @@ -155,6 +155,34 @@ class BaseTestApi(object): expected = 'Missing non optional `repoid` arg in JSON DATA' self._compare_error(id_, expected, given=response.body) + def test_api_missing_non_optional_param_args_null(self): + id_, params = _build_data(self.apikey, 'get_repo') + params = params.replace('"args": {}', '"args": null') + response = api_call(self, params) + + expected = 'Missing non optional `repoid` arg in JSON DATA' + self._compare_error(id_, expected, given=response.body) + + def test_api_missing_non_optional_param_args_bad(self): + id_, params = _build_data(self.apikey, 'get_repo') + params = params.replace('"args": {}', '"args": 1') + response = api_call(self, params) + + expected = 'Missing non optional `repoid` arg in JSON DATA' + self._compare_error(id_, expected, given=response.body) + + def test_api_args_is_null(self): + id_, params = _build_data(self.apikey, 'get_users',) + params = params.replace('"args": {}', '"args": null') + response = api_call(self, params) + self.assertEqual(response.status, '200 OK') + + def test_api_args_is_bad(self): + id_, params = _build_data(self.apikey, 'get_users',) + params = params.replace('"args": {}', '"args": 1') + response = api_call(self, params) + self.assertEqual(response.status, '200 OK') + def test_api_get_users(self): id_, params = _build_data(self.apikey, 'get_users',) response = api_call(self, params) |