test/helpers.py (mock_urlopen): se simula valor de policy para xades
FossilOrigin-Name: ec150ca9edb5cce8e6d98ffc936addc8cce9493be323c56ee86a6a4bbece86e7
This commit is contained in:
parent
ec8b92e1bc
commit
f6705c77fa
9
tests/helpers.py
Normal file
9
tests/helpers.py
Normal file
@ -0,0 +1,9 @@
|
||||
|
||||
def mock_urlopen(m):
|
||||
import urllib.request
|
||||
def mock(url):
|
||||
class FakeIO:
|
||||
def read(*args):
|
||||
return "X".encode('utf-8')
|
||||
return FakeIO()
|
||||
m.setattr(urllib.request, "urlopen", mock)
|
@ -7,7 +7,10 @@ import pytest
|
||||
from facho import fe
|
||||
|
||||
|
||||
def test_xmlsigned_build():
|
||||
import helpers
|
||||
|
||||
|
||||
def test_xmlsigned_build(monkeypatch):
|
||||
#openssl req -x509 -sha256 -nodes -subj "/CN=test" -days 1 -newkey rsa:2048 -keyout example.key -out example.pem
|
||||
#openssl pkcs12 -export -out example.p12 -inkey example.key -in example.pem
|
||||
signer = fe.DianXMLExtensionSigner('./tests/example.p12')
|
||||
@ -15,14 +18,17 @@ def test_xmlsigned_build():
|
||||
xml = fe.FeXML('Invoice',
|
||||
'http://www.dian.gov.co/contratos/facturaelectronica/v1')
|
||||
xml.add_extension(signer)
|
||||
xml.attach_extensions()
|
||||
|
||||
with monkeypatch.context() as m:
|
||||
helpers.mock_urlopen(m)
|
||||
xml.attach_extensions()
|
||||
elem = xml.find_or_create_element('/fe:Invoice/ext:UBLExtensions/ext:UBLExtension/ext:ExtensionContent/ds:Signature')
|
||||
|
||||
assert elem is not None
|
||||
#assert elem.findall('ds:SignedInfo', fe.NAMESPACES) is not None
|
||||
|
||||
|
||||
def test_xmlsigned_with_passphrase_build():
|
||||
def test_xmlsigned_with_passphrase_build(monkeypatch):
|
||||
#openssl req -x509 -sha256 -nodes -subj "/CN=test" -days 1 -newkey rsa:2048 -keyout example.key -out example.pem
|
||||
#openssl pkcs12 -export -out example.p12 -inkey example.key -in example.pem
|
||||
signer = fe.DianXMLExtensionSigner('./tests/example-with-passphrase.p12', 'test')
|
||||
@ -30,7 +36,10 @@ def test_xmlsigned_with_passphrase_build():
|
||||
xml = fe.FeXML('Invoice',
|
||||
'http://www.dian.gov.co/contratos/facturaelectronica/v1')
|
||||
xml.add_extension(signer)
|
||||
xml.attach_extensions()
|
||||
|
||||
with monkeypatch.context() as m:
|
||||
helpers.mock_urlopen(m)
|
||||
xml.attach_extensions()
|
||||
elem = xml.find_or_create_element('/fe:Invoice/ext:UBLExtensions/ext:UBLExtension/ext:ExtensionContent/ds:Signature')
|
||||
|
||||
assert elem is not None
|
||||
|
@ -79,7 +79,7 @@ def test_invoicesimple_build_with_cufe(simple_invoice):
|
||||
assert cufe != ''
|
||||
|
||||
|
||||
def test_invoicesimple_xml_signed(simple_invoice):
|
||||
def test_invoicesimple_xml_signed(monkeypatch, simple_invoice):
|
||||
invoice_validator = form.DianResolucion0001Validator()
|
||||
simple_invoice.validate(invoice_validator)
|
||||
assert invoice_validator.valid() == True
|
||||
@ -88,7 +88,10 @@ def test_invoicesimple_xml_signed(simple_invoice):
|
||||
signer = fe.DianXMLExtensionSigner('./tests/example.p12')
|
||||
xml.add_extension(signer)
|
||||
|
||||
xml.attach_extensions()
|
||||
with monkeypatch.context() as m:
|
||||
import helpers
|
||||
helpers.mock_urlopen(m)
|
||||
xml.attach_extensions()
|
||||
|
||||
elem = xml.find_or_create_element('/fe:Invoice/ext:UBLExtensions/ext:UBLExtension/ext:ExtensionContent/ds:Signature')
|
||||
assert elem.text is not None
|
||||
|
Loading…
Reference in New Issue
Block a user