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

NAT-286: added test for allocating interface

parent 563065d2
No related branches found
No related tags found
1 merge request!89Feature/nat 286 create unit tests for netbox client
...@@ -167,3 +167,54 @@ def test_reserve_interface(mock_api, device, interface, data_config_filename: Pa ...@@ -167,3 +167,54 @@ def test_reserve_interface(mock_api, device, interface, data_config_filename: Pa
assert updated_interface is not None assert updated_interface is not None
assert updated_interface.enabled is True assert updated_interface.enabled is True
mock_save.assert_called_once()
@patch("gso.services.netbox_client.pynetbox.api")
def test_allocate_interface_exception(mock_api, device, interface, data_config_filename: PathLike):
"""
If the interface is already allocated
the method should throw an exception
"""
# Change the interface to reserved
interface.enabled = True
# Change interface to allocated
interface.mark_connected = True
# expected exception message
exception_message = f"The interface: {interface.name} on device: {device.name} is already allocated."
# Mock netbox api
mock_api.return_value.dcim.devices.get.return_value = device
mock_api.return_value.dcim.interfaces.get.return_value = interface
# Check exception
with pytest.raises(WorkflowStateError) as test_exception:
NetboxClient().allocate_interface(device.name, interface.name)
assert str(test_exception.value) == exception_message
@patch("gso.services.netbox_client.pynetbox.api")
def test_allocation_interface(mock_api, device, interface, data_config_filename: PathLike):
"""
Test a normal allocation of a interface
"""
# Set interface to not allocated
interface.mark_connected = False
# Mock netbox api
mock_api.return_value.dcim.devices.get.return_value = device
mock_api.return_value.dcim.interfaces.get.return_value = interface
# mock save method
mock_save = Mock()
mock_save.save.return_value = interface
interface.save = mock_save
# Check allocation of interface
updated_interface = NetboxClient().allocate_interface(device.name, interface.name)
assert updated_interface is not None
assert updated_interface.mark_connected is True
mock_save.assert_called_once()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment