From 3fa06cb1ef6d044cf85d2a413aca05ec78fdd598 Mon Sep 17 00:00:00 2001 From: Mauricio Baeza Date: Fri, 11 Dec 2020 22:16:37 -0600 Subject: [PATCH] =?UTF-8?q?Agregar=20test=20de=20cancelaci=C3=B3n=20con=20?= =?UTF-8?q?XML=20firmado?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/tests/tests_comercio.py | 43 ++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/source/tests/tests_comercio.py b/source/tests/tests_comercio.py index 74ff0e9..83b5fb0 100644 --- a/source/tests/tests_comercio.py +++ b/source/tests/tests_comercio.py @@ -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()