diff --git a/test/services/test_netbox.py b/test/services/test_netbox.py index da5980d8327e38492c6b77a76093b27154a0b6e9..97c26df7404f0cdf17089571382b4bf8014ba093 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)]]