test/helpers.py (mock_urlopen): se simula valor de policy para xades
FossilOrigin-Name: ec150ca9edb5cce8e6d98ffc936addc8cce9493be323c56ee86a6a4bbece86e7
This commit is contained in:
		
							
								
								
									
										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 | 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 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 |     #openssl pkcs12 -export -out example.p12 -inkey example.key -in example.pem | ||||||
|     signer = fe.DianXMLExtensionSigner('./tests/example.p12') |     signer = fe.DianXMLExtensionSigner('./tests/example.p12') | ||||||
| @@ -15,6 +18,9 @@ def test_xmlsigned_build(): | |||||||
|     xml = fe.FeXML('Invoice', |     xml = fe.FeXML('Invoice', | ||||||
|                    'http://www.dian.gov.co/contratos/facturaelectronica/v1') |                    'http://www.dian.gov.co/contratos/facturaelectronica/v1') | ||||||
|     xml.add_extension(signer) |     xml.add_extension(signer) | ||||||
|  |  | ||||||
|  |     with monkeypatch.context() as m: | ||||||
|  |         helpers.mock_urlopen(m) | ||||||
|         xml.attach_extensions() |         xml.attach_extensions() | ||||||
|     elem = xml.find_or_create_element('/fe:Invoice/ext:UBLExtensions/ext:UBLExtension/ext:ExtensionContent/ds:Signature') |     elem = xml.find_or_create_element('/fe:Invoice/ext:UBLExtensions/ext:UBLExtension/ext:ExtensionContent/ds:Signature') | ||||||
|      |      | ||||||
| @@ -22,7 +28,7 @@ def test_xmlsigned_build(): | |||||||
|     #assert elem.findall('ds:SignedInfo', fe.NAMESPACES) 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 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 |     #openssl pkcs12 -export -out example.p12 -inkey example.key -in example.pem | ||||||
|     signer = fe.DianXMLExtensionSigner('./tests/example-with-passphrase.p12', 'test') |     signer = fe.DianXMLExtensionSigner('./tests/example-with-passphrase.p12', 'test') | ||||||
| @@ -30,6 +36,9 @@ def test_xmlsigned_with_passphrase_build(): | |||||||
|     xml = fe.FeXML('Invoice', |     xml = fe.FeXML('Invoice', | ||||||
|                    'http://www.dian.gov.co/contratos/facturaelectronica/v1') |                    'http://www.dian.gov.co/contratos/facturaelectronica/v1') | ||||||
|     xml.add_extension(signer) |     xml.add_extension(signer) | ||||||
|  |      | ||||||
|  |     with monkeypatch.context() as m: | ||||||
|  |         helpers.mock_urlopen(m) | ||||||
|         xml.attach_extensions() |         xml.attach_extensions() | ||||||
|     elem = xml.find_or_create_element('/fe:Invoice/ext:UBLExtensions/ext:UBLExtension/ext:ExtensionContent/ds:Signature') |     elem = xml.find_or_create_element('/fe:Invoice/ext:UBLExtensions/ext:UBLExtension/ext:ExtensionContent/ds:Signature') | ||||||
|      |      | ||||||
|   | |||||||
| @@ -79,7 +79,7 @@ def test_invoicesimple_build_with_cufe(simple_invoice): | |||||||
|     assert cufe != '' |     assert cufe != '' | ||||||
|  |  | ||||||
|  |  | ||||||
| def test_invoicesimple_xml_signed(simple_invoice): | def test_invoicesimple_xml_signed(monkeypatch, simple_invoice): | ||||||
|     invoice_validator = form.DianResolucion0001Validator() |     invoice_validator = form.DianResolucion0001Validator() | ||||||
|     simple_invoice.validate(invoice_validator) |     simple_invoice.validate(invoice_validator) | ||||||
|     assert invoice_validator.valid() == True |     assert invoice_validator.valid() == True | ||||||
| @@ -88,6 +88,9 @@ def test_invoicesimple_xml_signed(simple_invoice): | |||||||
|     signer = fe.DianXMLExtensionSigner('./tests/example.p12') |     signer = fe.DianXMLExtensionSigner('./tests/example.p12') | ||||||
|     xml.add_extension(signer) |     xml.add_extension(signer) | ||||||
|  |  | ||||||
|  |     with monkeypatch.context() as m: | ||||||
|  |         import helpers | ||||||
|  |         helpers.mock_urlopen(m) | ||||||
|         xml.attach_extensions() |         xml.attach_extensions() | ||||||
|  |  | ||||||
|     elem = xml.find_or_create_element('/fe:Invoice/ext:UBLExtensions/ext:UBLExtension/ext:ExtensionContent/ds:Signature') |     elem = xml.find_or_create_element('/fe:Invoice/ext:UBLExtensions/ext:UBLExtension/ext:ExtensionContent/ds:Signature') | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user