Fix unit tests

This commit is contained in:
twangboy 2018-05-16 15:13:24 -06:00
parent 87097eefb6
commit 008af0ac6b
No known key found for this signature in database
GPG Key ID: 93FF3BDEB278C9EB

View File

@ -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,
mock_ret = MagicMock(return_value=[{'vdata': 16,
'vname': 'TestCommunity'}])
with patch.dict(win_snmp.__salt__, {'reg.list_values': mock_value}):
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)