From 71bcf46f38556a992798a95869eca000cdd2858f Mon Sep 17 00:00:00 2001 From: Dylann Cordel Date: Mon, 22 Feb 2021 12:51:01 +0100 Subject: [PATCH] rename dpd_fr to dpd_fr_soap to conform to #140 --- roulier/carriers/__init__.py | 2 +- .../{dpd_fr => dpd_fr_soap}/__init__.py | 0 .../carriers/{dpd_fr => dpd_fr_soap}/api.py | 1 + .../{dpd_fr => dpd_fr_soap}/carrier_action.py | 8 +++--- .../{dpd_fr => dpd_fr_soap}/decoder.py | 6 ++-- .../{dpd_fr => dpd_fr_soap}/encoder.py | 9 +++--- .../templates/dpd_address.xml | 0 .../templates/dpd_addressInfo.xml | 0 .../dpd_createShipmentWithLabels.xml | 0 .../templates/dpd_header.xml | 0 .../templates/dpd_soap.xml | 0 .../{dpd_fr => dpd_fr_soap}/tests/__init__.py | 0 .../tests/credential_demo.py | 0 .../{dpd_fr => dpd_fr_soap}/tests/data.py | 0 .../{dpd_fr => dpd_fr_soap}/tests/test_dpd.py | 28 +++++++++---------- .../{dpd_fr => dpd_fr_soap}/transport.py | 11 ++++---- 16 files changed, 34 insertions(+), 31 deletions(-) rename roulier/carriers/{dpd_fr => dpd_fr_soap}/__init__.py (100%) rename roulier/carriers/{dpd_fr => dpd_fr_soap}/api.py (99%) rename roulier/carriers/{dpd_fr => dpd_fr_soap}/carrier_action.py (78%) rename roulier/carriers/{dpd_fr => dpd_fr_soap}/decoder.py (98%) rename roulier/carriers/{dpd_fr => dpd_fr_soap}/encoder.py (94%) rename roulier/carriers/{dpd_fr => dpd_fr_soap}/templates/dpd_address.xml (100%) rename roulier/carriers/{dpd_fr => dpd_fr_soap}/templates/dpd_addressInfo.xml (100%) rename roulier/carriers/{dpd_fr => dpd_fr_soap}/templates/dpd_createShipmentWithLabels.xml (100%) rename roulier/carriers/{dpd_fr => dpd_fr_soap}/templates/dpd_header.xml (100%) rename roulier/carriers/{dpd_fr => dpd_fr_soap}/templates/dpd_soap.xml (100%) rename roulier/carriers/{dpd_fr => dpd_fr_soap}/tests/__init__.py (100%) rename roulier/carriers/{dpd_fr => dpd_fr_soap}/tests/credential_demo.py (100%) rename roulier/carriers/{dpd_fr => dpd_fr_soap}/tests/data.py (100%) rename roulier/carriers/{dpd_fr => dpd_fr_soap}/tests/test_dpd.py (86%) rename roulier/carriers/{dpd_fr => dpd_fr_soap}/transport.py (96%) diff --git a/roulier/carriers/__init__.py b/roulier/carriers/__init__.py index 27e9507..3d82fb9 100755 --- a/roulier/carriers/__init__.py +++ b/roulier/carriers/__init__.py @@ -1,6 +1,6 @@ from . import laposte_fr from . import gls_fr from . import chronopost_fr -from . import dpd_fr +from . import dpd_fr_soap # from . import geodis diff --git a/roulier/carriers/dpd_fr/__init__.py b/roulier/carriers/dpd_fr_soap/__init__.py similarity index 100% rename from roulier/carriers/dpd_fr/__init__.py rename to roulier/carriers/dpd_fr_soap/__init__.py diff --git a/roulier/carriers/dpd_fr/api.py b/roulier/carriers/dpd_fr_soap/api.py similarity index 99% rename from roulier/carriers/dpd_fr/api.py rename to roulier/carriers/dpd_fr_soap/api.py index e0f429b..9c87b4a 100644 --- a/roulier/carriers/dpd_fr/api.py +++ b/roulier/carriers/dpd_fr_soap/api.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- """Implementation of Dpd Api.""" + from roulier.api import ApiParcel from roulier.api import MyValidator diff --git a/roulier/carriers/dpd_fr/carrier_action.py b/roulier/carriers/dpd_fr_soap/carrier_action.py similarity index 78% rename from roulier/carriers/dpd_fr/carrier_action.py rename to roulier/carriers/dpd_fr_soap/carrier_action.py index 1f26039..4abf43c 100755 --- a/roulier/carriers/dpd_fr/carrier_action.py +++ b/roulier/carriers/dpd_fr_soap/carrier_action.py @@ -1,12 +1,12 @@ -# -*- coding: utf-8 -*- """Implementation for Dpd.""" +from roulier.roulier import factory +from roulier.carrier_action import CarrierGetLabel + from .api import DpdApi from .decoder import DpdDecoder from .encoder import DpdEncoder from .transport import DpdTransport -from ...roulier import factory -from ...carrier_action import CarrierGetLabel class DpdGetabel(CarrierGetLabel): @@ -25,4 +25,4 @@ class DpdGetabel(CarrierGetLabel): manage_multi_label = False -factory.register_builder("dpd_fr", "get_label", DpdGetabel) +factory.register_builder("dpd_fr_soap", "get_label", DpdGetabel) diff --git a/roulier/carriers/dpd_fr/decoder.py b/roulier/carriers/dpd_fr_soap/decoder.py similarity index 98% rename from roulier/carriers/dpd_fr/decoder.py rename to roulier/carriers/dpd_fr_soap/decoder.py index 8b5ab4d..13b93d0 100755 --- a/roulier/carriers/dpd_fr/decoder.py +++ b/roulier/carriers/dpd_fr_soap/decoder.py @@ -1,9 +1,9 @@ -# -*- coding: utf-8 -*- """Dpd XML -> Python.""" +import base64 from lxml import objectify -from roulier.codec import DecoderGetLabel + from roulier import ws_tools as tools -import base64 +from roulier.codec import DecoderGetLabel class DpdDecoder(DecoderGetLabel): diff --git a/roulier/carriers/dpd_fr/encoder.py b/roulier/carriers/dpd_fr_soap/encoder.py similarity index 94% rename from roulier/carriers/dpd_fr/encoder.py rename to roulier/carriers/dpd_fr_soap/encoder.py index 76076f8..e980c75 100755 --- a/roulier/carriers/dpd_fr/encoder.py +++ b/roulier/carriers/dpd_fr_soap/encoder.py @@ -1,12 +1,13 @@ """Transform input to dpd compatible xml.""" + +from datetime import datetime + from jinja2 import Environment, PackageLoader + from roulier.codec import Encoder -from datetime import datetime from roulier.exception import InvalidApiInput -import logging DPD_ACTIONS = "createShipmentWithLabels" -log = logging.getLogger(__name__) class DpdEncoder(Encoder): @@ -46,7 +47,7 @@ def reduce_address(address): data["service"]["labelFormat"] = "Default" env = Environment( - loader=PackageLoader("roulier", "/carriers/dpd_fr/templates"), + loader=PackageLoader("roulier", "/carriers/dpd_fr_soap/templates"), extensions=["jinja2.ext.with_", "jinja2.ext.autoescape"], autoescape=True, ) diff --git a/roulier/carriers/dpd_fr/templates/dpd_address.xml b/roulier/carriers/dpd_fr_soap/templates/dpd_address.xml similarity index 100% rename from roulier/carriers/dpd_fr/templates/dpd_address.xml rename to roulier/carriers/dpd_fr_soap/templates/dpd_address.xml diff --git a/roulier/carriers/dpd_fr/templates/dpd_addressInfo.xml b/roulier/carriers/dpd_fr_soap/templates/dpd_addressInfo.xml similarity index 100% rename from roulier/carriers/dpd_fr/templates/dpd_addressInfo.xml rename to roulier/carriers/dpd_fr_soap/templates/dpd_addressInfo.xml diff --git a/roulier/carriers/dpd_fr/templates/dpd_createShipmentWithLabels.xml b/roulier/carriers/dpd_fr_soap/templates/dpd_createShipmentWithLabels.xml similarity index 100% rename from roulier/carriers/dpd_fr/templates/dpd_createShipmentWithLabels.xml rename to roulier/carriers/dpd_fr_soap/templates/dpd_createShipmentWithLabels.xml diff --git a/roulier/carriers/dpd_fr/templates/dpd_header.xml b/roulier/carriers/dpd_fr_soap/templates/dpd_header.xml similarity index 100% rename from roulier/carriers/dpd_fr/templates/dpd_header.xml rename to roulier/carriers/dpd_fr_soap/templates/dpd_header.xml diff --git a/roulier/carriers/dpd_fr/templates/dpd_soap.xml b/roulier/carriers/dpd_fr_soap/templates/dpd_soap.xml similarity index 100% rename from roulier/carriers/dpd_fr/templates/dpd_soap.xml rename to roulier/carriers/dpd_fr_soap/templates/dpd_soap.xml diff --git a/roulier/carriers/dpd_fr/tests/__init__.py b/roulier/carriers/dpd_fr_soap/tests/__init__.py similarity index 100% rename from roulier/carriers/dpd_fr/tests/__init__.py rename to roulier/carriers/dpd_fr_soap/tests/__init__.py diff --git a/roulier/carriers/dpd_fr/tests/credential_demo.py b/roulier/carriers/dpd_fr_soap/tests/credential_demo.py similarity index 100% rename from roulier/carriers/dpd_fr/tests/credential_demo.py rename to roulier/carriers/dpd_fr_soap/tests/credential_demo.py diff --git a/roulier/carriers/dpd_fr/tests/data.py b/roulier/carriers/dpd_fr_soap/tests/data.py similarity index 100% rename from roulier/carriers/dpd_fr/tests/data.py rename to roulier/carriers/dpd_fr_soap/tests/data.py diff --git a/roulier/carriers/dpd_fr/tests/test_dpd.py b/roulier/carriers/dpd_fr_soap/tests/test_dpd.py similarity index 86% rename from roulier/carriers/dpd_fr/tests/test_dpd.py rename to roulier/carriers/dpd_fr_soap/tests/test_dpd.py index 2308488..f4b4ea6 100644 --- a/roulier/carriers/dpd_fr/tests/test_dpd.py +++ b/roulier/carriers/dpd_fr_soap/tests/test_dpd.py @@ -30,9 +30,9 @@ def decorator(test): def test_methods(): assert ( - "dpd_fr" in roulier.get_carriers_action_available().keys() + "dpd_fr_soap" in roulier.get_carriers_action_available().keys() ), "DPD carrier unavailable" - assert roulier.get_carriers_action_available()["dpd_fr"] == [ + assert roulier.get_carriers_action_available()["dpd_fr_soap"] == [ "get_label", ], "get_label() method unavailable" @@ -42,35 +42,35 @@ def test_label_basic_checks(): vals["service"]["product"] = "whatisitproduct" with assert_raises(InvalidApiInput, {"service": [{"product": "unallowed"}]}): - roulier.get("dpd_fr", "get_label", vals) + roulier.get("dpd_fr_soap", "get_label", vals) del vals["service"]["product"] vals["parcels"][0].pop("weight") with assert_raises(InvalidApiInput, {"parcels": [{0: [{"weight": "float"}]}]}): - roulier.get("dpd_fr", "get_label", vals) + roulier.get("dpd_fr_soap", "get_label", vals) vals["parcels"][0]["weight"] = DATA["parcels"][0]["weight"] vals["to_address"].pop("country") with assert_raises(InvalidApiInput, {"to_address": [{"country": "empty"}]}): - roulier.get("dpd_fr", "get_label", vals) + roulier.get("dpd_fr_soap", "get_label", vals) # no address del vals["to_address"] with assert_raises(InvalidApiInput, {"to_address": "empty"}): - roulier.get("dpd_fr", "get_label", vals) + roulier.get("dpd_fr_soap", "get_label", vals) @_test_ip_allowed(False) def test_dpd_invalid_ip(): vals = copy.deepcopy(DATA) with assert_raises(CarrierError, [{"id": "IpPermissionDenied"}]): - roulier.get("dpd_fr", "get_label", vals) + roulier.get("dpd_fr_soap", "get_label", vals) @_test_ip_allowed(True) def test_dpd_classic(): vals = copy.deepcopy(DATA) - result = roulier.get("dpd_fr", "get_label", vals) + result = roulier.get("dpd_fr_soap", "get_label", vals) assert_result(vals, result, 1, 1) @@ -80,17 +80,17 @@ def test_common_failed_get_label(): # Weight vals["parcels"][0]["weight"] = 999.99 with assert_raises(CarrierError, [{"id": "InvalidWeight"}]): - roulier.get("dpd_fr", "get_label", vals) + roulier.get("dpd_fr_soap", "get_label", vals) vals["parcels"][0]["weight"] = 0 with assert_raises(CarrierError, [{"id": "InvalidWeight"}]): - roulier.get("dpd_fr", "get_label", vals) + roulier.get("dpd_fr_soap", "get_label", vals) vals["parcels"][0]["weight"] = DATA["parcels"][0]["weight"] # Country vals["to_address"]["country"] = "ZZ" with assert_raises(CarrierError, [{"id": "InvalidCountryPrefix"}]): - roulier.get("dpd_fr", "get_label", vals) + roulier.get("dpd_fr_soap", "get_label", vals) @_test_ip_allowed(True) @@ -98,7 +98,7 @@ def test_auth(): vals = copy.deepcopy(DATA) vals["auth"]["login"] = "test" with assert_raises(CarrierError, [{"id": "PermissionDenied"}]): - roulier.get("dpd_fr", "get_label", vals) + roulier.get("dpd_fr_soap", "get_label", vals) @_test_ip_allowed(True) @@ -108,9 +108,9 @@ def test_relai(): with assert_raises( InvalidApiInput, {"service": [{"pickupLocationId": "mandatory"}]} ): - roulier.get("dpd_fr", "get_label", vals) + roulier.get("dpd_fr_soap", "get_label", vals) vals["service"]["pickupLocationId"] = "P62025" - result = roulier.get("dpd_fr", "get_label", vals) + result = roulier.get("dpd_fr_soap", "get_label", vals) assert_result(vals, result, 1, 1) diff --git a/roulier/carriers/dpd_fr/transport.py b/roulier/carriers/dpd_fr_soap/transport.py similarity index 96% rename from roulier/carriers/dpd_fr/transport.py rename to roulier/carriers/dpd_fr_soap/transport.py index 6ffa9be..cc7b68e 100755 --- a/roulier/carriers/dpd_fr/transport.py +++ b/roulier/carriers/dpd_fr_soap/transport.py @@ -1,11 +1,12 @@ -# -*- coding: utf-8 -*- """Implement dpdWS.""" -import requests -from lxml import objectify, etree + from jinja2 import Environment, PackageLoader +from lxml import objectify, etree +import requests + +from roulier.exception import CarrierError from roulier.transport import RequestsTransport from roulier.ws_tools import remove_empty_tags -from roulier.exception import CarrierError import logging @@ -38,7 +39,7 @@ def send(self, payload): def soap_wrap(self, body, auth): """Wrap body in a soap:Enveloppe.""" env = Environment( - loader=PackageLoader("roulier", "/carriers/dpd_fr/templates"), + loader=PackageLoader("roulier", "/carriers/dpd_fr_soap/templates"), extensions=["jinja2.ext.with_"], )