mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
Fix unit tests
This commit is contained in:
parent
87097eefb6
commit
008af0ac6b
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user