diff --git a/source/tests/tests_comercio.py b/source/tests/tests_comercio.py index 831d9ee..f87fac9 100644 --- a/source/tests/tests_comercio.py +++ b/source/tests/tests_comercio.py @@ -1,7 +1,9 @@ #!/usr/bin/env python3 +import base64 import datetime import sys +import time import unittest import uuid import lxml.etree as ET @@ -15,6 +17,7 @@ from comerciodigital import PACComercioDigital NAME = 'comercio' + TEMPLATE_CFDI = """ @@ -50,8 +53,8 @@ class TestCfdi(object): path_cer = Path(path.parent).joinpath('certificados', f'{NAME}.cer') path_key = Path(path.parent).joinpath('certificados', f'{NAME}.enc') path_xslt = Path(path.parent).joinpath('xslt', 'cadena.xslt') - cer = path_cer.read_bytes() - key = path_key.read_bytes() + self._cer_ori = cer = path_cer.read_bytes() + self._key_ori = key = path_key.read_bytes() self._cert = SATCertificate(cer, key) self._doc = ET.parse(BytesIO(TEMPLATE_CFDI.encode())) @@ -75,6 +78,12 @@ class TestCfdi(object): xslt.close() return + @property + def cert(self): + cer = base64.b64encode(self._cer_ori).decode() + key = base64.b64encode(self._key_ori).decode() + return key, cer + class TestStamp(unittest.TestCase): @@ -90,6 +99,27 @@ class TestStamp(unittest.TestCase): self.assertFalse(bool(self.pac.error)) self.assertTrue(bool(uuid.UUID(cfdi_uuid))) + def test_cfdi_cancel(self): + 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))) + + time.sleep(1) + cert = cfdi.cert + info = { + 'key': cert[0], + 'cer': cert[1], + 'pass': '12345678', + 'tipo': 'cfdi3.3', + } + result = self.pac.cancel(result, info) + + self.assertFalse(bool(self.pac.error)) + self.assertTrue(bool(result)) + if __name__ == '__main__': unittest.main()