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

Added sample test.

parent 42f445d9
No related branches found
No related tags found
1 merge request!89Feature/nat 286 create unit tests for netbox client
Pipeline #84221 failed
...@@ -3,6 +3,7 @@ Unit tests for testing the netbox client ...@@ -3,6 +3,7 @@ Unit tests for testing the netbox client
""" """
import os import os
import json import json
import uuid
from os import PathLike from os import PathLike
from unittest.mock import patch from unittest.mock import patch
...@@ -65,3 +66,26 @@ def test_create_device(data_config_filename: PathLike): ...@@ -65,3 +66,26 @@ def test_create_device(data_config_filename: PathLike):
result = NetBoxClient().create_device(device_name, site_tier) result = NetBoxClient().create_device(device_name, site_tier)
assert result is not None 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)]]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment