From 0513b62c8defafb0cb640e33804a32928354b18d Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Sun, 25 Jun 2023 15:07:24 +0200 Subject: [PATCH 1/3] Pre-commit stuff --- roulier/api.py | 44 +++++-- roulier/carrier_action.py | 6 +- roulier/carriers/chronopost_fr/api.py | 10 +- roulier/carriers/dpd_fr_soap/transport.py | 10 +- roulier/carriers/geodis/geodis_encoder_ws.py | 3 +- .../geodis_fr/geodis_soap_transport.py | 14 +- .../geodis_fr/geodis_transport_rest.py | 20 ++- roulier/carriers/geodis_fr/tests/test_edi.py | 64 ++++----- .../carriers/geodis_fr/tests/test_tracking.py | 121 +++++++++--------- .../geodis_fr/tests/test_validate_address.py | 12 +- roulier/carriers/geodis_fr/tracking/api.py | 6 +- .../geodis_fr/validate_address/encoder.py | 3 +- roulier/carriers/gls_fr/glsbox/gls.py | 6 +- roulier/carriers/gls_fr/rest/api.py | 12 +- roulier/carriers/laposte_fr/api.py | 19 ++- roulier/carriers/laposte_fr/encoder.py | 7 +- roulier/carriers/laposte_fr/transport.py | 5 +- roulier/ws_tools.py | 4 +- setup.py | 4 +- 19 files changed, 238 insertions(+), 132 deletions(-) diff --git a/roulier/api.py b/roulier/api.py index 54c54fc..73a5664 100644 --- a/roulier/api.py +++ b/roulier/api.py @@ -204,7 +204,11 @@ def _service(self): "agencyId": {"default": ""}, "customerId": {"default": ""}, "shippingId": {"default": ""}, - "shippingDate": {"type": "date", "required": True, "empty": False,}, + "shippingDate": { + "type": "date", + "required": True, + "empty": False, + }, # 'description': 'Additionnal info visible by the client. Example : order number' "reference1": {"type": "string", "default": ""}, "reference2": {"type": "string", "default": ""}, @@ -228,7 +232,10 @@ def _schemas(self): class ApiPackingSlip(BaseApi): def _packing_slip_number(self): return { - "schema": {"type": "string", "empty": False,}, + "schema": { + "type": "string", + "empty": False, + }, "required": True, "excludes": "parcels_numbers", } @@ -236,7 +243,10 @@ def _packing_slip_number(self): def _parcels_numbers(self): return { "type": "list", - "schema": {"type": "string", "empty": False,}, + "schema": { + "type": "string", + "empty": False, + }, "empty": False, "required": True, "excludes": "packing_slip_number", @@ -258,25 +268,41 @@ def __init__(self, config_object): def _parcel_number(self): return { - "schema": {"type": "string", "empty": False, "default": "",}, + "schema": { + "type": "string", + "empty": False, + "default": "", + }, "required": True, } def _document_id(self): return { - "schema": {"type": "string", "empty": False, "default": "",}, + "schema": { + "type": "string", + "empty": False, + "default": "", + }, "required": True, } def _document_type(self): return { - "schema": {"type": "string", "empty": False, "default": "",}, + "schema": { + "type": "string", + "empty": False, + "default": "", + }, "required": True, } def _document_path(self): return { - "schema": {"type": "string", "empty": False, "default": "",}, + "schema": { + "type": "string", + "empty": False, + "default": "", + }, "required": True, } @@ -284,7 +310,9 @@ def _schemas(self): schema = {"auth": self._auth(), "service": {}} if self.current_action == "get_documents": schema["service"].update( - {"parcel_number": self._parcel_number(),} + { + "parcel_number": self._parcel_number(), + } ) elif self.current_action == "get_document": schema["service"].update( diff --git a/roulier/carrier_action.py b/roulier/carrier_action.py index 621c9fc..9d4a6ce 100755 --- a/roulier/carrier_action.py +++ b/roulier/carrier_action.py @@ -100,8 +100,8 @@ def get_packing_slip(self, carrier_type, action, data): class CarrierAddressValidation(CarrierWebservice, ABC): """ - Check if address is valid/known from the carrier and eventually get proposal - if addresses that could match the input + Check if address is valid/known from the carrier and eventually get proposal + if addresses that could match the input """ def validate_address(self, carrier_type, action, data): @@ -110,7 +110,7 @@ def validate_address(self, carrier_type, action, data): class CarrierGetEdi(CarrierBase, ABC): """ - Generate an EDI file. + Generate an EDI file. """ @property diff --git a/roulier/carriers/chronopost_fr/api.py b/roulier/carriers/chronopost_fr/api.py index 64be090..870d98e 100644 --- a/roulier/carriers/chronopost_fr/api.py +++ b/roulier/carriers/chronopost_fr/api.py @@ -71,7 +71,10 @@ def _parcel(self): def _address(self): schema = super(ChronopostFrApiParcel, self)._address() additional_fields = { - "civility": {"type": "string", "allowed": ["E", "L", "M"],}, + "civility": { + "type": "string", + "allowed": ["E", "L", "M"], + }, "contact_name": {"type": "string", "maxlength": 100}, "preAlert": {"type": "integer"}, } @@ -96,7 +99,10 @@ def _from_address(self): schema["preAlert"].update({"allowed": [0, 11]}) # strangely, civility seem really mandatory for shipper schema["civility"].update( - {"required": True, "empty": False,} + { + "required": True, + "empty": False, + } ) return schema diff --git a/roulier/carriers/dpd_fr_soap/transport.py b/roulier/carriers/dpd_fr_soap/transport.py index 8120080..104dafc 100755 --- a/roulier/carriers/dpd_fr_soap/transport.py +++ b/roulier/carriers/dpd_fr_soap/transport.py @@ -45,7 +45,15 @@ def handle_500(self, response): obj = objectify.fromstring(response.content) error_id = (obj.xpath("//ErrorId") or obj.xpath("//faultcode"))[0] error_message = (obj.xpath("//ErrorMessage") or obj.xpath("//faultstring"))[0] - raise CarrierError(response, [{"id": error_id, "message": error_message,}]) + raise CarrierError( + response, + [ + { + "id": error_id, + "message": error_message, + } + ], + ) def handle_200(self, response): """Handle response type 200 (success).""" diff --git a/roulier/carriers/geodis/geodis_encoder_ws.py b/roulier/carriers/geodis/geodis_encoder_ws.py index e9ed0b6..6f5c46a 100755 --- a/roulier/carriers/geodis/geodis_encoder_ws.py +++ b/roulier/carriers/geodis/geodis_encoder_ws.py @@ -68,7 +68,8 @@ def request_impression_etiquette(): def request_find_localite(): return { "body": template.render( - receiver_address=data["to_address"], xmlns=infos["xmlns"], + receiver_address=data["to_address"], + xmlns=infos["xmlns"], ), "headers": data["auth"], "infos": infos, diff --git a/roulier/carriers/geodis_fr/geodis_soap_transport.py b/roulier/carriers/geodis_fr/geodis_soap_transport.py index 24d3116..4ff56e1 100755 --- a/roulier/carriers/geodis_fr/geodis_soap_transport.py +++ b/roulier/carriers/geodis_fr/geodis_soap_transport.py @@ -53,7 +53,12 @@ def handle_500(self, response): and obj.xpath("//*[local-name() = 'code']")[0] or "" ) - errors = [{"id": id_message, "message": message,}] + errors = [ + { + "id": id_message, + "message": message, + } + ] raise CarrierError(response, errors) def handle_200(self, response): @@ -89,5 +94,10 @@ def handle_response(self, response): else: raise CarrierError( response, - [{"id": None, "message": "Unexpected status code from server",}], + [ + { + "id": None, + "message": "Unexpected status code from server", + } + ], ) diff --git a/roulier/carriers/geodis_fr/geodis_transport_rest.py b/roulier/carriers/geodis_fr/geodis_transport_rest.py index 9a7a1b8..617139a 100644 --- a/roulier/carriers/geodis_fr/geodis_transport_rest.py +++ b/roulier/carriers/geodis_fr/geodis_transport_rest.py @@ -59,13 +59,22 @@ def send(self, payload): def send_request(self, body, token): """Send body to geodis WS.""" ws_url = self.config.ws_url - return requests.post(ws_url, headers={"X-GEODIS-Service": token}, data=body,) + return requests.post( + ws_url, + headers={"X-GEODIS-Service": token}, + data=body, + ) def handle_500(self, response): """Handle reponse in case of ERROR 500 type.""" # TODO : put a try catch (like wrong server) log.warning("Geodis error 500") - errors = [{"id": "", "message": "",}] + errors = [ + { + "id": "", + "message": "", + } + ] raise CarrierError(response, errors) def handle_true_negative_error(self, response, payload): @@ -98,5 +107,10 @@ def handle_response(self, response): else: raise CarrierError( response, - [{"id": None, "message": "Unexpected status code from server",}], + [ + { + "id": None, + "message": "Unexpected status code from server", + } + ], ) diff --git a/roulier/carriers/geodis_fr/tests/test_edi.py b/roulier/carriers/geodis_fr/tests/test_edi.py index f34141b..c6f7dbb 100644 --- a/roulier/carriers/geodis_fr/tests/test_edi.py +++ b/roulier/carriers/geodis_fr/tests/test_edi.py @@ -6,64 +6,64 @@ PAYLOAD = { "shipments": [ { - "product": u"MES", + "product": "MES", "productOption": "RDW", "to_address": { - "city": u"PARIS", - "name": u"Test Customer", - "zip": u"75015", - "street1": u"12 RUE DE LA CONVENTION", + "city": "PARIS", + "name": "Test Customer", + "zip": "75015", + "street1": "12 RUE DE LA CONVENTION", "street2": "", "street3": "", - "phone": u"+33778787878", - "country": u"FR", - "email": u"test@test.com", + "phone": "+33778787878", + "country": "FR", + "email": "test@test.com", }, "productPriority": "3", "notifications": "P", "productTOD": "P", "reference2": "", - "reference1": u"test-ref", - "shippingId": u"11111111", + "reference1": "test-ref", + "shippingId": "11111111", "reference3": "", "parcels": [ - {"barcode": u"JVGTC1111111111111111", "weight": 5.0}, - {"barcode": u"JVGTC1234567891111111", "weight": 4.0}, + {"barcode": "JVGTC1111111111111111", "weight": 5.0}, + {"barcode": "JVGTC1234567891111111", "weight": 4.0}, ], } ], "from_address": { - "city": u"VILLEURBANNE", - "name": u"AKRETION", - "zip": u"69100", - "street1": u"27 rue Henri Rolland", + "city": "VILLEURBANNE", + "name": "AKRETION", + "zip": "69100", + "street1": "27 rue Henri Rolland", "street2": "", "street3": "", - "phone": u"+33645452556", - "country": u"FR", - "siret": u"79237773100023", - "email": u"contact@test.com", + "phone": "+33645452556", + "country": "FR", + "siret": "79237773100023", + "email": "contact@test.com", }, "service": { "depositId": "11111", - "interchangeSender": u"987654321", - "interchangeRecipient": u"123456789", + "interchangeSender": "987654321", + "interchangeRecipient": "123456789", "depositDate": datetime.datetime(2020, 12, 21, 13, 14, 53), - "customerId": u"193032", + "customerId": "193032", }, "sender_id": 1, - "agency_id": u"021059", + "agency_id": "021059", "agency_address": { - "city": u"Lomme", - "name": u"Geodis Lille Europe", - "zip": u"59160", - "mobile": u"+33320085555", - "street1": u"7 Avenue de la Rotonde", + "city": "Lomme", + "name": "Geodis Lille Europe", + "zip": "59160", + "mobile": "+33320085555", + "street1": "7 Avenue de la Rotonde", "street2": "", "street3": "", - "phone": u"+33320085555", - "country": u"FR", - "siret": u"45750735800044", + "phone": "+33320085555", + "country": "FR", + "siret": "45750735800044", }, } diff --git a/roulier/carriers/geodis_fr/tests/test_tracking.py b/roulier/carriers/geodis_fr/tests/test_tracking.py index 627a194..bb50f3f 100644 --- a/roulier/carriers/geodis_fr/tests/test_tracking.py +++ b/roulier/carriers/geodis_fr/tests/test_tracking.py @@ -72,7 +72,10 @@ def test_decoder_visit(): schema = { "str": "simple_string", "int": "simple_integer", - "inner": {"inner_a": "inner_a", "inner_b": "inner_b",}, + "inner": { + "inner_a": "inner_a", + "inner_b": "inner_b", + }, } data = { "simple_string": "abcdef", @@ -161,84 +164,84 @@ def test_decoder_visit(): ret_val = [ { "from_address": { - "city": u"STRASBOURG", - "country": u"FR", - "country_name": u"France", - "name": u"RETOUR", - "street1": u"axxxZ", - "street2": u"wcvwv", - "zip": u"69100", + "city": "STRASBOURG", + "country": "FR", + "country_name": "France", + "name": "RETOUR", + "street1": "axxxZ", + "street2": "wcvwv", + "zip": "69100", }, "parcels": {"weight": 9.0}, "service": { - "agencyId": u"122121", - "customerId": u"01234", - "option": u"RET", - "product": u"ENE", - "reference1": u"abcdeefefefe", - "reference2": u"", - "reference3": u"", - "shippingDate": u"2019-07-09", - "shippingId": u"12212122", + "agencyId": "122121", + "customerId": "01234", + "option": "RET", + "product": "ENE", + "reference1": "abcdeefefefe", + "reference2": "", + "reference3": "", + "shippingDate": "2019-07-09", + "shippingId": "12212122", }, "to_address": { - "city": u"LESQUIN", - "country": u"FR", - "country_name": u"France", - "name": u"TdsdsfsfsfsT", - "street1": u"27 rue Henri Rolland", - "street2": u"", - "zip": u"59810", + "city": "LESQUIN", + "country": "FR", + "country_name": "France", + "name": "TdsdsfsfsfsT", + "street1": "27 rue Henri Rolland", + "street2": "", + "zip": "59810", }, "tracking": { - "estDeliveryDate": u"2019-07-10", - "proofUrl": u"http://github.com/akretion/roulier", - "publicUrl": u"https://akretion.com", + "estDeliveryDate": "2019-07-10", + "proofUrl": "http://github.com/akretion/roulier", + "publicUrl": "https://akretion.com", "status": "DELIVERED", - "statusDate": u"2019-07-10", - "statusDetails": u"Livr\xe9e", - "trackingCode": u"12122121", + "statusDate": "2019-07-10", + "statusDetails": "Livr\xe9e", + "trackingCode": "12122121", }, }, { "from_address": { - "city": u"VILLEURBANNE", - "country": u"FR", - "country_name": u"France", - "name": u"RETOUR POUR AVARIE", - "street1": u"Akretion", - "street2": u"GRAND", - "zip": u"69100", + "city": "VILLEURBANNE", + "country": "FR", + "country_name": "France", + "name": "RETOUR POUR AVARIE", + "street1": "Akretion", + "street2": "GRAND", + "zip": "69100", }, "parcels": {"weight": 5.0}, "service": { - "agencyId": u"12121", - "customerId": u"1212121", - "option": u"RET", - "product": u"ENE", - "reference1": u"Shopinvader", - "reference2": u"", - "reference3": u"", - "shippingDate": u"2019-07-09", - "shippingId": u"1212121ae", + "agencyId": "12121", + "customerId": "1212121", + "option": "RET", + "product": "ENE", + "reference1": "Shopinvader", + "reference2": "", + "reference3": "", + "shippingDate": "2019-07-09", + "shippingId": "1212121ae", }, "to_address": { - "city": u"Villeurbanne", - "country": u"FR", - "country_name": u"France", - "name": u"Akretion", - "street1": u"27 Rue Henri Rolland", - "street2": u"", - "zip": u"69100", + "city": "Villeurbanne", + "country": "FR", + "country_name": "France", + "name": "Akretion", + "street1": "27 Rue Henri Rolland", + "street2": "", + "zip": "69100", }, "tracking": { - "estDeliveryDate": u"2019-07-10", - "proofUrl": u"http://github.com/akretion/roulier", - "publicUrl": u"http://akretion.com", + "estDeliveryDate": "2019-07-10", + "proofUrl": "http://github.com/akretion/roulier", + "publicUrl": "http://akretion.com", "status": "DELIVERED", - "statusDate": u"2019-07-10", - "statusDetails": u"Livr\xe9e", - "trackingCode": u"12212121", + "statusDate": "2019-07-10", + "statusDetails": "Livr\xe9e", + "trackingCode": "12212121", }, }, ] diff --git a/roulier/carriers/geodis_fr/tests/test_validate_address.py b/roulier/carriers/geodis_fr/tests/test_validate_address.py index 44c736c..16d3f1e 100644 --- a/roulier/carriers/geodis_fr/tests/test_validate_address.py +++ b/roulier/carriers/geodis_fr/tests/test_validate_address.py @@ -19,10 +19,10 @@ def test_geodis_correct_address(self): def test_geodis_wrong_city(self): payload = { - "to_address": {"city": u"Villeurbanne", "zip": u"59100", "country": u"FR"}, + "to_address": {"city": "Villeurbanne", "zip": "59100", "country": "FR"}, "auth": { - "login": u"45393e38323033372b3c3334", - "password": u"2d5a44584356", + "login": "45393e38323033372b3c3334", + "password": "2d5a44584356", "isTest": True, }, } @@ -33,10 +33,10 @@ def test_geodis_wrong_city(self): def test_geodis_wrong_zip(self): payload = { - "to_address": {"city": u"ROUBAIX", "zip": u"59199", "country": u"FR"}, + "to_address": {"city": "ROUBAIX", "zip": "59199", "country": "FR"}, "auth": { - "login": u"45393e38323033372b3c3334", - "password": u"2d5a44584356", + "login": "45393e38323033372b3c3334", + "password": "2d5a44584356", "isTest": True, }, } diff --git a/roulier/carriers/geodis_fr/tracking/api.py b/roulier/carriers/geodis_fr/tracking/api.py index 7596cf7..f76b576 100644 --- a/roulier/carriers/geodis_fr/tracking/api.py +++ b/roulier/carriers/geodis_fr/tracking/api.py @@ -52,7 +52,11 @@ class GeodisApiTrackingMapping(GeodisMappingIn): Used to rename fields.""" def _schemas(self): - return {"service": {"trackingId": {"rename": "noSuivi"},}} + return { + "service": { + "trackingId": {"rename": "noSuivi"}, + } + } class GeodisApiTracking(GeodisApiRestWs): diff --git a/roulier/carriers/geodis_fr/validate_address/encoder.py b/roulier/carriers/geodis_fr/validate_address/encoder.py index 1fce299..93c61ad 100755 --- a/roulier/carriers/geodis_fr/validate_address/encoder.py +++ b/roulier/carriers/geodis_fr/validate_address/encoder.py @@ -16,7 +16,8 @@ def transform_input_to_carrier_webservice(self, data): template = env.get_template("geodis_%s.xml" % action) return { "body": template.render( - receiver_address=data["to_address"], xmlns=self.config.xmlns, + receiver_address=data["to_address"], + xmlns=self.config.xmlns, ), "headers": data["auth"], } diff --git a/roulier/carriers/gls_fr/glsbox/gls.py b/roulier/carriers/gls_fr/glsbox/gls.py index 4d66a8c..04f8410 100644 --- a/roulier/carriers/gls_fr/glsbox/gls.py +++ b/roulier/carriers/gls_fr/glsbox/gls.py @@ -15,11 +15,11 @@ class Gls(Carrier): ws = GlsTransport() def api(self): - """ Expose how to communicate with GLS """ + """Expose how to communicate with GLS""" return self.encoder.api() def get(self, data, action=None): - """ Run an action with data against Gls WS """ + """Run an action with data against Gls WS""" if not action: action = "label" request = self.encoder.encode(data, action) @@ -38,5 +38,5 @@ def get(self, data, action=None): # shortcuts def get_label(self, data): - """ Generate a label """ + """Generate a label""" return self.get(data, "label") diff --git a/roulier/carriers/gls_fr/rest/api.py b/roulier/carriers/gls_fr/rest/api.py index ae3d6cb..d841f89 100644 --- a/roulier/carriers/gls_fr/rest/api.py +++ b/roulier/carriers/gls_fr/rest/api.py @@ -24,7 +24,11 @@ def _service(self): "allowed": ["A6", "A5", "A4"], } schema["labelFormat"].update( - {"type": "string", "default": "PDF", "allowed": ["PDF", "PNG", "ZPL"],} + { + "type": "string", + "default": "PDF", + "allowed": ["PDF", "PNG", "ZPL"], + } ) schema["incoterm"] = { "type": "string", @@ -44,7 +48,11 @@ def _address(self): schema["zip"].update(string_1_10) schema["phone"].update({"maxlength": 20}) schema["email"].update( - {"required": True, "minlength": 3, "maxlength": 100,} + { + "required": True, + "minlength": 3, + "maxlength": 100, + } ) schema["city"].update(string_2_35) schema.update( diff --git a/roulier/carriers/laposte_fr/api.py b/roulier/carriers/laposte_fr/api.py index 7334730..be5c8d2 100644 --- a/roulier/carriers/laposte_fr/api.py +++ b/roulier/carriers/laposte_fr/api.py @@ -206,7 +206,11 @@ def _customs(self): }, "default": [], }, - "category": {"required": True, "type": "integer", "maxlength": 1,}, + "category": { + "required": True, + "type": "integer", + "maxlength": 1, + }, "explanations": {"required": False, "type": "string", "regex": "^.{0,35}$"}, "original": { "type": "dict", @@ -228,7 +232,10 @@ def _customs(self): }, "officeOrigin": {"type": "string", "regex": "^.{0,35}$", "required": False}, "comments": {"type": "string", "regex": "^.{0,35}$", "required": False}, - "description": {"type": "string", "regex": "^.{1,}$",}, + "description": { + "type": "string", + "regex": "^.{1,}$", + }, "invoiceNumber": { "type": "string", "regex": "^.{0,35}$", @@ -373,7 +380,13 @@ def _schemas(self): schemas["service"]["language"] = { "default": "fr_FR", "type": "string", - "allowed": ["fr_FR", "en_GB", "es_ES", "de_DE", "it_IT",], + "allowed": [ + "fr_FR", + "en_GB", + "es_ES", + "de_DE", + "it_IT", + ], "required": False, } if self.current_action in ("create_document", "update_document"): diff --git a/roulier/carriers/laposte_fr/encoder.py b/roulier/carriers/laposte_fr/encoder.py index ef65bcf..6cfbc4c 100644 --- a/roulier/carriers/laposte_fr/encoder.py +++ b/roulier/carriers/laposte_fr/encoder.py @@ -132,7 +132,12 @@ def transform_input_to_carrier_webservice(self, data): ) filename = os.path.basename(data["service"]["document_path"]) with open(data["service"]["document_path"], mode="rb") as file: - files = {"file": (filename, file.read(),)} + files = { + "file": ( + filename, + file.read(), + ) + } body["filename"] = filename if data.get("parcelNumberList"): body["parcelNumberList"] = data["service"]["parcelNumberList"] diff --git a/roulier/carriers/laposte_fr/transport.py b/roulier/carriers/laposte_fr/transport.py index c6ec59e..41d1769 100644 --- a/roulier/carriers/laposte_fr/transport.py +++ b/roulier/carriers/laposte_fr/transport.py @@ -57,7 +57,10 @@ def raise_on_error(response_xml): xml = objectify.fromstring(response_xml) messages = xml.xpath("//messages") errors = [ - {"id": message.id, "message": str(message.messageContent),} + { + "id": message.id, + "message": str(message.messageContent), + } for message in messages if message.type == "ERROR" ] diff --git a/roulier/ws_tools.py b/roulier/ws_tools.py index be0875e..70cc3de 100755 --- a/roulier/ws_tools.py +++ b/roulier/ws_tools.py @@ -60,7 +60,7 @@ def get_parts(response): def png_to_zpl(png, rotate): - u"""Transform a PNG in a suitable format for ZPL. + """Transform a PNG in a suitable format for ZPL. .png is converted to GRF format. Printing a Portable Network Graphics (PNG) with zpl instructions (like DY) @@ -78,7 +78,7 @@ def base64_to_png(data): return BytesIO(base64.b64decode(data)) def get_grf(png, rotate): - u"""Get a GRF from a png. + """Get a GRF from a png. params: png: BytesIO stream diff --git a/setup.py b/setup.py index 352be79..afe92cf 100755 --- a/setup.py +++ b/setup.py @@ -20,7 +20,9 @@ "unidecode", "pycountry", ], - extras_requires={"dev": ["ptpython", "pytest"],}, + extras_requires={ + "dev": ["ptpython", "pytest"], + }, author="Hparfr ", author_email="roulier@hpar.fr", description="Label parcels without pain", From 82bb025513c682035a9bde72d66e26378f31c6b4 Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Sun, 25 Jun 2023 15:08:12 +0200 Subject: [PATCH 2/3] [IMP] Move ci from travis to github action --- .git-blame-ignore-revs | 1 + .github/workflows/ci.yml | 52 ++++++++++++++++++++++++++++++++++++++++ .pre-commit-config.yaml | 2 +- .travis.yml | 40 ------------------------------- tox.ini | 16 +++++++++++++ 5 files changed, 70 insertions(+), 41 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml create mode 100644 tox.ini diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index 2e8cd99..3764239 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -1,3 +1,4 @@ # black roulier c8f96f37968d26aacbc36f8f09616ff683a89392 b2064d9d658b385bfd46ef136da186522107f575 +1d31fdb69211052ee112e65db535df8f364a2e53 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..c6c38b6 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,52 @@ +name: CI + +on: + pull_request: + push: + branches: + - "master" + tags: + - "[0-9]+.[0-9]+.[0-9]+" + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + - uses: pre-commit/action@v2.0.0 + tests: + name: "Python ${{ matrix.python-version }}" + runs-on: "ubuntu-latest" + strategy: + fail-fast: false + matrix: + python-version: ["3.10", "3.11"] + steps: + - uses: "actions/checkout@v3" + - uses: "actions/setup-python@v4" + with: + python-version: "${{ matrix.python-version }}" + - name: "Install dependencies" + run: | + python -m pip install --upgrade vcrpy-unittest + python -m pip install --upgrade virtualenv tox tox-gh-actions + - name: "Run tox targets for ${{ matrix.python-version }}" + run: | + python -m tox + - uses: codecov/codecov-action@v3 + deploy: + runs-on: ubuntu-latest + needs: + - pre-commit + - tests + if: startsWith(github.ref, 'refs/tags') + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + - name: Build a binary wheel and a source tarball + run: pipx run build + - name: Publish distribution 📦 to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + password: ${{ secrets.PYPI_API_TOKEN }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e514ff8..cc4ed4e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,6 +14,6 @@ default_language_version: python: python3 repos: - repo: https://github.com/psf/black - rev: 19.10b0 + rev: 22.3.0 hooks: - id: black diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 6861ac8..0000000 --- a/.travis.yml +++ /dev/null @@ -1,40 +0,0 @@ -language: python -cache: - directories: - - $HOME/.cache/pip - - $HOME/.cache/pre-commit -python: -- "3.6" -install: - - pip install -r requirements.txt - - pip install -r requirements-test.txt -stages: - - name: linting - - name: test - - name: deploy - if: tag IS present - -jobs: - include: - - stage: linting - name: "pre-commit" - python: 3.6 - install: pip install pre-commit - script: pre-commit run --all --show-diff-on-failure - - stage: test - python: 3.6 - script: pytest -s roulier/carriers - - stage: deploy - install: - script: echo "Deploy to PyPi" - deploy: - provider: pypi - user: hparfr - password: - secure: go1MWqMNj5t21FWbZWlSvZsMYiAAJkgO8aeQRMCIv5ZQN8LGCE3nUQxjx1REY768lD9uMD6QgrXchxWWoWk+4B95cEjVOfi+CcINwOT9i3tvQoixwWhK/d4kgUmYggjCR1yOgGR75wc5CrAE5wghg36vnLAxJxxXR1mP5/L2Cz/0qSLUp7MEEal7j+Yo8Hx2o6/lBBHSjKXQugK5FlmOvyfJHHTARU4puSQdyBc/GfgKE6Uxt5vihD3lvj8n/HmXLG1nInEd0DKbIZvFc759ZAk3njKxuL1FWycdaSoGc3XVa5b3qFZa5+7LNrFOjldBm0O21MaHGDHgVE8DLs45i/PgC3L3ATSQ7eDx/1ArPazrZCSdn+umJtkxS2Id/KHLF1yDHguXmUtYwDjW4NmUSLAiVInz5Il/bnADFwXnOQ4WLdmU0GMHkWPLd+TJe4iPTj+SagVpUMVxtQXm2RgFhGSo5h8daK5/ZQnu8DEMX4dtdSKGrMF7FJkbBWFzXIMw8mGbIKKoSjw+nYIl72lNgaPorR3l9s6aR/bwHFaxF0sviSwebvNEecLKIP2TZEIU45u6CQEU5iKptCLzznWemA9mvzw/JDiUlehqm5M0cLgYiJf74QJJbrj6eTC1IK9oAo8iCfn3511u19SqPpnV2ovEenPHly1Gni0i/Gv8JQ0= - distributions: "sdist bdist_wheel" - skip_upload_docs: true - on: - repo: akretion/roulier - branch: master - tags: true diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..e632063 --- /dev/null +++ b/tox.ini @@ -0,0 +1,16 @@ +[gh-actions] +python = + 3.10: py310 + 3.11: py311 + +[tox] +envlist = py310, py311 + +[testenv] +deps = + coverage + pytest + vcrpy-unittest +commands = + coverage run --source roulier -m pytest . -v + coverage xml From 4d11d2d647f02c9d81848c7807ad681fe6c59a02 Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Wed, 19 Jul 2023 16:59:23 +0200 Subject: [PATCH 3/3] Remove test on legacy glsbox webservice It causes issues in CI and as it is legacy, it should not be used anymore, a new gls webservice is available and the switch is easy --- .../glsbox/tests/test_roulier_gls_fr.py | 86 +++++++++---------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/roulier/carriers/gls_fr/glsbox/tests/test_roulier_gls_fr.py b/roulier/carriers/gls_fr/glsbox/tests/test_roulier_gls_fr.py index 7909f90..332e53d 100644 --- a/roulier/carriers/gls_fr/glsbox/tests/test_roulier_gls_fr.py +++ b/roulier/carriers/gls_fr/glsbox/tests/test_roulier_gls_fr.py @@ -17,46 +17,46 @@ ) -def test_connexion(): - roulier.get( - "gls_fr_glsbox", - "get_label", - { - "auth": {"login": credentials["login"], "isTest": credentials["isTest"]}, - "service": { - "agencyId": credentials["agencyId"], - "customerId": credentials["customerId"], - "shippingDate": date.today(), - "shippingId": "125874", - "intructions": "Sent from automatic test", - "parcel_total_number": 1, - }, - "from_address": { - "company": "my company", - "name": "my name", - "street1": "blablabla street", - "zip": "69000", - "city": "Lyon", - "phone": "04 99 99 99 99", - "email": "contact@mycompany.fr", - }, - "to_address": { - "company": "my customer", - "name": "Martine MARTIN", - "street1": "13 avenue des champs Elysées", - "zip": "75001", - "city": "Paris", - "phone": "01 99 99 99 99", - "email": "contact@mycustomer.fr", - "country": "FR", - }, - "parcels": [ - { - "weight": 3.4, - "parcel_number_label": 1, - "parcel_number_barcode": 1, - "custom_sequence": "1234567899", - } - ], - }, - ) +# def test_connexion(): +# roulier.get( +# "gls_fr_glsbox", +# "get_label", +# { +# "auth": {"login": credentials["login"], "isTest": credentials["isTest"]}, +# "service": { +# "agencyId": credentials["agencyId"], +# "customerId": credentials["customerId"], +# "shippingDate": date.today(), +# "shippingId": "125874", +# "intructions": "Sent from automatic test", +# "parcel_total_number": 1, +# }, +# "from_address": { +# "company": "my company", +# "name": "my name", +# "street1": "blablabla street", +# "zip": "69000", +# "city": "Lyon", +# "phone": "04 99 99 99 99", +# "email": "contact@mycompany.fr", +# }, +# "to_address": { +# "company": "my customer", +# "name": "Martine MARTIN", +# "street1": "13 avenue des champs Elysées", +# "zip": "75001", +# "city": "Paris", +# "phone": "01 99 99 99 99", +# "email": "contact@mycustomer.fr", +# "country": "FR", +# }, +# "parcels": [ +# { +# "weight": 3.4, +# "parcel_number_label": 1, +# "parcel_number_barcode": 1, +# "custom_sequence": "1234567899", +# } +# ], +# }, +# )