# 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",
#     },
# }
# 
# PACKING_SLIP_DATA = {
#     "auth": {
#         "login": credentials["login"],
#         "password": credentials["password"],
#         "isTest": credentials["isTest"],
#     },
# }


import logging
import copy
import base64
import requests
import shutil
import pytest
from roulier import roulier
from roulier.exception import InvalidApiInput, CarrierError
from .data import DATA, PACKING_SLIP_DATA



logger = logging.getLogger(__name__)

DOWNLOAD_PDF_FILE = False  # Update to get demo files

EXCEPTION_MESSAGE = "Failed call with parameters %s"


def test_methods():
    assert (
        "laposte_fr" in roulier.get_carriers_action_available().keys()
    ), "Laposte carrier unavailable"
    assert roulier.get_carriers_action_available()["laposte_fr"] == [
        "get_label",
        "get_packing_slip",
    ], "get_label() or get_packing_slip() methods unavailable"


def test_label_basic_checks():
    if _do_not_execute_test_on_remote():
        return
    with pytest.raises(InvalidApiInput, match="empty values not allowed"):
        roulier.get("laposte_fr", "get_label", DATA)
    vals = copy.deepcopy(DATA)

    vals["service"]["product"] = "whatisitproduct"

# 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",
#     },
# }
# 
# PACKING_SLIP_DATA = {
#     "auth": {
#         "login": credentials["login"],
#         "password": credentials["password"],
#         "isTest": credentials["isTest"],
#     },
# }


# Path: roulier/carriers/laposte_fr/tests/test_laposte_basic.py
import logging
import copy
import base64
import requests
import shutil
import pytest
from roulier import roulier
from roulier.exception import InvalidApiInput, CarrierError
from .data import DATA, PACKING_SLIP_DATA




logger = logging.getLogger(__name__)

DOWNLOAD_PDF_FILE = False  # Update to get demo files

EXCEPTION_MESSAGE = "Failed call with parameters %s"


def test_methods():
    assert (
        "laposte_fr" in roulier.get_carriers_action_available().keys()
    ), "Laposte carrier unavailable"
    assert roulier.get_carriers_action_available()["laposte_fr"] == [
        "get_label",
        "get_packing_slip",
    ], "get_label() or get_packing_slip() methods unavailable"


def test_label_basic_checks():
    if _do_not_execute_test_on_remote():
        return
    with pytest.raises(InvalidApiInput, match="empty values not allowed"):
        roulier.get("laposte_fr", "get_label", DATA)
    vals = copy.deepcopy(DATA)

    vals["service"]["product"] = "whatisitproduct"

    with pytest.raises(CarrierError, match="'id': 30109"):