From 54198aff119ccfd422183a8af6b50c9bd2cbdf96 Mon Sep 17 00:00:00 2001
From: Neda Moeini <neda.moeini@GA0479-NMOEINI.local>
Date: Thu, 12 Oct 2023 12:48:48 +0200
Subject: [PATCH] Added sample test.

---
 test/services/test_netbox.py | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/test/services/test_netbox.py b/test/services/test_netbox.py
index da5980d8..97c26df7 100644
--- a/test/services/test_netbox.py
+++ b/test/services/test_netbox.py
@@ -3,6 +3,7 @@ Unit tests for testing the netbox client
 """
 import os
 import json
+import uuid
 from os import PathLike
 from unittest.mock import patch
 
@@ -65,3 +66,26 @@ def test_create_device(data_config_filename: PathLike):
 
     result = NetBoxClient().create_device(device_name, site_tier)
     assert result is not None
+
+
+@patch("gso.services.netbox_client.Router.from_subscription")
+@patch("gso.services.netbox_client.pynetbox.api")
+def test_get_available_lags(mock_api, mock_from_subscription, data_config_filename: PathLike):
+    router_id = uuid.uuid4()
+    feasible_lags = [f"LAG-{i}" for i in range(1, 10)]
+
+    # Mock the pynetbox API instance
+    mock_netbox = mock_api.return_value
+    mock_filter = mock_netbox.dcim.interfaces.filter
+    mock_filter.return_value = [{"name": f"LAG-{i}", "type": "lag"} for i in range(1, 4)]
+
+    # Mock the Router.from_subscription method
+    mock_subscription = mock_from_subscription.return_value
+    mock_router = mock_subscription.router
+    mock_router.router_fqdn = "test_router"
+
+    netbox_client = NetBoxClient()
+    result = netbox_client.get_available_lags(router_id)
+
+    # Check the result of the function
+    assert result == [lag for lag in feasible_lags if lag not in [f"LAG-{i}" for i in range(1, 4)]]
-- 
GitLab