111 lines
3.6 KiB
Python
111 lines
3.6 KiB
Python
import pytest
|
|
import os
|
|
import tempfile
|
|
import xml.etree.ElementTree as ET
|
|
|
|
|
|
FACTURA_XML = '''<?xml version="1.0" encoding="utf-8"?>
|
|
<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
|
|
xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
|
|
xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">
|
|
<cbc:ID>F001-00005103</cbc:ID>
|
|
<cbc:InvoiceTypeCode>01</cbc:InvoiceTypeCode>
|
|
<cac:AccountingSupplierParty>
|
|
<cac:Party>
|
|
<cac:PartyIdentification>
|
|
<cbc:ID schemeID="6">20549758054</cbc:ID>
|
|
</cac:PartyIdentification>
|
|
</cac:Party>
|
|
</cac:AccountingSupplierParty>
|
|
<cac:TaxTotal>
|
|
<cac:TaxSubtotal>
|
|
<cac:TaxCategory>
|
|
<cbc:ID>IGV</cbc:ID>
|
|
</cac:TaxCategory>
|
|
</cac:TaxSubtotal>
|
|
</cac:TaxTotal>
|
|
</Invoice>'''
|
|
|
|
CREDIT_NOTE_XML = '''<?xml version="1.0" encoding="utf-8"?>
|
|
<CreditNote xmlns="urn:oasis:names:specification:ubl:schema:xsd:CreditNote-2"
|
|
xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
|
|
xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">
|
|
<cbc:ID>B001-00001234</cbc:ID>
|
|
<cbc:InvoiceTypeCode>07</cbc:InvoiceTypeCode>
|
|
<cac:AccountingSupplierParty>
|
|
<cac:Party>
|
|
<cac:PartyIdentification>
|
|
<cbc:ID schemeID="6">20123456789</cbc:ID>
|
|
</cac:PartyIdentification>
|
|
</cac:Party>
|
|
</cac:AccountingSupplierParty>
|
|
</CreditNote>'''
|
|
|
|
CDR_XML = '''<?xml version="1.0" encoding="utf-8"?>
|
|
<ApplicationResponse xmlns="urn:oasis:names:specification:ubl:schema:xsd:ApplicationResponse-2"
|
|
xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
|
|
xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">
|
|
<cbc:ID>R-2025-00000123</cbc:ID>
|
|
<cac:SenderParty>
|
|
<cac:PartyLegalEntity>
|
|
<cbc:CompanyID schemeID="6">20549758054</cbc:CompanyID>
|
|
</cac:PartyLegalEntity>
|
|
</cac:SenderParty>
|
|
</ApplicationResponse>'''
|
|
|
|
RECIBO_XML = '''<?xml version="1.0" encoding="utf-8"?>
|
|
<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
|
|
xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
|
|
xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">
|
|
<cbc:ID>R001-00000456</cbc:ID>
|
|
<cbc:InvoiceTypeCode>02</cbc:InvoiceTypeCode>
|
|
<cac:AccountingSupplierParty>
|
|
<cbc:CustomerAssignedAccountID>10456789012</cbc:CustomerAssignedAccountID>
|
|
</cac:AccountingSupplierParty>
|
|
<cac:TaxTotal>
|
|
<cac:TaxSubtotal>
|
|
<cac:TaxCategory>
|
|
<cbc:ID>RET 4TA</cbc:ID>
|
|
</cac:TaxCategory>
|
|
</cac:TaxSubtotal>
|
|
</cac:TaxTotal>
|
|
</Invoice>'''
|
|
|
|
|
|
@pytest.fixture
|
|
def temp_dir():
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
yield tmpdir
|
|
|
|
|
|
@pytest.fixture
|
|
def factura_xml_path(temp_dir):
|
|
path = os.path.join(temp_dir, "F001-00005103.xml")
|
|
with open(path, "w", encoding="utf-8") as f:
|
|
f.write(FACTURA_XML)
|
|
return path
|
|
|
|
|
|
@pytest.fixture
|
|
def credito_xml_path(temp_dir):
|
|
path = os.path.join(temp_dir, "B001-00001234.xml")
|
|
with open(path, "w", encoding="utf-8") as f:
|
|
f.write(CREDIT_NOTE_XML)
|
|
return path
|
|
|
|
|
|
@pytest.fixture
|
|
def cdr_xml_path(temp_dir):
|
|
path = os.path.join(temp_dir, "R-2025-00000123.xml")
|
|
with open(path, "w", encoding="utf-8") as f:
|
|
f.write(CDR_XML)
|
|
return path
|
|
|
|
|
|
@pytest.fixture
|
|
def recibo_xml_path(temp_dir):
|
|
path = os.path.join(temp_dir, "R001-00000456.xml")
|
|
with open(path, "w", encoding="utf-8") as f:
|
|
f.write(RECIBO_XML)
|
|
return path
|