Skip to content
Snippets Groups Projects
Commit 46d70aa4 authored by Neda Moeini's avatar Neda Moeini
Browse files

Added test for get_available_lags function.

parent 124c74c9
No related branches found
No related tags found
1 merge request!89Feature/nat 286 create unit tests for netbox client
Pipeline #84217 failed
""" """
Unit tests for testing the netbox client Unit tests for testing the netbox client
""" """
import uuid
from os import PathLike from os import PathLike
from unittest.mock import patch, Mock
import responses import responses
from gso.services.netbox_client import NetBoxClient from gso.services.netbox_client import NetBoxClient
...@@ -60,3 +63,26 @@ def test_get_all_interfaces(data_config_filename: PathLike): ...@@ -60,3 +63,26 @@ def test_get_all_interfaces(data_config_filename: PathLike):
assert result is not None assert result is not None
assert len(result) == num_iface 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)]]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment