127 lines
4.9 KiB
Python
127 lines
4.9 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
# This file is part of facho. The COPYRIGHT file at the top level of
|
|
# this repository contains the full copyright notices and license terms.
|
|
# from datetime import datetime
|
|
|
|
import pytest
|
|
from facho.fe import form_xml
|
|
from datetime import datetime
|
|
import helpers
|
|
from fixtures import simple_invoice
|
|
|
|
simple_invoice = simple_invoice
|
|
|
|
def test_xml_with_required_elements(simple_invoice):
|
|
|
|
DIANInvoiceXML = form_xml.DIANInvoiceXML(
|
|
simple_invoice)
|
|
|
|
doc = form_xml.AttachedDocument(
|
|
simple_invoice,
|
|
DIANInvoiceXML,
|
|
id='123')
|
|
|
|
xml = doc.toFachoXML()
|
|
|
|
DIANInvoiceXML = form_xml.DIANInvoiceXML(
|
|
simple_invoice, 'Invoice').attach_invoice
|
|
|
|
attached_document = (
|
|
'<?xml version="1.0" encoding="UTF-8" standalone="no"?>'
|
|
) + DIANInvoiceXML.tostring()
|
|
|
|
assert xml.get_element_text(
|
|
'/atd:AttachedDocument/cbc:UBLVersionID') == 'UBL 2.1'
|
|
assert xml.get_element_text(
|
|
'/atd:AttachedDocument/cbc:CustomizationID') == 'Documentos adjuntos'
|
|
assert xml.get_element_text(
|
|
'/atd:AttachedDocument/cbc:ProfileID') == 'Factura Electrónica de Venta'
|
|
assert xml.get_element_text(
|
|
'/atd:AttachedDocument/cbc:ProfileExecutionID') == '1'
|
|
assert xml.get_element_text(
|
|
'/atd:AttachedDocument/cbc:ID') == '123'
|
|
assert xml.get_element_text(
|
|
'/atd:AttachedDocument/cbc:IssueDate') == str(datetime.today().date())
|
|
assert xml.get_element_text(
|
|
'/atd:AttachedDocument/cbc:IssueTime') == datetime.today(
|
|
).time().strftime(
|
|
'%H:%M:%S-05:00')
|
|
assert xml.get_element_text(
|
|
'/atd:AttachedDocument/cbc:DocumentType'
|
|
) == 'Contenedor de Factura Electrónica'
|
|
assert xml.get_element_text(
|
|
'/atd:AttachedDocument/cbc:ParentDocumentID'
|
|
) == 'ABC123'
|
|
|
|
assert xml.get_element_text(
|
|
'/atd:AttachedDocument/cac:SenderParty/cac:PartyTaxScheme/cbc:RegistrationName'
|
|
) == 'facho-supplier'
|
|
assert xml.get_element_text(
|
|
'/atd:AttachedDocument/cac:SenderParty/cac:PartyTaxScheme/cbc:CompanyID'
|
|
) == '123'
|
|
assert xml.get_element_text(
|
|
'/atd:AttachedDocument/cac:SenderParty/cac:PartyTaxScheme/cbc:TaxLevelCode'
|
|
) == 'ZZ'
|
|
assert xml.get_element_text(
|
|
'/atd:AttachedDocument/cac:SenderParty/cac:PartyTaxScheme/cac:TaxScheme/cbc:ID'
|
|
) == '01'
|
|
assert xml.get_element_text(
|
|
'/atd:AttachedDocument/cac:SenderParty/cac:PartyTaxScheme/cac:TaxScheme/cbc:Name'
|
|
) == 'IVA'
|
|
|
|
assert xml.get_element_text(
|
|
'/atd:AttachedDocument/cac:ReceiverParty/cac:PartyTaxScheme/cbc:RegistrationName'
|
|
) == 'facho-customer'
|
|
assert xml.get_element_text(
|
|
'/atd:AttachedDocument/cac:ReceiverParty/cac:PartyTaxScheme/cbc:CompanyID'
|
|
) == '321'
|
|
assert xml.get_element_text(
|
|
'/atd:AttachedDocument/cac:ReceiverParty/cac:PartyTaxScheme/cbc:TaxLevelCode'
|
|
) == 'ZZ'
|
|
assert xml.get_element_text(
|
|
'/atd:AttachedDocument/cac:ReceiverParty/cac:PartyTaxScheme/cac:TaxScheme/cbc:ID'
|
|
) == '01'
|
|
assert xml.get_element_text(
|
|
'/atd:AttachedDocument/cac:ReceiverParty/cac:PartyTaxScheme/cac:TaxScheme/cbc:Name'
|
|
) == 'IVA'
|
|
|
|
assert xml.get_element_text(
|
|
'/atd:AttachedDocument/cac:Attachment/cac:ExternalReference/cbc:MimeCode'
|
|
) == "text/xml"
|
|
assert xml.get_element_text(
|
|
'/atd:AttachedDocument/cac:Attachment/cac:ExternalReference/cbc:EncodingCode'
|
|
) == "UTF-8"
|
|
assert xml.get_element_text(
|
|
'/atd:AttachedDocument/cac:Attachment/cac:ExternalReference/cbc:Description'
|
|
) == "<![CDATA[{}]]>".format(attached_document)
|
|
|
|
assert xml.get_element_text(
|
|
'/atd:AttachedDocument/cac:ParentDocumentLineReference/cbc:LineID'
|
|
) == '1'
|
|
assert xml.get_element_text(
|
|
'/atd:AttachedDocument/cac:ParentDocumentLineReference/cac:DocumentReference/cbc:ID'
|
|
) == '1234'
|
|
assert xml.get_element_text(
|
|
'/atd:AttachedDocument/cac:ParentDocumentLineReference/cac:DocumentReference/cbc:UUID'
|
|
) == '1234'
|
|
assert xml.get_element_text(
|
|
'/atd:AttachedDocument/cac:ParentDocumentLineReference/cac:DocumentReference/cbc:IssueDate'
|
|
) == '2024-11-28'
|
|
assert xml.get_element_text(
|
|
'/atd:AttachedDocument/cac:ParentDocumentLineReference/cac:DocumentReference/cbc:DocumentType'
|
|
) == 'ApplicationResponse'
|
|
assert xml.get_element_text(
|
|
'/atd:AttachedDocument/cac:ParentDocumentLineReference/cac:DocumentReference/cac:Attachment/cac:ExternalReference/cbc:MimeCode'
|
|
) == 'text/xml'
|
|
|
|
assert xml.get_element_text(
|
|
'/atd:AttachedDocument/cac:ParentDocumentLineReference/cac:DocumentReference/cac:Attachment/cac:ExternalReference/cbc:EncodingCode'
|
|
) == "UTF-8"
|
|
assert xml.get_element_text(
|
|
'/atd:AttachedDocument/cac:ParentDocumentLineReference/cac:DocumentReference/cac:Attachment/cac:ExternalReference/cbc:Description'
|
|
) == " "
|
|
|
|
with open("output.xml", "w") as fh:
|
|
fh.write(xml.tostring())
|