From 2ba605ccf7310223a06addceed62d8c2bec35168 Mon Sep 17 00:00:00 2001
From: Karel van Klink <karel.vanklink@geant.org>
Date: Fri, 13 Dec 2024 11:41:42 +0100
Subject: [PATCH] Update unit test for VRF router list modification workflow

---
 gso/workflows/vrf/modify_vrf_router_list.py   |  4 ++--
 .../vrf/test_modify_vrf_router_list.py        | 21 +++++++++++--------
 2 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/gso/workflows/vrf/modify_vrf_router_list.py b/gso/workflows/vrf/modify_vrf_router_list.py
index 17f888d0..efa7e531 100644
--- a/gso/workflows/vrf/modify_vrf_router_list.py
+++ b/gso/workflows/vrf/modify_vrf_router_list.py
@@ -56,7 +56,7 @@ def update_subscription_model(subscription: VRF, router_list: list[dict[str, UUI
 
 @step("[DRY RUN] Update VRF on list of routers")
 def update_vrf_on_routers_dry(
-    subscription: dict[str, Any], process_id: UUIDstr, tt_number: str, router_list
+    subscription: dict[str, Any], process_id: UUIDstr, tt_number: str, router_list: list[dict[str, UUIDstr]]
 ) -> LSOState:
     """Deploy VRF on a list of routers - Dry run."""
     vrf_new_router_list = [Router.from_subscription(router["router_id"]) for router in router_list]
@@ -77,7 +77,7 @@ def update_vrf_on_routers_dry(
 
 @step("[FOR REAL] Update VRF on list of routers")
 def update_vrf_on_routers_real(
-    subscription: dict[str, Any], process_id: UUIDstr, tt_number: str, router_list
+    subscription: dict[str, Any], process_id: UUIDstr, tt_number: str, router_list: list[dict[str, UUIDstr]]
 ) -> LSOState:
     """Deploy VRF on a list of routers - with commit."""
     vrf_new_router_list = [Router.from_subscription(router["router_id"]) for router in router_list]
diff --git a/test/workflows/vrf/test_modify_vrf_router_list.py b/test/workflows/vrf/test_modify_vrf_router_list.py
index 97f04656..7a5bd14f 100644
--- a/test/workflows/vrf/test_modify_vrf_router_list.py
+++ b/test/workflows/vrf/test_modify_vrf_router_list.py
@@ -1,22 +1,28 @@
 import uuid
+from unittest.mock import patch
 
 import pytest
 from pydantic_forms.exceptions import FormValidationError
 
 from gso.products.product_types.vrf import VRF
-from test.workflows import assert_complete, extract_state, run_workflow
+from test.workflows import assert_complete, assert_lso_interaction_success, extract_state, run_workflow
 
 
 @pytest.mark.workflow()
-def test_modify_vrf_router_list(vrf_subscription_factory, router_subscription_factory, faker):
+@patch("gso.services.lso_client._send_request")
+def test_modify_vrf_router_list(mock_lso_call, vrf_subscription_factory, router_subscription_factory, faker):
     subscription_id = vrf_subscription_factory()
     initial_vrf_data = [
         {"subscription_id": subscription_id},
         {
             "router_list": [{"router_id": router_subscription_factory()}, {"router_id": router_subscription_factory()}],
+            "tt_number": faker.tt_number(),
         },
     ]
-    result, _, _ = run_workflow("modify_vrf_router_list", initial_vrf_data)
+    result, process_stat, step_log = run_workflow("modify_vrf_router_list", initial_vrf_data)
+    for _ in range(2):
+        result, step_log = assert_lso_interaction_success(result, process_stat, step_log)
+
     assert_complete(result)
 
     state = extract_state(result)
@@ -24,6 +30,7 @@ def test_modify_vrf_router_list(vrf_subscription_factory, router_subscription_fa
     subscription = VRF.from_subscription(subscription_id)
     assert subscription.status == "active"
     assert len(subscription.vrf.vrf_router_list) == 2
+    assert mock_lso_call.call_count == 2
 
 
 @pytest.mark.workflow()
@@ -31,9 +38,7 @@ def test_modify_vrf_router_list_with_invalid_router_id(vrf_subscription_factory,
     subscription_id = vrf_subscription_factory()
     initial_vrf_data = [
         {"subscription_id": subscription_id},
-        {
-            "router_list": [{"router_id": uuid.uuid4()}],
-        },
+        {"router_list": [{"router_id": uuid.uuid4()}], "tt_number": faker.tt_number()},
     ]
 
     with pytest.raises(FormValidationError, match="Input should be an instance of Select a router"):
@@ -46,9 +51,7 @@ def test_modify_vrf_router_list_with_duplicate_router_id(vrf_subscription_factor
     router_id = router_subscription_factory()
     initial_vrf_data = [
         {"subscription_id": subscription_id},
-        {
-            "router_list": [{"router_id": router_id}, {"router_id": router_id}],
-        },
+        {"router_list": [{"router_id": router_id}, {"router_id": router_id}], "tt_number": faker.tt_number()},
     ]
 
     with pytest.raises(FormValidationError, match="List must be unique"):
-- 
GitLab