Agregar test de cancelación con XML firmado
This commit is contained in:
parent
ad7593f53d
commit
3fa06cb1ef
|
@ -109,6 +109,12 @@ class TestCfdi(object):
|
|||
xslt.close()
|
||||
return
|
||||
|
||||
def sign_xml(self, template):
|
||||
tree = ET.fromstring(template.encode())
|
||||
tree = self._cert.sign_xml(tree)
|
||||
xml = ET.tostring(tree).decode()
|
||||
return xml
|
||||
|
||||
@property
|
||||
def cert(self):
|
||||
cer = base64.b64encode(self._cer_ori).decode()
|
||||
|
@ -157,6 +163,43 @@ class TestStamp(unittest.TestCase):
|
|||
self.assertEqual(cfdi_uuid, cancel_uuid)
|
||||
self.assertEqual(status, expected)
|
||||
|
||||
def test_cfdi_cancel_xml(self):
|
||||
expected = '201'
|
||||
cfdi = TestCfdi()
|
||||
result = self.pac.stamp(cfdi.xml)
|
||||
cfdi_uuid = self.pac.cfdi_uuid
|
||||
|
||||
self.assertFalse(bool(self.pac.error))
|
||||
self.assertTrue(bool(uuid.UUID(cfdi_uuid)))
|
||||
|
||||
NS_CFDI = {
|
||||
'cfdi': 'http://www.sat.gob.mx/cfd/3',
|
||||
'tdf': 'http://www.sat.gob.mx/TimbreFiscalDigital',
|
||||
}
|
||||
tree = ET.fromstring(result.encode())
|
||||
rfc_emisor = tree.xpath(
|
||||
'string(//cfdi:Comprobante/cfdi:Emisor/@Rfc)',
|
||||
namespaces=NS_CFDI)
|
||||
|
||||
time.sleep(1)
|
||||
data = {
|
||||
'rfc': rfc_emisor,
|
||||
'fecha': datetime.datetime.now().isoformat()[:19],
|
||||
'uuid': cfdi_uuid,
|
||||
}
|
||||
template = TEMPLATE_CANCEL.format(**data)
|
||||
sign_xml = cfdi.sign_xml(template)
|
||||
info = {
|
||||
'tipo': 'cfdi3.3',
|
||||
}
|
||||
result = self.pac.cancel_xml(result, sign_xml, info)
|
||||
tree = ET.fromstring(result)
|
||||
uid = tree.xpath('string(//Acuse/Folios/UUID)')
|
||||
status = tree.xpath('string(//Acuse/Folios/EstatusUUID)')
|
||||
|
||||
self.assertEqual(cfdi_uuid, uid)
|
||||
self.assertEqual(status, expected)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Loading…
Reference in New Issue