# 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/laposte_fr/tests/data.py
# DATA = {
#     "auth": {
#         "login": credentials["login"],
#         "password": credentials["password"],
#         "isTest": credentials["isTest"],
#     },
#     "service": {"shippingDate": date.today()},
#     "parcels": [{"weight": 1.2, "instructions": "Fake instructions"}],
#     "to_address": {
#         "name": "Fr",
#         "firstName": "Hpar",
#         "street1": "27 rue Léon CAMET",
#         "city": "Villeurbanne",
#         "country": "FR",
#         "zip": "69100",
#     },
#     "from_address": {
#         "name": "TEST",
#         "firstName": "AUTOMATIC",
#         "street1": "72 rue Cécile Honxa",
#         "city": "Paris",
#         "country": "FR",
#         "zip": "75001",
#     },
# }
# 
# Path: roulier/carriers/laposte_fr/tests/test_laposte_basic.py
# def _do_not_execute_test_on_remote():
#     """Test execution require valid credentials
#     which are not included in commited files.
# 
#     Main tests are only executable in local installation.
#     This method when called allow to escape remote tests
#     """
#     if DATA["auth"]["password"] == "blablabla":
#         return True
#     return False
# 
# Path: roulier/carriers/laposte_fr/tests/test_laposte_basic.py
# def assert_label(result):
#     assert "parcels" in result
#     assert len(result["parcels"]) > 0
#     assert "label" in result["parcels"][0]
#     assert "data" in result["parcels"][0]["label"]
#     return result["parcels"][0]["label"]


import logging
import copy
from roulier import roulier
from roulier.exception import InvalidApiInput, CarrierError
from .data import DATA
from .test_laposte_basic import _do_not_execute_test_on_remote
from .test_laposte_basic import assert_label

logger = logging.getLogger(__name__)


# TODO : UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe2 in position 7143: invalid continuation byte
def test_COM_product():
    """Outre-Mer - Colissimo Domicile - sans signature"""
    if _do_not_execute_test_on_remote():
        return
    vals = copy.deepcopy(DATA)
    vals["service"]["product"] = "COM"
    vals["service"]["transportationAmount"] = 123
    vals["service"]["totalAmount"] = 123
    vals["to_address"]["country"] = "GP"  # Guadeloupe
    vals["to_address"]["zip"] = "97100"  # Basse-Terre
    vals["parcels"][0]["customs"] = {
        "articles": [
            {
                "quantity": "2",
                "weight": 0.5,
                "originCountry": "FR",
                "description": "Printed circuits",
                "hsCode": "853400",
                "value": 1.0,
            }
        ],
        "category": 3,
    }
    vals["parcels"][0]["totalAmount"] = 123  # Frais de transport
    result = roulier.get("laposte_fr", "get_label", vals)

# 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/laposte_fr/tests/data.py
# DATA = {
#     "auth": {
#         "login": credentials["login"],
#         "password": credentials["password"],
#         "isTest": credentials["isTest"],
#     },
#     "service": {"shippingDate": date.today()},
#     "parcels": [{"weight": 1.2, "instructions": "Fake instructions"}],
#     "to_address": {
#         "name": "Fr",
#         "firstName": "Hpar",
#         "street1": "27 rue Léon CAMET",
#         "city": "Villeurbanne",
#         "country": "FR",
#         "zip": "69100",
#     },
#     "from_address": {
#         "name": "TEST",
#         "firstName": "AUTOMATIC",
#         "street1": "72 rue Cécile Honxa",
#         "city": "Paris",
#         "country": "FR",
#         "zip": "75001",
#     },
# }
# 
# Path: roulier/carriers/laposte_fr/tests/test_laposte_basic.py
# def _do_not_execute_test_on_remote():
#     """Test execution require valid credentials
#     which are not included in commited files.
# 
#     Main tests are only executable in local installation.
#     This method when called allow to escape remote tests
#     """
#     if DATA["auth"]["password"] == "blablabla":
#         return True
#     return False
# 
# Path: roulier/carriers/laposte_fr/tests/test_laposte_basic.py
# def assert_label(result):
#     assert "parcels" in result
#     assert len(result["parcels"]) > 0
#     assert "label" in result["parcels"][0]
#     assert "data" in result["parcels"][0]["label"]
#     return result["parcels"][0]["label"]


# Path: roulier/carriers/laposte_fr/tests/test_laposte_outside_europe.py
import logging
import copy
from roulier import roulier
from roulier.exception import InvalidApiInput, CarrierError
from .data import DATA
from .test_laposte_basic import _do_not_execute_test_on_remote
from .test_laposte_basic import assert_label


logger = logging.getLogger(__name__)


# TODO : UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe2 in position 7143: invalid continuation byte
def test_COM_product():
    """Outre-Mer - Colissimo Domicile - sans signature"""
    if _do_not_execute_test_on_remote():
        return
    vals = copy.deepcopy(DATA)
    vals["service"]["product"] = "COM"
    vals["service"]["transportationAmount"] = 123
    vals["service"]["totalAmount"] = 123
    vals["to_address"]["country"] = "GP"  # Guadeloupe
    vals["to_address"]["zip"] = "97100"  # Basse-Terre
    vals["parcels"][0]["customs"] = {
        "articles": [
            {
                "quantity": "2",
                "weight": 0.5,
                "originCountry": "FR",
                "description": "Printed circuits",
                "hsCode": "853400",
                "value": 1.0,
            }
        ],
        "category": 3,
    }
    vals["parcels"][0]["totalAmount"] = 123  # Frais de transport
    result = roulier.get("laposte_fr", "get_label", vals)

    label = assert_label(result)