Skip to content

Commit

Permalink
rename dpd_fr to dpd_fr_soap to conform to akretion#140
Browse files Browse the repository at this point in the history
  • Loading branch information
DylannCordel committed Feb 22, 2021
1 parent 86cd9da commit 71bcf46
Show file tree
Hide file tree
Showing 16 changed files with 34 additions and 31 deletions.
2 changes: 1 addition & 1 deletion roulier/carriers/__init__.py
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
"""Implementation of Dpd Api."""

from roulier.api import ApiParcel
from roulier.api import MyValidator

Expand Down
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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)
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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,
)
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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)


Expand All @@ -80,25 +80,25 @@ 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)
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)
Expand All @@ -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)


Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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_"],
)

Expand Down

0 comments on commit 71bcf46

Please sign in to comment.