Skip to content

Commit

Permalink
Update arnold enable/disable tests
Browse files Browse the repository at this point in the history
Use the new dependency injection path to insert our mocked SNMP Agent
into change_port_status().

Also, since change_port_status() now gets a partial call to an Snmp
constructor, it will only feed in the IP address of the Netbox, so the
asserts needed to change to account for that.
  • Loading branch information
lunkwill42 committed Nov 16, 2023
1 parent 1009841 commit e77fd49
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions tests/unittests/arnold/arnold_snmp_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""Tests for Arnold using snmp objects"""
from nav.arnold import change_port_status
from mock import Mock, patch
from unittest.mock import Mock, patch
import unittest

from nav.models.manage import ManagementProfile


@patch('nav.Snmp.Snmp', autospec=True)
class TestArnoldSnmp(unittest.TestCase):
Expand All @@ -28,9 +30,13 @@ def create_interface_mock(self):

def create_management_profile_mock(self):
"""Create management profile model mock object"""
profile = Mock()
profile.snmp_version = 1
profile.snmp_community = "public"
profile = ManagementProfile(
protocol=ManagementProfile.PROTOCOL_SNMP,
configuration={
"version": 1,
"community": "public",
},
)
return profile

def create_netbox_mock(self):
Expand All @@ -46,11 +52,9 @@ def test_change_port_status_enable(self, snmp):
instance = snmp.return_value
identity = Mock()
identity.interface = self.interface
change_port_status('enable', identity)
change_port_status('enable', identity, agent_getter=lambda profile: snmp)

snmp.assert_called_once_with(
self.ip, self.profile.snmp_community, self.profile.snmp_version
)
snmp.assert_called_once_with(self.ip)
instance.set.assert_called_once_with(
self.port_status_oid + '.' + str(self.ifindex), 'i', 1
)
Expand All @@ -60,11 +64,9 @@ def test_change_port_status_disable(self, snmp):
instance = snmp.return_value
identity = Mock()
identity.interface = self.interface
change_port_status('disable', identity)
change_port_status('disable', identity, agent_getter=lambda profile: snmp)

snmp.assert_called_once_with(
self.ip, self.profile.snmp_community, self.profile.snmp_version
)
snmp.assert_called_once_with(self.ip)
instance.set.assert_called_once_with(
self.port_status_oid + '.' + str(self.ifindex), 'i', 2
)

0 comments on commit e77fd49

Please sign in to comment.