# Path: ebill_paynet/components/api.py
# class PayNetDWS:
#     """PayNet DWS web services."""
# 
#     def __init__(self, url, test_service):
#         settings = zeep.Settings(xml_huge_tree=True)
#         session = requests.Session()
#         if test_service:
#             session.verify = SSL_TEST_CERTIFICATE
#         else:
#             session.verify = SSL_PROD_CERTIFICATE
#         transport = zeep.transports.Transport(session=session)
#         self.client = zeep.Client(WSDL_DOC, transport=transport, settings=settings)
#         if url:
#             self.service = self.client.create_service(
#                 "{http://www.sap.com/DWS}DWSBinding", url
#             )
#         else:
#             self.service = self.client.service
# 
#     @staticmethod
#     def authorization(userid, password):
#         """Generate Authorization node."""
#         return {"UserName": userid, "Password": password}
# 
#     @staticmethod
#     def handle_fault(fault):
#         msg = ("{}\n" "code: {} -> {}\n" "actor: {}\n" "detail: {}\n").format(
#             fault.message.upper(),
#             fault.code,
#             fault.subcodes,
#             fault.actor,
#             html.tostring(fault.detail),
#         )
#         _logger.info("Paynet DWS fault : {}".format(msg))
#         return msg
# 
# Path: ebill_paynet/tests/common.py
# class CommonCase(SavepointCase, XmlTestMixin):
#     def setUpClass(cls):
#     def compare_xml_line_by_line(content, expected):
# def get_recorder(base_path=None, **kw):


import os
from odoo.tests.common import SingleTransactionCase
from ..components.api import PayNetDWS
from .common import recorder

class TestEbillPaynet(SingleTransactionCase):
    @classmethod
    def setUpClass(cls):
        super().setUpClass()
        cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))

        # Invoice and account should be the same company
        cls.env.user.company_id = cls.env.ref("l10n_ch.demo_company_ch").id

        cls.bank = cls.env.ref("base.res_bank_1")
        cls.bank.clearing = 777
        cls.partner_bank = cls.env["res.partner.bank"].create(
            {
                "bank_id": cls.bank.id,
                "acc_number": "300.300.300",
                "acc_holder_name": "AccountHolderName",
                "partner_id": cls.env.user.partner_id.id,
                "l10n_ch_qr_iban": "CH21 3080 8001 2345 6782 7",
            }
        )

        cls.paynet = cls.env["paynet.service"].create(
            {
                "name": "Paynet Test Service",
                "use_test_service": True,
                "client_pid": os.getenv("PAYNET_ID", "123456789"),
                "service_type": "b2b",
            }
        )

# Path: ebill_paynet/components/api.py
# class PayNetDWS:
#     """PayNet DWS web services."""
# 
#     def __init__(self, url, test_service):
#         settings = zeep.Settings(xml_huge_tree=True)
#         session = requests.Session()
#         if test_service:
#             session.verify = SSL_TEST_CERTIFICATE
#         else:
#             session.verify = SSL_PROD_CERTIFICATE
#         transport = zeep.transports.Transport(session=session)
#         self.client = zeep.Client(WSDL_DOC, transport=transport, settings=settings)
#         if url:
#             self.service = self.client.create_service(
#                 "{http://www.sap.com/DWS}DWSBinding", url
#             )
#         else:
#             self.service = self.client.service
# 
#     @staticmethod
#     def authorization(userid, password):
#         """Generate Authorization node."""
#         return {"UserName": userid, "Password": password}
# 
#     @staticmethod
#     def handle_fault(fault):
#         msg = ("{}\n" "code: {} -> {}\n" "actor: {}\n" "detail: {}\n").format(
#             fault.message.upper(),
#             fault.code,
#             fault.subcodes,
#             fault.actor,
#             html.tostring(fault.detail),
#         )
#         _logger.info("Paynet DWS fault : {}".format(msg))
#         return msg
# 
# Path: ebill_paynet/tests/common.py
# class CommonCase(SavepointCase, XmlTestMixin):
#     def setUpClass(cls):
#     def compare_xml_line_by_line(content, expected):
# def get_recorder(base_path=None, **kw):


# Path: ebill_paynet/tests/test_ebill_paynet.py
import os
from odoo.tests.common import SingleTransactionCase
from ..components.api import PayNetDWS
from .common import recorder


class TestEbillPaynet(SingleTransactionCase):
    @classmethod
    def setUpClass(cls):
        super().setUpClass()
        cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))

        # Invoice and account should be the same company
        cls.env.user.company_id = cls.env.ref("l10n_ch.demo_company_ch").id

        cls.bank = cls.env.ref("base.res_bank_1")
        cls.bank.clearing = 777
        cls.partner_bank = cls.env["res.partner.bank"].create(
            {
                "bank_id": cls.bank.id,
                "acc_number": "300.300.300",
                "acc_holder_name": "AccountHolderName",
                "partner_id": cls.env.user.partner_id.id,
                "l10n_ch_qr_iban": "CH21 3080 8001 2345 6782 7",
            }
        )

        cls.paynet = cls.env["paynet.service"].create(
            {
                "name": "Paynet Test Service",
                "use_test_service": True,
                "client_pid": os.getenv("PAYNET_ID", "123456789"),
                "service_type": "b2b",
            }
        )

        cls.dws = PayNetDWS(cls.paynet.url, True)