diff --git a/apimatic_core/utilities/api_helper.py b/apimatic_core/utilities/api_helper.py index 29ca060..26d5cc2 100644 --- a/apimatic_core/utilities/api_helper.py +++ b/apimatic_core/utilities/api_helper.py @@ -108,7 +108,7 @@ def json_deserialize(json, unboxing_function=None, as_dict=False): JSON serialized string. """ - if json is None: + if json is None or json.strip() == '': return None try: diff --git a/setup.py b/setup.py index 347a99b..1427192 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ setup( name='apimatic-core', - version='0.2.14', + version='0.2.15', description='A library that contains core logic and utilities for ' 'consuming REST APIs using Python SDKs generated by APIMatic.', long_description=long_description, diff --git a/tests/apimatic_core/response_handler_tests/test_response_handler.py b/tests/apimatic_core/response_handler_tests/test_response_handler.py index e88d566..183b35a 100644 --- a/tests/apimatic_core/response_handler_tests/test_response_handler.py +++ b/tests/apimatic_core/response_handler_tests/test_response_handler.py @@ -151,7 +151,10 @@ def test_simple_response_body_with_convertor(self, input_http_response, input_re @pytest.mark.parametrize('input_http_response, expected_response_body', [ (Base.response(text=ApiHelper.json_serialize(Base.employee_model())), - ApiHelper.json_serialize(Base.employee_model())) + ApiHelper.json_serialize(Base.employee_model())), + (Base.response(), None), + (Base.response(text=''), None), + (Base.response(text=' '), None) ]) def test_custom_type_response_body(self, input_http_response, expected_response_body): http_response = self.new_response_handler \ @@ -164,7 +167,10 @@ def test_custom_type_response_body(self, input_http_response, expected_response_ (Base.response(text='[1, 2, 3, 4]'), '[1, 2, 3, 4]'), (Base.response(text='{"key1": "value1", "key2": "value2"}'), '{"key1": "value1", "key2": "value2"}'), (Base.response(text='{"key1": "value1", "key2": [1, 2, 3, {"key1": "value1", "key2": "value2"}]}'), - '{"key1": "value1", "key2": [1, 2, 3, {"key1": "value1", "key2": "value2"}]}') + '{"key1": "value1", "key2": [1, 2, 3, {"key1": "value1", "key2": "value2"}]}'), + (Base.response(), None), + (Base.response(text=''), None), + (Base.response(text=' '), None) ]) def test_json_response_body(self, input_http_response, expected_response_body): http_response = self.new_response_handler \ @@ -267,7 +273,9 @@ def test_api_response_convertor(self, input_http_response, expected_response_bod @pytest.mark.parametrize('input_http_response, expected_response_body, expected_error_list', [ (Base.response(text='{"key1": "value1", "key2": "value2", "errors": ["e1", "e2"]}'), - '{"key1": "value1", "key2": "value2", "errors": ["e1", "e2"]}', ['e1', 'e2']) + '{"key1": "value1", "key2": "value2", "errors": ["e1", "e2"]}', ['e1', 'e2']), + (Base.response(text=''), None, None), + (Base.response(text=' '), None, None) ]) def test_api_response_with_errors(self, input_http_response, expected_response_body, expected_error_list): api_response = self.new_response_handler \ diff --git a/tests/apimatic_core/utility_tests/test_api_helper.py b/tests/apimatic_core/utility_tests/test_api_helper.py index abfe874..d595776 100644 --- a/tests/apimatic_core/utility_tests/test_api_helper.py +++ b/tests/apimatic_core/utility_tests/test_api_helper.py @@ -152,6 +152,8 @@ def test_json_serialize(self, input_value, expected_value): @pytest.mark.parametrize('input_json_value, unboxing_function, as_dict, expected_value', [ (None, None, False, None), ('true', None, False, 'true'), + ('', None, False, None), + (' ', None, False, None), (ApiHelper.json_serialize(Base.employee_model()), Employee.from_dictionary, False, ApiHelper.json_serialize(Base.employee_model())), (ApiHelper.json_serialize([Base.employee_model(), Base.employee_model()]), @@ -176,14 +178,6 @@ def test_json_deserialize(self, input_json_value, unboxing_function, as_dict, ex deserialized_value = ApiHelper.json_deserialize(input_json_value, unboxing_function, as_dict) assert ApiHelper.json_serialize(deserialized_value) == expected_value - @pytest.mark.parametrize('input_json', [ - True - ]) - def test_json_deserialize_value_error(self, input_json): - with pytest.raises(ValueError): - raise ValueError(input_json) - ApiHelper.json_deserialize(input_json) - @pytest.mark.parametrize('input_url, input_file_value, expected_value', [ ('C:\\PYTHON_GENERIC_LIB\\Tester\\models\\test_file.py', "test_file", 'C:\\PYTHON_GENERIC_LIB\\Tester\\schemas\\TestFile.json'), @@ -789,7 +783,9 @@ def test_get_content_type(self, input_value, output_value): @pytest.mark.parametrize('input_value, output_value', [ ('{"method": "GET", "body": {}, "uploadCount": 0}', {'body': {}, 'method': 'GET', 'uploadCount': 0}), ('I am a string', 'I am a string'), - (None, None) + (None, None), + ('', None), + (' ', None) ]) def test_dynamic_deserialize(self, input_value, output_value): assert ApiHelper.dynamic_deserialize(input_value) == output_value