From 9811c8d3cfb374e7c6192bc2120ec424d24a07b2 Mon Sep 17 00:00:00 2001 From: Francesco Faraone Date: Tue, 19 Nov 2019 14:29:09 +0100 Subject: [PATCH 1/2] fix schema for ServerErrorResponse --- CHANGES.md | 5 ++++ README.md | 40 +++++++++++++++++++++++++-- connect/logger/logger.py | 4 +-- connect/models/schemas.py | 2 +- tests/data/response_server_error.json | 16 +++++++++++ tests/test_server_error_response.py | 23 +++++++++++++++ 6 files changed, 84 insertions(+), 6 deletions(-) create mode 100644 tests/data/response_server_error.json create mode 100644 tests/test_server_error_response.py diff --git a/CHANGES.md b/CHANGES.md index fa34316..273428a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,10 @@ # Connect SDK Changes History +## v17.6 + +* Fix: `ServerErrorResponseSchema` has a wrong errors field definition, it must be a list of strings. +* Fix: `function_log` decorator use list comprehension to set a custom formatter for each logging handler configured for the current logger. Changed to a for loop. + ## v17.5 * Fix: UsageFileAction's subclass SubmitUsageFile has a rejection note, a parameter which should go in RejectUsageFile instead. diff --git a/README.md b/README.md index 8455dd6..a399237 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Connect Python SDK allows an easy and fast integration with Connect fulfillment Please check the documentation available [here](https://connect-python-sdk.readthedocs.io), which contains information on how to install and use the library, and a complete API reference guide. -### Main Features +## Main Features This library may be consumed in your project in order to automate the fulfillment of requests, this class once imported into your project will allow you to: @@ -29,14 +29,48 @@ This library may be consumed in your project in order to automate the fulfillmen Your code may use any scheduler to execute, from a simple cron to a cloud scheduler like the ones available in Azure, Google, Amazon or other cloud platforms. -### Installation +## Installation ```sh $ pip install connect-sdk ``` -### Requirements +## Requirements * Python 2.7+ or Python 3.4+ * Requests (https://pypi.org/project/requests/) * Marshmallow (https://pypi.org/project/marshmallow/) + +## Contribute + +If you want to contribute to the connect-python-sdk development feel free to open issues or fork the github repository and submit your pull request. + +## Development + +### Getting started + +Assuming that you have python and virtualenv installed, and forked the connect-python-sdk repository, set up your environment and install the required dependencies like this: + +```sh +$ git clone https://github.com/{your_github_account}/connect-python-sdk.git +$ cd connect-python-sdk +$ virtualenv venv +$ . venv/bin/activate +$ pip install -r requirements/test.txt +``` + +### Running tests + +The connect-python-sdk uses [pytest](https://docs.pytest.org/en/latest/) for unit testing. + +To run the entire tests suite execute: + +```sh +$ pytest +``` + +## License + +The connect-python-sdk is released under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0). + + diff --git a/connect/logger/logger.py b/connect/logger/logger.py index 83ecabf..cb3db17 100644 --- a/connect/logger/logger.py +++ b/connect/logger/logger.py @@ -22,8 +22,8 @@ def function_log(custom_logger=None): custom_logger = logging.getLogger() sformat = " %(levelname)-6s; %(asctime)s; %(name)-6s; %(module)s:%(funcName)s:line" \ "-%(lineno)d: %(message)s" - [handler.setFormatter(logging.Formatter(sformat, "%I:%M:%S")) - for handler in custom_logger.handlers] + for handler in custom_logger.handlers: + handler.setFormatter(logging.Formatter(sformat, "%I:%M:%S")) # noinspection PyUnusedLocal def decorator(func, **kwargs): diff --git a/connect/models/schemas.py b/connect/models/schemas.py index 9f87780..a133e51 100644 --- a/connect/models/schemas.py +++ b/connect/models/schemas.py @@ -474,7 +474,7 @@ def make_object(self, data): class ServerErrorResponseSchema(BaseSchema): error_code = fields.Str() params = fields.Dict() - errors = fields.Str(many=True) + errors = fields.List(fields.Str()) @post_load def make_object(self, data): diff --git a/tests/data/response_server_error.json b/tests/data/response_server_error.json new file mode 100644 index 0000000..6c2af14 --- /dev/null +++ b/tests/data/response_server_error.json @@ -0,0 +1,16 @@ +{ + "errors": [ + "error_str_1", + "error_str_2" + ], + "error_code": "ERR_000", + "params": { + "param1": "value", + "param2": false, + "param3": ["a", "b", "c"], + "param4": { + "key": "value" + }, + "param5": 10 + } +} \ No newline at end of file diff --git a/tests/test_server_error_response.py b/tests/test_server_error_response.py new file mode 100644 index 0000000..6b662fe --- /dev/null +++ b/tests/test_server_error_response.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- + +# This file is part of the Ingram Micro Cloud Blue Connect SDK. +# Copyright (c) 2019 Ingram Micro. All Rights Reserved. + +import os + +from connect.models import ServerErrorResponse +from .common import load_str + + +server_error_response_content = load_str( + os.path.join(os.path.dirname(__file__), 'data', 'response_server_error.json')) + + +def test_server_error_response_attributes(): + # type: () -> None + srv_error = ServerErrorResponse.deserialize(server_error_response_content) + assert isinstance(srv_error, ServerErrorResponse) + assert srv_error.error_code == 'ERR_000' + assert isinstance(srv_error.errors, list) + assert len(srv_error.errors) == 2 + assert isinstance(srv_error.params, dict) From 520b9a51b102ac5fa6cd2427cd73db2d024d34fd Mon Sep 17 00:00:00 2001 From: Francesco Faraone Date: Tue, 19 Nov 2019 14:43:43 +0100 Subject: [PATCH 2/2] fix no newline at end of file --- tests/data/response_server_error.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/data/response_server_error.json b/tests/data/response_server_error.json index 6c2af14..905f09a 100644 --- a/tests/data/response_server_error.json +++ b/tests/data/response_server_error.json @@ -13,4 +13,4 @@ }, "param5": 10 } -} \ No newline at end of file +}