From 008af0ac6b306b0478fb5769e1bf73002b00773a Mon Sep 17 00:00:00 2001 From: twangboy Date: Wed, 16 May 2018 15:13:24 -0600 Subject: [PATCH] Fix unit tests --- tests/unit/modules/test_win_snmp.py | 39 +++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/tests/unit/modules/test_win_snmp.py b/tests/unit/modules/test_win_snmp.py index 9660d5d6a0..295be4e842 100644 --- a/tests/unit/modules/test_win_snmp.py +++ b/tests/unit/modules/test_win_snmp.py @@ -11,6 +11,7 @@ from __future__ import absolute_import # Import Salt Libs import salt.modules.win_snmp as win_snmp +from salt.exceptions import CommandExecutionError # Import Salt Testing Libs from tests.support.mixins import LoaderModuleMockMixin @@ -70,19 +71,47 @@ class WinSnmpTestCase(TestCase, LoaderModuleMockMixin): ''' Test - Get the current accepted SNMP community names and their permissions. ''' - mock_value = MagicMock(return_value=[{'vdata': 16, - 'vname': 'TestCommunity'}]) - with patch.dict(win_snmp.__salt__, {'reg.list_values': mock_value}): + mock_ret = MagicMock(return_value=[{'vdata': 16, + 'vname': 'TestCommunity'}]) + mock_false = MagicMock(return_value=False) + with patch.dict(win_snmp.__salt__, {'reg.list_values': mock_ret, + 'reg.key_exists': mock_false}): self.assertEqual(win_snmp.get_community_names(), COMMUNITY_NAMES) + def test_get_community_names_gpo(self): + ''' + Test - Get the current accepted SNMP community names and their permissions. + ''' + mock_ret = MagicMock(return_value=[{'vdata': 'TestCommunity', + 'vname': 1}]) + mock_false = MagicMock(return_value=True) + with patch.dict(win_snmp.__salt__, {'reg.list_values': mock_ret, + 'reg.key_exists': mock_false}): + self.assertEqual(win_snmp.get_community_names(), + {'TestCommunity': 'Managed by GPO'}) + def test_set_community_names(self): ''' Test - Manage the SNMP accepted community names and their permissions. ''' - mock_value = MagicMock(return_value=True) + mock_true = MagicMock(return_value=True) kwargs = {'communities': COMMUNITY_NAMES} - with patch.dict(win_snmp.__salt__, {'reg.set_value': mock_value}), \ + mock_false = MagicMock(return_value=False) + with patch.dict(win_snmp.__salt__, {'reg.set_value': mock_true, + 'reg.key_exists': mock_false}), \ patch('salt.modules.win_snmp.get_community_names', MagicMock(return_value=COMMUNITY_NAMES)): self.assertTrue(win_snmp.set_community_names(**kwargs)) + + def test_set_community_names_gpo(self): + ''' + Test - Manage the SNMP accepted community names and their permissions. + ''' + mock_true = MagicMock(return_value=True) + kwargs = {'communities': COMMUNITY_NAMES} + with patch.dict(win_snmp.__salt__, {'reg.set_value': mock_true, + 'reg.key_exists': mock_true}), \ + patch('salt.modules.win_snmp.get_community_names', + MagicMock(return_value=COMMUNITY_NAMES)): + self.assertRaises(CommandExecutionError, win_snmp.set_community_names, **kwargs)