From 572f99e2417ff2a41c797fa3777594512426fa2e Mon Sep 17 00:00:00 2001
From: Karel van Klink <karel.vanklink@geant.org>
Date: Fri, 11 Oct 2024 14:54:21 +0200
Subject: [PATCH] =?UTF-8?q?Add=20unit=20test=20for=20G=C3=89ANT=20IP=20mig?=
 =?UTF-8?q?ration?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../module/workflows/geant_ip/index.rst       |  3 +-
 .../workflows/geant_ip/migrate_geant_ip.rst   |  6 +++
 .../geant_ip/test_migrate_geant_ip.py         | 46 +++++++++++++++++++
 3 files changed, 54 insertions(+), 1 deletion(-)
 create mode 100644 docs/source/module/workflows/geant_ip/migrate_geant_ip.rst
 create mode 100644 test/workflows/geant_ip/test_migrate_geant_ip.py

diff --git a/docs/source/module/workflows/geant_ip/index.rst b/docs/source/module/workflows/geant_ip/index.rst
index bf8b1a3b..c2dd7576 100644
--- a/docs/source/module/workflows/geant_ip/index.rst
+++ b/docs/source/module/workflows/geant_ip/index.rst
@@ -13,6 +13,7 @@ Submodules
    :titlesonly:
 
    create_geant_ip
-   modify_geant_ip
    create_imported_geant_ip
    import_geant_ip
+   migrate_geant_ip
+   modify_geant_ip
diff --git a/docs/source/module/workflows/geant_ip/migrate_geant_ip.rst b/docs/source/module/workflows/geant_ip/migrate_geant_ip.rst
new file mode 100644
index 00000000..fccea906
--- /dev/null
+++ b/docs/source/module/workflows/geant_ip/migrate_geant_ip.rst
@@ -0,0 +1,6 @@
+``gso.workflows.geant_ip.migrate_geant_ip``
+===========================================
+
+.. automodule:: gso.workflows.geant_ip.migrate_geant_ip
+   :members:
+   :show-inheritance:
diff --git a/test/workflows/geant_ip/test_migrate_geant_ip.py b/test/workflows/geant_ip/test_migrate_geant_ip.py
new file mode 100644
index 00000000..304fc75b
--- /dev/null
+++ b/test/workflows/geant_ip/test_migrate_geant_ip.py
@@ -0,0 +1,46 @@
+import pytest
+
+from gso.products.product_types.geant_ip import GeantIP
+from test.workflows import assert_complete, extract_state, run_workflow
+
+
+@pytest.mark.workflow()
+def test_migrate_geant_ip_success(
+    faker, edge_port_subscription_factory, partner_factory, geant_ip_subscription_factory
+):
+    partner = partner_factory()
+    subscription_id = geant_ip_subscription_factory(partner=partner)
+    new_edge_port_1 = edge_port_subscription_factory(partner=partner)
+    new_edge_port_2 = edge_port_subscription_factory(partner=partner)
+    subscription = GeantIP.from_subscription(subscription_id)
+
+    form_input_data = [
+        {"subscription_id": subscription_id},
+        {
+            "tt_number": faker.tt_number(),
+            "edge_port_selection": [
+                {
+                    "old_edge_port": subscription.geant_ip.geant_ip_ap_list[0].geant_ip_sbp.edge_port.description,
+                    "new_edge_port": new_edge_port_1,
+                },
+                {
+                    "old_edge_port": subscription.geant_ip.geant_ip_ap_list[1].geant_ip_sbp.edge_port.description,
+                    "new_edge_port": new_edge_port_2,
+                },
+            ],
+        },
+    ]
+
+    result, _, _ = run_workflow("migrate_geant_ip", form_input_data)
+
+    assert_complete(result)
+    state = extract_state(result)
+    subscription = GeantIP.from_subscription(state["subscription_id"])
+    assert subscription.insync
+    assert len(subscription.geant_ip.geant_ip_ap_list) == 2
+    assert (
+        str(subscription.geant_ip.geant_ip_ap_list[0].geant_ip_sbp.edge_port.owner_subscription_id) == new_edge_port_1
+    )
+    assert (
+        str(subscription.geant_ip.geant_ip_ap_list[1].geant_ip_sbp.edge_port.owner_subscription_id) == new_edge_port_2
+    )
-- 
GitLab