From 171ad52506e0531761563a3555539a8194c6ec61 Mon Sep 17 00:00:00 2001 From: HanslettTheDev Date: Mon, 11 Sep 2023 23:19:24 +0100 Subject: [PATCH 1/2] feat: adding unit tests for wsfev1 based on issue #107 Signed-off-by: HanslettTheDev --- tests/test_wsfev1.py | 55 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/tests/test_wsfev1.py b/tests/test_wsfev1.py index cfe67ed27..c8dc4332f 100644 --- a/tests/test_wsfev1.py +++ b/tests/test_wsfev1.py @@ -10,6 +10,7 @@ # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. +from unittest.mock import Mock from pyafipws.wsaa import WSAA from pyafipws.wsfev1 import WSFEv1, main from builtins import str @@ -40,6 +41,35 @@ pytestmark =[pytest.mark.vcr, pytest.mark.freeze_time('2021-07-01')] +@pytest.fixture +def mock_client(): + mock = Mock() + + mock_response = { + "FEParamGetActividadesResult": { + "ResultGet": [ + { + "ActividadesTipo": { + "Id": 1, + "Orden": 10, + "Desc": "Activity 1", + } + }, + { + "ActividadesTipo": { + "Id": 2, + "Orden": 20, + "Desc": "Activity 2", + } + }, + ] + } + } + + mock.FEParamGetActividades.return_value = mock_response + + return mock + def test_dummy(auth): wsfev1 = auth wsfev1.Dummy() @@ -222,6 +252,31 @@ def test_reproceso_nota_debito(auth): test_autorizar_comprobante(auth, tipo_cbte, cbte_nro, servicios=False) assert (wsfev1.Reproceso == "S") +def test_agregar_actividad(): + """Test Agrego actividad a una factura (interna)""" + wsfev1 = WSFEv1() + wsfev1.CrearFactura() + wsfev1.AgregarActividad(960990) + assert wsfev1.factura["actividades"][0]["actividad_id"] == 960990 + + +def test_param_get_actividades(mock_client): + """Test the response values from activity code from the web service""" + wsfev1 = WSFEv1() + wsfev1.Cuit = "sdfsdf" + wsfev1.client = mock_client + + # call the ParamGetActividades where the client + # will be instantiated by the mock + items = wsfev1.ParamGetActividades() + + expected_result = [ + "1|10|Activity 1", + "2|20|Activity 2", + ] + + # Check the methods return the expected result + assert items == expected_result def test_main(auth): sys.argv = [] From 3a62832684e8af64360d823f596490c8302bbb4a Mon Sep 17 00:00:00 2001 From: HanslettTheDev Date: Sat, 28 Oct 2023 06:26:33 +0100 Subject: [PATCH 2/2] ref: refactored the function name, removed pytest.fixture Signed-off-by: HanslettTheDev --- tests/test_wsfev1.py | 65 ++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/tests/test_wsfev1.py b/tests/test_wsfev1.py index c8dc4332f..877eb1a62 100644 --- a/tests/test_wsfev1.py +++ b/tests/test_wsfev1.py @@ -40,36 +40,6 @@ pytestmark =[pytest.mark.vcr, pytest.mark.freeze_time('2021-07-01')] - -@pytest.fixture -def mock_client(): - mock = Mock() - - mock_response = { - "FEParamGetActividadesResult": { - "ResultGet": [ - { - "ActividadesTipo": { - "Id": 1, - "Orden": 10, - "Desc": "Activity 1", - } - }, - { - "ActividadesTipo": { - "Id": 2, - "Orden": 20, - "Desc": "Activity 2", - } - }, - ] - } - } - - mock.FEParamGetActividades.return_value = mock_response - - return mock - def test_dummy(auth): wsfev1 = auth wsfev1.Dummy() @@ -260,12 +230,41 @@ def test_agregar_actividad(): assert wsfev1.factura["actividades"][0]["actividad_id"] == 960990 -def test_param_get_actividades(mock_client): +def test_param_get_actividades(): """Test the response values from activity code from the web service""" + def simulate_wsfev1_client(): + mock = Mock() + + mock_response = { + "FEParamGetActividadesResult": { + "ResultGet": [ + { + "ActividadesTipo": { + "Id": 1, + "Orden": 10, + "Desc": "Activity 1", + } + }, + { + "ActividadesTipo": { + "Id": 2, + "Orden": 20, + "Desc": "Activity 2", + } + }, + ] + } + } + + mock.FEParamGetActividades.return_value = mock_response + + return mock + + wsfev1 = WSFEv1() wsfev1.Cuit = "sdfsdf" - wsfev1.client = mock_client - + wsfev1.client = simulate_wsfev1_client() + # call the ParamGetActividades where the client # will be instantiated by the mock items = wsfev1.ParamGetActividades()