Skip to content
Snippets Groups Projects
Commit f0774e61 authored by Hakan Calim's avatar Hakan Calim
Browse files

NAT-286: fixed problem in test_interface_reservation

parent 65ead28f
No related branches found
No related tags found
1 merge request!89Feature/nat 286 create unit tests for netbox client
Pipeline #84240 failed
...@@ -4,7 +4,7 @@ Unit tests for testing the netbox client ...@@ -4,7 +4,7 @@ Unit tests for testing the netbox client
import uuid import uuid
from os import PathLike from os import PathLike
from unittest.mock import patch from unittest.mock import patch, Mock
import pytest import pytest
from pynetbox.core.response import Record from pynetbox.core.response import Record
...@@ -62,6 +62,21 @@ def interface(): ...@@ -62,6 +62,21 @@ def interface():
return Record(values, None, None) return Record(values, None, None)
@pytest.fixture(scope="module")
def app():
app = Mock()
app.token = "abc123"
app.base_url = "http://localhost:8080/testing/api"
return app
@pytest.fixture(scope="module")
def endpoint():
endpoint = Mock()
endpoint.name = "test-endpoint"
return endpoint
@patch("gso.services.netbox_client.pynetbox.api") @patch("gso.services.netbox_client.pynetbox.api")
def test_create_device(mock_api, def test_create_device(mock_api,
device, device,
...@@ -158,15 +173,18 @@ def test_reserve_interface(mock_api, device, interface, data_config_filename: Pa ...@@ -158,15 +173,18 @@ def test_reserve_interface(mock_api, device, interface, data_config_filename: Pa
""" """
# Set interface to not reserved # Set interface to not reserved
interface.enabled = False interface.enabled = False
interface.api = mock_api
# Mock netbox api # Mock netbox api
mock_api.return_value.dcim.devices.get.return_value = device mock_api.return_value.dcim.devices.get.return_value = device
mock_api.return_value.dcim.interfaces.get.return_value = interface mock_api.return_value.dcim.interfaces.get.return_value = interface
mock_api.return_value.dcim.interfaces.save.return_value = interface
# mock save method
mock_save = Mock()
mock_save.save.return_value = interface
interface.save = mock_save
# Check reservation of interface # Check reservation of interface
updated_interface = NetBoxClient().reserve_interface(device.name, interface.name) updated_interface = NetBoxClient().reserve_interface(device.name, interface.name)
assert updated_interface is not None assert updated_interface is not None
assert updated_interface.enabled is not True assert updated_interface.enabled is True
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment