# Path: roulier/roulier.py
# class RoulierFactory(object):
#     def __init__(self):
#     def register_builder(self, carrier_type, action, Carrierclass):
#     def get(self, carrier_type, action, **kwargs):
# def get(carrier_type, action, *args, **kwargs):
# def get_carriers_action_available():
# 
# Path: roulier/exception.py
# class InvalidApiInput(Exception):
#     """Bad input.
# 
#     Use this class in your application to manage
#     exception with api call
#     """
# 
# class CarrierError(Exception):
#     """Error from WS.
# 
#     Use this class in your application to manage
#     exception with the carrier WS
#     """
# 
#     def __init__(self, response, msg=None):
#         if msg is None:
#             msg = "An error occured with WS"
#         super(CarrierError, self).__init__(msg)
#         self.response = response
#         if self.response:
#             if hasattr(self.response, "text"):
#                 log.debug(response.text)
#             else:
#                 log.debug(response)
# 
# Path: roulier/carriers/dpd_fr_soap/tests/data.py
# DATA = {
#     "auth": {
#         "login": credentials["login"],
#         "password": credentials["password"],
#         "isTest": credentials["isTest"],
#     },
#     "service": {
#         "shippingDate": date.today(),
#         "customerId": credentials["customerId"],
#         "customerCountry": credentials["customerCountry"],
#         "agencyId": credentials["agencyId"],
#         "product": "DPD_Classic",
#         "labelFormat": "PDF",
#     },
#     "parcels": [{"weight": 1.2, "comment": "Fake comment"}],
#     "from_address": {
#         "name": "Fr",
#         "street1": "27 rue Léon CAMET",
#         "city": "Villeurbanne",
#         "country": "FR",
#         "zip": "69100",
#         "phone": "+330123456789",
#     },
#     "to_address": {
#         "name": "Fr",
#         "firstName": "Hpar",
#         "street1": "27 rue Léon CAMET",
#         "city": "Villeurbanne",
#         "country": "FR",
#         "zip": "69100",
#         "email": "test@example.com",
#     },
# }
# 
# MY_IP_IS_ALLOWED = credentials.get("my_IP_is_allowed", False)


import logging
import copy
import re
from roulier import roulier
from roulier.exception import InvalidApiInput, CarrierError
from .data import DATA, MY_IP_IS_ALLOWED
    vals = copy.deepcopy(DATA)
    vals["service"]["labelFormat"] = "invalid"
    with assert_raises(InvalidApiInput, {"service": [{"labelFormat": "unallowed"}]}):
        result = roulier.get("dpd_fr_soap", "get_label", vals)


@_test_ip_allowed(True)
def test_common_failed_get_label():
    vals = copy.deepcopy(DATA)
    # Weight
    vals["parcels"][0]["weight"] = 999.99
    with assert_raises(CarrierError, [{"id": "InvalidWeight"}]):
        roulier.get("dpd_fr_soap", "get_label", vals)

    vals["parcels"][0]["weight"] = 0
    with assert_raises(CarrierError, [{"id": "InvalidWeight"}]):
        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_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"}]):

# Path: roulier/roulier.py
# class RoulierFactory(object):
#     def __init__(self):
#     def register_builder(self, carrier_type, action, Carrierclass):
#     def get(self, carrier_type, action, **kwargs):
# def get(carrier_type, action, *args, **kwargs):
# def get_carriers_action_available():
# 
# Path: roulier/exception.py
# class InvalidApiInput(Exception):
#     """Bad input.
# 
#     Use this class in your application to manage
#     exception with api call
#     """
# 
# class CarrierError(Exception):
#     """Error from WS.
# 
#     Use this class in your application to manage
#     exception with the carrier WS
#     """
# 
#     def __init__(self, response, msg=None):
#         if msg is None:
#             msg = "An error occured with WS"
#         super(CarrierError, self).__init__(msg)
#         self.response = response
#         if self.response:
#             if hasattr(self.response, "text"):
#                 log.debug(response.text)
#             else:
#                 log.debug(response)
# 
# Path: roulier/carriers/dpd_fr_soap/tests/data.py
# DATA = {
#     "auth": {
#         "login": credentials["login"],
#         "password": credentials["password"],
#         "isTest": credentials["isTest"],
#     },
#     "service": {
#         "shippingDate": date.today(),
#         "customerId": credentials["customerId"],
#         "customerCountry": credentials["customerCountry"],
#         "agencyId": credentials["agencyId"],
#         "product": "DPD_Classic",
#         "labelFormat": "PDF",
#     },
#     "parcels": [{"weight": 1.2, "comment": "Fake comment"}],
#     "from_address": {
#         "name": "Fr",
#         "street1": "27 rue Léon CAMET",
#         "city": "Villeurbanne",
#         "country": "FR",
#         "zip": "69100",
#         "phone": "+330123456789",
#     },
#     "to_address": {
#         "name": "Fr",
#         "firstName": "Hpar",
#         "street1": "27 rue Léon CAMET",
#         "city": "Villeurbanne",
#         "country": "FR",
#         "zip": "69100",
#         "email": "test@example.com",
#     },
# }
# 
# MY_IP_IS_ALLOWED = credentials.get("my_IP_is_allowed", False)


# Path: roulier/carriers/dpd_fr_soap/tests/test_dpd.py
import logging
import copy
import re
from roulier import roulier
from roulier.exception import InvalidApiInput, CarrierError
from .data import DATA, MY_IP_IS_ALLOWED

    vals = copy.deepcopy(DATA)
    vals["service"]["labelFormat"] = "invalid"
    with assert_raises(InvalidApiInput, {"service": [{"labelFormat": "unallowed"}]}):
        result = roulier.get("dpd_fr_soap", "get_label", vals)


@_test_ip_allowed(True)
def test_common_failed_get_label():
    vals = copy.deepcopy(DATA)
    # Weight
    vals["parcels"][0]["weight"] = 999.99
    with assert_raises(CarrierError, [{"id": "InvalidWeight"}]):
        roulier.get("dpd_fr_soap", "get_label", vals)

    vals["parcels"][0]["weight"] = 0
    with assert_raises(CarrierError, [{"id": "InvalidWeight"}]):
        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_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_soap", "get_label", vals)