Skip to content

Commit 1d15ed0

Browse files
Merge pull request reingart#59 from PyAr/gsoc
Bring back GSoC 2019 tests
2 parents 4cf0046 + 292f4ed commit 1d15ed0

18 files changed

Lines changed: 3201 additions & 4 deletions

tests/conftest.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/python
2+
# -*- coding: utf8 -*-
3+
# This program is free software; you can redistribute it and/or modify
4+
# it under the terms of the GNU General Public License as published by the
5+
# Free Software Foundation; either version 3, or (at your option) any later
6+
# version.
7+
#
8+
# This program is distributed in the hope that it will be useful, but
9+
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY
10+
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11+
# for more details.
12+
13+
import os
14+
15+
__author__ = "Mariano Reingart <reingart@gmail.com>"
16+
__copyright__ = "Copyright (C) 2021- Mariano Reingart"
17+
__license__ = "GPL 3.0"
18+
19+
20+
WSDL = "https://wswhomo.afip.gov.ar/wsfev1/service.asmx?WSDL"
21+
CUIT = 20267565393
22+
CERT = "/home/reingart/pyafipws/reingart.crt"
23+
PRIVATEKEY = "/home/reingart/pyafipws/reingart.key"
24+
CACERT = "/home/reingart/pyafipws/afip_root_desa_ca.crt"
25+
CACHE = "/home/reingart/pyafipws/cache"
26+
27+
os.environ["CUIT"] = str(CUIT)

tests/test_ws_sr_padron.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/usr/bin/python
2+
# -*- coding: utf8 -*-
3+
# This program is free software; you can redistribute it and/or modify
4+
# it under the terms of the GNU General Public License as published by the
5+
# Free Software Foundation; either version 3, or (at your option) any later
6+
# version.
7+
#
8+
# This program is distributed in the hope that it will be useful, but
9+
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY
10+
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11+
# for more details.
12+
13+
"""Test para Módulo WS_SR_PADRON
14+
(Módulo para acceder a los datos de un contribuyente registrado en el Padrón
15+
de AFIP).
16+
"""
17+
18+
__author__ = "Mariano Reingart <reingart@gmail.com>"
19+
__copyright__ = "Copyright (C) 2010-2019 Mariano Reingart"
20+
__license__ = "GPL 3.0"
21+
22+
import os
23+
import pytest
24+
25+
from pyafipws.wsaa import WSAA
26+
from pyafipws.ws_sr_padron import WSSrPadronA4, WSSrPadronA5
27+
28+
29+
WSDL = "https://awshomo.afip.gov.ar/sr-padron/webservices/personaServiceA5?wsdl"
30+
CUIT = os.environ["CUIT"]
31+
CERT = "reingart.crt"
32+
PKEY = "reingart.key"
33+
CACHE = ""
34+
35+
# obteniendo el TA para pruebas
36+
wsaa = WSAA()
37+
wspa5 = WSSrPadronA5()
38+
39+
ta = wsaa.Autenticar("ws_sr_padron_a5", CERT, PKEY)
40+
# ta = wsaa.Autenticar("ws_sr_padron_a4", CERT, PKEY)
41+
wspa5.Cuit = CUIT
42+
wspa5.SetTicketAcceso(ta)
43+
wspa5.Conectar(CACHE, WSDL)
44+
45+
46+
@pytest.mark.skip
47+
def test_server_status():
48+
"""Test de estado de servidores."""
49+
# Estados de servidores respuesta no funciona afip
50+
wspa5.Dummy()
51+
assert wspa5.AppServerStatus == "OK"
52+
assert wspa5.DbServerStatus == "OK"
53+
assert wspa5.AuthServerStatus == "OK"
54+
55+
56+
def test_inicializar():
57+
"""Test inicializar variables de BaseWS."""
58+
wspa5.inicializar()
59+
assert wspa5.tipo_doc == 0
60+
assert wspa5.denominacion == ""
61+
assert wspa5.actividades == []
62+
63+
64+
@pytest.mark.skip
65+
def test_consultar():
66+
"""Test consultar."""
67+
# Consulta Nivel A4 afip no esta funcionando.
68+
id_persona = "20002307554"
69+
consulta = wspa4.Consultar(id_persona)
70+
assert consulta
71+
72+
73+
def test_consultar_a5():
74+
"""Test consultar padron nivel A5."""
75+
id_persona = "20201797064"
76+
consulta = wspa5.Consultar(id_persona)
77+
assert consulta
78+
assert wspa5.direccion == "LARREA 1"
79+
assert wspa5.provincia == "CIUDAD AUTONOMA BUENOS AIRES"
80+
assert wspa5.cod_postal == "1030"
81+
82+
# metodo analizar datos
83+
assert wspa5.imp_iva == "N"
84+
assert wspa5.cat_iva == 5

tests/test_wsaa.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/usr/bin/python
2+
# -*- coding: utf8 -*-
3+
# This program is free software; you can redistribute it and/or modify
4+
# it under the terms of the GNU General Public License as published by the
5+
# Free Software Foundation; either version 3, or (at your option) any later
6+
# version.
7+
#
8+
# This program is distributed in the hope that it will be useful, but
9+
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY
10+
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11+
# for more details.
12+
13+
"""Test para WSAA"""
14+
15+
__author__ = "Mariano Reingart <reingart@gmail.com>"
16+
__copyright__ = "Copyright (C) 2010-2019 Mariano Reingart"
17+
__license__ = "GPL 3.0"
18+
19+
import os
20+
21+
from pyafipws.wsaa import WSAA
22+
from pyafipws import wsaa as at
23+
24+
import cryptography as crypt
25+
26+
CERT = "reingart.crt"
27+
PKEY = "reingart.key"
28+
29+
wsaa = WSAA()
30+
# Generar ticket de accseso
31+
ta = wsaa.Autenticar("wsfe", CERT, PKEY)
32+
tra = at.create_tra()
33+
sign = at.sign_tra(tra, CERT, PKEY)
34+
35+
# Se remueven test por tema de 10 minutos Afip
36+
37+
38+
def test_create_tra():
39+
""" xml para autorizacion inicial"""
40+
assert isinstance(tra, bytes)
41+
42+
43+
# Si esta instalado m2crypto o cryptography.
44+
if crypt:
45+
46+
def test_sign_tra_cript():
47+
"""Firmar tra con las credenciales."""
48+
assert sign.startswith("MIIG+")
49+
50+
def test_analizar_certificado():
51+
"""Test analizar datos en certificado."""
52+
wsaa.AnalizarCertificado(CERT)
53+
assert wsaa.Identidad
54+
assert wsaa.Caducidad
55+
assert wsaa.Emisor
56+
57+
def test_crear_clave_privada():
58+
"""Test crear clave RSA."""
59+
pkey = wsaa.CrearClavePrivada()
60+
assert pkey
61+
62+
def test_crear_pedido_certificado():
63+
"""Crea CSM para solicitar certificado."""
64+
csm = wsaa.CrearPedidoCertificado()
65+
assert csm
66+
67+
68+
else:
69+
# con OpenSSL directo
70+
def test_sign_tra_openssl():
71+
"""Firmar tra con las credenciales."""
72+
assert sign.startswith("MIIG+")
73+
74+
75+
def test_expirado():
76+
"""Revisar si el TA se encuentra vencido."""
77+
exp = wsaa.Expirado()
78+
assert exp or True
79+
80+
81+
def test_autenticar():
82+
"""Genera TA o devuelve el ya autorizado"""
83+
assert ta

0 commit comments

Comments
 (0)