From b17c6c4843e607438d2c58418329be525fa43da8 Mon Sep 17 00:00:00 2001 From: UTKARSH KUMAR Date: Fri, 25 Jun 2021 23:07:09 +0530 Subject: [PATCH 1/8] pytest config file added Signed-off-by: UTKARSH KUMAR --- pytest.ini | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 pytest.ini diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 000000000..6dd1c4e5b --- /dev/null +++ b/pytest.ini @@ -0,0 +1,3 @@ +[pytest] +markers = + dontusefix: Dont use fixture in the current file \ No newline at end of file From d33783e7ba262caa8ecd5d8c70858084e5bd2766 Mon Sep 17 00:00:00 2001 From: UTKARSH KUMAR Date: Fri, 25 Jun 2021 23:08:21 +0530 Subject: [PATCH 2/8] added support for unicode literals Signed-off-by: UTKARSH KUMAR --- wsaa.py | 1 + 1 file changed, 1 insertion(+) diff --git a/wsaa.py b/wsaa.py index 707e6dea0..fdb38095f 100644 --- a/wsaa.py +++ b/wsaa.py @@ -13,6 +13,7 @@ "Módulo para obtener un ticket de autorización del web service WSAA de AFIP" from __future__ import print_function from __future__ import absolute_import +from __future__ import unicode_literals # Basado en wsaa-client.php de Gerardo Fisanotti - DvSHyS/DiOPIN/AFIP - 13-apr-07 # Definir WSDL, CERT, PRIVATEKEY, PASSPHRASE, SERVICE, WSAAURL From 5554a444859551ed3cc544f84d85a8b38f807ede Mon Sep 17 00:00:00 2001 From: UTKARSH KUMAR Date: Fri, 25 Jun 2021 23:09:17 +0530 Subject: [PATCH 3/8] fixed issues with cacert reading Signed-off-by: UTKARSH KUMAR --- wsfexv1.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wsfexv1.py b/wsfexv1.py index 64eaa9eaf..91f0b12eb 100644 --- a/wsfexv1.py +++ b/wsfexv1.py @@ -834,8 +834,8 @@ def p_assert_eq(a, b): else: wsdl = "https://wswhomo.afip.gov.ar/wsfexv1/service.asmx?WSDL" cache = proxy = "" - wrapper = "httplib2" - cacert = open("conf/afip_ca_info.crt").read() + wrapper = "" + cacert = "conf/afip_ca_info.crt" ok = wsfexv1.Conectar(cache, wsdl, proxy, wrapper, cacert) if "--dummy" in sys.argv: From de05b9fbbf9d7de130c24b4137843b490250f8ff Mon Sep 17 00:00:00 2001 From: UTKARSH KUMAR Date: Fri, 25 Jun 2021 23:10:57 +0530 Subject: [PATCH 4/8] fixed issues with date format(which was causing error on different py versions) Signed-off-by: UTKARSH KUMAR --- wsmtx.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/wsmtx.py b/wsmtx.py index ec090b34c..c32d1a539 100644 --- a/wsmtx.py +++ b/wsmtx.py @@ -1156,7 +1156,7 @@ def ConsultarComprobante(self, tipo_cbte, punto_vta, cbte_nro, reproceso=False): "numeroDocumento": f["nro_doc"], "numeroComprobante": f["cbt_desde"], "numeroComprobante": f["cbt_hasta"], - "fechaEmision": f["fecha_cbte"], + "fechaEmision": f["fecha_cbte"].isoformat(), "importeTotal": decimal.Decimal(str(f["imp_total"])), "importeNoGravado": decimal.Decimal(str(f["imp_tot_conc"])), "importeGravado": decimal.Decimal(str(f["imp_neto"])), @@ -1165,9 +1165,9 @@ def ConsultarComprobante(self, tipo_cbte, punto_vta, cbte_nro, reproceso=False): and decimal.Decimal(str(f["imp_trib"])) or None, "importeSubtotal": f["imp_subtotal"], - "fechaServicioDesde": f.get("fecha_serv_desde"), - "fechaServicioHasta": f.get("fecha_serv_hasta"), - "fechaVencimientoPago": f.get("fecha_venc_pago"), + "fechaServicioDesde": f.get("fecha_serv_desde").isoformat(), + "fechaServicioHasta": f.get("fecha_serv_hasta").isoformat(), + "fechaVencimientoPago": f.get("fecha_venc_pago").isoformat(), "codigoMoneda": f["moneda_id"], "cotizacionMoneda": str(decimal.Decimal(str(f["moneda_ctz"]))), "arrayItems": [ From 706ae6586f938cf8d69633c21f6b1ba727b007a3 Mon Sep 17 00:00:00 2001 From: UTKARSH KUMAR Date: Fri, 25 Jun 2021 23:12:21 +0530 Subject: [PATCH 5/8] evince not working properly with os, used subprocess instead Signed-off-by: UTKARSH KUMAR --- wslsp.py | 4 ++-- wsltv.py | 4 ++-- wslum.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/wslsp.py b/wslsp.py index 0a94df97e..fe5df550a 100644 --- a/wslsp.py +++ b/wslsp.py @@ -69,7 +69,7 @@ Ver wslsp.ini para parámetros de configuración (URL, certificados, etc.)" """ -import os, sys, shelve +import os, sys, shelve, subprocess import decimal, datetime import traceback import pprint @@ -1033,7 +1033,7 @@ def ConsultarPuntosVentas(self, sep="||"): def MostrarPDF(self, archivo, imprimir=False): try: if sys.platform == "linux2": - os.system("evince " "%s" "" % archivo) + subprocess.call(["evince", archivo]) else: operation = imprimir and "print" or "" os.startfile(archivo, operation) diff --git a/wsltv.py b/wsltv.py index 90b116035..313a12e97 100644 --- a/wsltv.py +++ b/wsltv.py @@ -75,7 +75,7 @@ Ver wsltv.ini para parámetros de configuración (URL, certificados, etc.)" """ -import os, sys, shelve +import os, sys, shelve, subprocess import decimal, datetime import traceback import pprint @@ -844,7 +844,7 @@ def ConsultarPuntosVentas(self, sep="||"): def MostrarPDF(self, archivo, imprimir=False): try: if sys.platform == "linux2": - os.system("evince " "%s" "" % archivo) + subprocess.call(["evince", archivo]) else: operation = imprimir and "print" or "" os.startfile(archivo, operation) diff --git a/wslum.py b/wslum.py index df08821cb..188bcdbb1 100644 --- a/wslum.py +++ b/wslum.py @@ -72,7 +72,7 @@ Ver wslum.ini para parámetros de configuración (URL, certificados, etc.)" """ -import os, sys, shelve +import os, sys, shelve, subprocess import decimal, datetime import traceback import pprint @@ -779,7 +779,7 @@ def ConsultarPuntosVentas(self, sep="||"): def MostrarPDF(self, archivo, imprimir=False): try: if sys.platform == "linux2": - os.system("evince " "%s" "" % archivo) + subprocess.call(["evince", archivo]) else: operation = imprimir and "print" or "" os.startfile(archivo, operation) From acbad74a909f21cec3cf7325264a13565c7f41b3 Mon Sep 17 00:00:00 2001 From: UTKARSH KUMAR Date: Fri, 25 Jun 2021 23:14:23 +0530 Subject: [PATCH 6/8] fixed issues with str(which was causing errors on different py versions) Signed-off-by: UTKARSH KUMAR --- tests/test_wsaa.py | 10 +++++++--- tests/test_wsbfev1.py | 13 +++++++++---- tests/test_wsfev1.py | 12 +++++++++--- tests/test_wsfexv1.py | 17 +++++++++++++---- tests/test_wslsp.py | 2 +- tests/test_wsltv.py | 2 +- tests/test_wslum.py | 14 +++++++++----- tests/test_wsmtx.py | 2 +- 8 files changed, 50 insertions(+), 22 deletions(-) diff --git a/tests/test_wsaa.py b/tests/test_wsaa.py index f2ce8d1a1..76eb716de 100644 --- a/tests/test_wsaa.py +++ b/tests/test_wsaa.py @@ -52,7 +52,7 @@ def test_crear_clave_privada(): chk = wsaa.CrearClavePrivada() assert chk==True -@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires python3.7 or higher") + def test_crear_pedido_certificado(): """Crea CSM para solicitar certificado.""" wsaa=WSAA() @@ -78,7 +78,7 @@ def test_expirado(): assert chk2==True assert chk3==False -@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires python3.7 or higher") + @pytest.mark.vcr def test_login_cms(key_and_cert): """comprobando si LoginCMS está funcionando correctamente""" @@ -91,7 +91,11 @@ def test_login_cms(key_and_cert): ta = SimpleXMLElement(ta_xml) - assert isinstance(cms,str) + if sys.version_info[0] == 3: + assert isinstance(cms,str) + elif sys.version_info[0] == 2: + assert isinstance(cms.decode('utf-8'),str) + assert cms.startswith('MIIG+') assert chk==True diff --git a/tests/test_wsbfev1.py b/tests/test_wsbfev1.py index 7f450f412..c78c49749 100644 --- a/tests/test_wsbfev1.py +++ b/tests/test_wsbfev1.py @@ -16,14 +16,14 @@ __copyright__ = "Copyright (C) 2010-2019 Mariano Reingart" __license__ = "GPL 3.0" -import unittest import os import sys from datetime import datetime, timedelta import pytest from pyafipws.wsaa import WSAA from pyafipws.wsbfev1 import WSBFEv1 -from pysimplesoap.simplexml import SimpleXMLElement +from pysimplesoap.simplexml import SimpleXMLElement +import future __WSDL__ = "http://wswhomo.afip.gov.ar/WSBFEv1/service.asmx" __obj__ = WSBFEv1() @@ -146,7 +146,7 @@ def test_agregar_opcional(auth): opcional = wsbfev1.AgregarOpcional(idz, ds) assert opcional==True -@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires python3.7 or higher") + def test_autorizar(auth): """Test Autorizar Comprobante.""" wsbfev1 =auth @@ -158,7 +158,12 @@ def test_autorizar(auth): wsbfev1.Authorize(idx) assert (wsbfev1.Resultado== "A") - assert isinstance(wsbfev1.CAE,str) + + if sys.version_info[0] == 3: + assert isinstance(wsbfev1.CAE,str) + elif sys.version_info[0] == 2: + assert isinstance((wsbfev1.CAE),future.types.newstr) + assert (wsbfev1.CAE) # ten = datetime.now() + timedelta(days=10) # assert (wsbfev1.Vencimiento == ten.strftime("%d/%m/%Y")) diff --git a/tests/test_wsfev1.py b/tests/test_wsfev1.py index 97b226200..69bfbb949 100644 --- a/tests/test_wsfev1.py +++ b/tests/test_wsfev1.py @@ -23,6 +23,7 @@ import sys import pytest import os +import future __WSDL__ = "https://wswhomo.afip.gov.ar/wsfev1/service.asmx" __obj__ = WSFEv1() @@ -48,7 +49,7 @@ def test_dummy(auth): assert (wsfev1.DbServerStatus== "OK") assert (wsfev1.AuthServerStatus== "OK") -@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires python3.7 or higher") + def test_autorizar_comprobante(auth, tipo_cbte=1, cbte_nro=None, servicios=True): "Prueba de autorización de un comprobante (obtención de CAE)" wsfev1 = auth @@ -131,14 +132,19 @@ def test_autorizar_comprobante(auth, tipo_cbte=1, cbte_nro=None, servicios=True) wsfev1.CAESolicitar() assert (wsfev1.Resultado== "A") # Aprobado! - assert isinstance(wsfev1.CAE, str) + + if sys.version_info[0] == 3: + assert isinstance(wsfev1.CAE,str) + elif sys.version_info[0] == 2: + assert isinstance((wsfev1.CAE),future.types.newstr) + assert (len(wsfev1.CAE)==len("63363178822329")) assert (len(wsfev1.Vencimiento)==len("20130907")) wsfev1.AnalizarXml("XmlResponse") # observación "... no se encuentra registrado en los padrones de AFIP.": #assertEqual(wsfev1.ObtenerTagXml("Obs", 0, "Code"), None) -@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires python3.7 or higher") + def test_consulta(auth): "Prueba de obtener los datos de un comprobante autorizado" wsfev1 = auth diff --git a/tests/test_wsfexv1.py b/tests/test_wsfexv1.py index a8c6ca0c4..f88ca029c 100644 --- a/tests/test_wsfexv1.py +++ b/tests/test_wsfexv1.py @@ -19,6 +19,7 @@ import pytest from pyafipws.wsaa import WSAA from pyafipws.wsfexv1 import WSFEXv1 +import future __author__ = "Mariano Reingart " __copyright__ = "Copyright (C) 2010-2019 Mariano Reingart" @@ -151,7 +152,7 @@ def test_agregar_cbte_asoc(auth): ) assert cbteasoc==True -@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires python3.7 or higher") + def test_autorizar(auth): """Test Autorizar Comprobante.""" wsfexv1 = auth @@ -168,7 +169,12 @@ def test_autorizar(auth): wsfexv1.GetCMP(tipo_cbte, punto_vta, cbte_nro) assert (wsfexv1.Resultado == "A") - assert isinstance(wsfexv1.CAE, str) + + if sys.version_info[0] == 3: + assert isinstance(wsfexv1.CAE,str) + elif sys.version_info[0] == 2: + assert isinstance((wsfexv1.CAE),future.types.newstr) + assert (wsfexv1.CAE) #commented because wsfexv1.Vencimiento giving wrong expiration date @@ -212,7 +218,7 @@ def test_recuperar_numero_transaccion(auth): idx = wsfexv1.GetLastID() # TODO: assertEqual(idy, idx) -@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires python3.7 or higher") + def test_parametros(auth): """Test de Parametros.""" wsfexv1 = auth @@ -227,6 +233,9 @@ def test_parametros(auth): assert (wsfexv1.GetParamIncoterms()) assert (wsfexv1.GetParamMonConCotizacion()) #assert (wsfexv1.GetParamPtosVenta()) - assert isinstance(wsfexv1.GetParamCtz("DOL"), str) + if sys.version_info[0] == 3: + assert isinstance(wsfexv1.GetParamCtz("DOL"),str) + elif sys.version_info[0] == 2: + assert isinstance((wsfexv1.GetParamCtz("DOL")),future.types.newstr) diff --git a/tests/test_wslsp.py b/tests/test_wslsp.py index b4ce4fd8e..7abeb6f71 100644 --- a/tests/test_wslsp.py +++ b/tests/test_wslsp.py @@ -440,7 +440,7 @@ def test_consultar_puntos_ventas(auth): consulta = wslsp.ConsultarPuntosVentas() assert consulta -@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires python3.7 or higher") + def test_mostrar_pdf(auth): """Test mostrar pdf.""" wslsp=auth diff --git a/tests/test_wsltv.py b/tests/test_wsltv.py index a4c221bd8..6c7f7aa6c 100644 --- a/tests/test_wsltv.py +++ b/tests/test_wsltv.py @@ -366,7 +366,7 @@ def test_consultar_puntos_ventas(auth): consulta = wsltv.ConsultarPuntosVentas() assert consulta -@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires python3.7 or higher") + def test_mostrar_pdf(auth): """Test mostrar PDF.""" wsltv=auth diff --git a/tests/test_wslum.py b/tests/test_wslum.py index 4499055db..ae9d9ca20 100644 --- a/tests/test_wslum.py +++ b/tests/test_wslum.py @@ -344,11 +344,15 @@ def test_consultar_puntos_ventas(auth): consulta = wslum.ConsultarPuntosVentas() assert consulta -@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires python3.7 or higher") + def test_mostrar_pdf(auth): """Test mostrar pdf.""" wslum=auth - archivo = "nota" - imprimir = False - pdf_ok = wslum.MostrarPDF(archivo, imprimir) - assert pdf_ok is False + pdf = wslum.GetParametro("pdf") + if pdf: + with open("liq.pdf", "wb") as f: + f.write(pdf) + + show = wslum.MostrarPDF(archivo="liq.pdf", imprimir=True) + + assert show is False diff --git a/tests/test_wsmtx.py b/tests/test_wsmtx.py index c57bdebdd..dbc83e38c 100644 --- a/tests/test_wsmtx.py +++ b/tests/test_wsmtx.py @@ -289,7 +289,7 @@ def test_autorizar_comprobante(auth): autorizado = wsmtx.AutorizarComprobante() assert autorizado -@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires python3.7 or higher") + def test_cae_solicitar(auth): """Test de metodo opcional a AutorizarComprobante """ wsmtx = auth From addf48972965b5ebc5166f8a4552c17820c26585 Mon Sep 17 00:00:00 2001 From: UTKARSH KUMAR Date: Sat, 26 Jun 2021 00:10:47 +0530 Subject: [PATCH 7/8] reverting minor change in wsfexv1.py Signed-off-by: UTKARSH KUMAR --- wsfexv1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wsfexv1.py b/wsfexv1.py index 91f0b12eb..7e615e24b 100644 --- a/wsfexv1.py +++ b/wsfexv1.py @@ -834,7 +834,7 @@ def p_assert_eq(a, b): else: wsdl = "https://wswhomo.afip.gov.ar/wsfexv1/service.asmx?WSDL" cache = proxy = "" - wrapper = "" + wrapper = "httplib2" cacert = "conf/afip_ca_info.crt" ok = wsfexv1.Conectar(cache, wsdl, proxy, wrapper, cacert) From 6778dd6bf08e239ac6ecbd05516e907b516e11df Mon Sep 17 00:00:00 2001 From: UTKARSH KUMAR Date: Mon, 28 Jun 2021 05:11:35 +0530 Subject: [PATCH 8/8] version dependent assertion issues fixed Signed-off-by: UTKARSH KUMAR --- tests/test_wsaa.py | 9 +++++---- tests/test_wsbfev1.py | 8 +++----- tests/test_wsfev1.py | 8 ++++---- tests/test_wsfexv1.py | 13 +++++-------- 4 files changed, 17 insertions(+), 21 deletions(-) diff --git a/tests/test_wsaa.py b/tests/test_wsaa.py index 76eb716de..ffa4dd480 100644 --- a/tests/test_wsaa.py +++ b/tests/test_wsaa.py @@ -91,10 +91,11 @@ def test_login_cms(key_and_cert): ta = SimpleXMLElement(ta_xml) - if sys.version_info[0] == 3: - assert isinstance(cms,str) - elif sys.version_info[0] == 2: - assert isinstance(cms.decode('utf-8'),str) + if not isinstance(cms,str): + cms = cms.decode('utf-8') + + assert isinstance(cms,str) + assert cms.startswith('MIIG+') diff --git a/tests/test_wsbfev1.py b/tests/test_wsbfev1.py index c78c49749..335acfc43 100644 --- a/tests/test_wsbfev1.py +++ b/tests/test_wsbfev1.py @@ -23,7 +23,7 @@ from pyafipws.wsaa import WSAA from pyafipws.wsbfev1 import WSBFEv1 from pysimplesoap.simplexml import SimpleXMLElement -import future +from builtins import str __WSDL__ = "http://wswhomo.afip.gov.ar/WSBFEv1/service.asmx" __obj__ = WSBFEv1() @@ -159,10 +159,8 @@ def test_autorizar(auth): assert (wsbfev1.Resultado== "A") - if sys.version_info[0] == 3: - assert isinstance(wsbfev1.CAE,str) - elif sys.version_info[0] == 2: - assert isinstance((wsbfev1.CAE),future.types.newstr) + assert isinstance(wsbfev1.CAE,str) + assert (wsbfev1.CAE) # ten = datetime.now() + timedelta(days=10) diff --git a/tests/test_wsfev1.py b/tests/test_wsfev1.py index 69bfbb949..b0f775f83 100644 --- a/tests/test_wsfev1.py +++ b/tests/test_wsfev1.py @@ -12,6 +12,7 @@ from pyafipws.wsaa import WSAA from pyafipws.wsfev1 import WSFEv1 +from builtins import str "Pruebas para WSFEv1 de AFIP (Factura Electrónica Mercado Interno sin detalle)" @@ -133,10 +134,9 @@ def test_autorizar_comprobante(auth, tipo_cbte=1, cbte_nro=None, servicios=True) assert (wsfev1.Resultado== "A") # Aprobado! - if sys.version_info[0] == 3: - assert isinstance(wsfev1.CAE,str) - elif sys.version_info[0] == 2: - assert isinstance((wsfev1.CAE),future.types.newstr) + + assert isinstance(wsfev1.CAE,str) + assert (len(wsfev1.CAE)==len("63363178822329")) assert (len(wsfev1.Vencimiento)==len("20130907")) diff --git a/tests/test_wsfexv1.py b/tests/test_wsfexv1.py index f88ca029c..d99bd38e0 100644 --- a/tests/test_wsfexv1.py +++ b/tests/test_wsfexv1.py @@ -20,6 +20,7 @@ from pyafipws.wsaa import WSAA from pyafipws.wsfexv1 import WSFEXv1 import future +from builtins import str __author__ = "Mariano Reingart " __copyright__ = "Copyright (C) 2010-2019 Mariano Reingart" @@ -170,10 +171,8 @@ def test_autorizar(auth): assert (wsfexv1.Resultado == "A") - if sys.version_info[0] == 3: - assert isinstance(wsfexv1.CAE,str) - elif sys.version_info[0] == 2: - assert isinstance((wsfexv1.CAE),future.types.newstr) + assert isinstance(wsfexv1.CAE,str) + assert (wsfexv1.CAE) @@ -233,9 +232,7 @@ def test_parametros(auth): assert (wsfexv1.GetParamIncoterms()) assert (wsfexv1.GetParamMonConCotizacion()) #assert (wsfexv1.GetParamPtosVenta()) - if sys.version_info[0] == 3: - assert isinstance(wsfexv1.GetParamCtz("DOL"),str) - elif sys.version_info[0] == 2: - assert isinstance((wsfexv1.GetParamCtz("DOL")),future.types.newstr) + assert isinstance(wsfexv1.GetParamCtz("DOL"),str) +