diff --git a/test/services/test_netbox.py b/test/services/test_netbox.py index eab8edace6b1c12f51e7921acda70a15bcd6a7dd..8c5c05e0e15f233a96feaeae951d949313bf500c 100644 --- a/test/services/test_netbox.py +++ b/test/services/test_netbox.py @@ -1,7 +1,10 @@ """ Unit tests for testing the netbox client """ +import uuid from os import PathLike +from unittest.mock import patch, Mock + import responses from gso.services.netbox_client import NetBoxClient @@ -60,3 +63,26 @@ def test_get_all_interfaces(data_config_filename: PathLike): assert result is not None assert len(result) == num_iface + + +@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)]]