Skip to content

Commit

Permalink
Add tests for cisco poe
Browse files Browse the repository at this point in the history
  • Loading branch information
stveit committed Oct 31, 2023
1 parent 2a50a6e commit 896dc8d
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions tests/unittests/portadmin/portadmin_poe_cisco_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from mock import Mock

import pytest

from nav.portadmin.snmp.cisco import Cisco
from nav.portadmin.handlers import (
POEIndexNotFoundError,
POEStateNotSupportedError,
)


def test_returns_correct_poe_state_options_cisco(handler_cisco):
state_options = handler_cisco.get_poe_state_options()
assert Cisco.POE_AUTO in state_options
assert Cisco.POE_STATIC in state_options
assert Cisco.POE_LIMIT in state_options
assert Cisco.POE_DISABLE in state_options


class TestGetPoeState:
def test_should_raise_exception_if_unknown_poe_state_cisco(self, handler_cisco):
handler_cisco._get_poe_indexes_for_interface = Mock(return_value=(1, 1))
handler_cisco._query_netbox = Mock(return_value=76)
interface = Mock()
with pytest.raises(POEStateNotSupportedError):
handler_cisco.get_poe_states([interface])

def test_should_raise_exception_if_no_poe_indexes_cisco(self, handler_cisco):
handler_cisco._get_poe_indexes_for_interface = Mock(
side_effect=POEIndexNotFoundError("Fail")
)
interface = Mock()
with pytest.raises(POEIndexNotFoundError):
handler_cisco.get_poe_states([interface])

def test_dict_should_give_none_if_interface_does_not_support_poe(
self, handler_cisco
):
handler_cisco._get_poe_indexes_for_interface = Mock(return_value=(1, 1))
handler_cisco._query_netbox = Mock(return_value=None)
interface = Mock(ifindex=1)
states = handler_cisco.get_poe_states([interface])
assert states[interface.ifindex] is None

def test_returns_correct_poe_state_cisco(self, handler_cisco):
expected_state = Cisco.POE_AUTO
handler_cisco._get_poe_indexes_for_interface = Mock(return_value=(1, 1))
handler_cisco._query_netbox = Mock(return_value=expected_state.state)
interface = Mock(ifindex=1)
state = handler_cisco.get_poe_states([interface])
assert state[interface.ifindex] == expected_state

0 comments on commit 896dc8d

Please sign in to comment.