2016-09-03 19:34:28 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
|
|
|
:synopsis: Unit Tests for Windows SNMP Module 'module.win_snmp'
|
|
|
|
:platform: Windows
|
|
|
|
:maturity: develop
|
2017-06-14 17:53:05 +00:00
|
|
|
.. versionadded:: 2017.7.0
|
2016-09-03 19:34:28 +00:00
|
|
|
'''
|
|
|
|
|
|
|
|
# Import Python Libs
|
2018-01-24 20:47:14 +00:00
|
|
|
from __future__ import absolute_import, unicode_literals, print_function
|
2016-09-03 19:34:28 +00:00
|
|
|
|
|
|
|
# Import Salt Libs
|
2017-03-21 17:15:36 +00:00
|
|
|
import salt.modules.win_snmp as win_snmp
|
2016-09-03 19:34:28 +00:00
|
|
|
|
|
|
|
# Import Salt Testing Libs
|
2017-03-21 18:27:29 +00:00
|
|
|
from tests.support.mixins import LoaderModuleMockMixin
|
2017-02-27 13:58:07 +00:00
|
|
|
from tests.support.unit import TestCase, skipIf
|
|
|
|
from tests.support.mock import (
|
2016-09-03 19:34:28 +00:00
|
|
|
MagicMock,
|
|
|
|
patch,
|
|
|
|
NO_MOCK,
|
|
|
|
NO_MOCK_REASON,
|
|
|
|
)
|
|
|
|
|
|
|
|
COMMUNITY_NAMES = {'TestCommunity': 'Read Create'}
|
|
|
|
|
|
|
|
|
|
|
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
2017-03-21 18:27:29 +00:00
|
|
|
class WinSnmpTestCase(TestCase, LoaderModuleMockMixin):
|
2016-09-03 19:34:28 +00:00
|
|
|
'''
|
|
|
|
Test cases for salt.modules.win_snmp
|
|
|
|
'''
|
2017-03-21 18:27:29 +00:00
|
|
|
def setup_loader_modules(self):
|
|
|
|
return {win_snmp: {}}
|
2016-09-03 19:34:28 +00:00
|
|
|
|
|
|
|
def test_get_agent_service_types(self):
|
|
|
|
'''
|
|
|
|
Test - Get the sysServices types that can be configured.
|
|
|
|
'''
|
|
|
|
with patch.dict(win_snmp.__salt__):
|
|
|
|
self.assertIsInstance(win_snmp.get_agent_service_types(), list)
|
|
|
|
|
|
|
|
def test_get_permission_types(self):
|
|
|
|
'''
|
|
|
|
Test - Get the permission types that can be configured for communities.
|
|
|
|
'''
|
|
|
|
with patch.dict(win_snmp.__salt__):
|
|
|
|
self.assertIsInstance(win_snmp.get_permission_types(), list)
|
|
|
|
|
|
|
|
def test_get_auth_traps_enabled(self):
|
|
|
|
'''
|
|
|
|
Test - Determine whether the host is configured to send authentication traps.
|
|
|
|
'''
|
|
|
|
mock_value = MagicMock(return_value={'vdata': 1})
|
|
|
|
with patch.dict(win_snmp.__salt__, {'reg.read_value': mock_value}):
|
|
|
|
self.assertTrue(win_snmp.get_auth_traps_enabled())
|
|
|
|
|
|
|
|
def test_set_auth_traps_enabled(self):
|
|
|
|
'''
|
|
|
|
Test - Manage the sending of authentication traps.
|
|
|
|
'''
|
|
|
|
mock_value = MagicMock(return_value=True)
|
|
|
|
kwargs = {'status': True}
|
2017-04-10 13:00:57 +00:00
|
|
|
with patch.dict(win_snmp.__salt__, {'reg.set_value': mock_value}), \
|
|
|
|
patch('salt.modules.win_snmp.get_auth_traps_enabled',
|
|
|
|
MagicMock(return_value=True)):
|
2016-09-03 19:34:28 +00:00
|
|
|
self.assertTrue(win_snmp.set_auth_traps_enabled(**kwargs))
|
|
|
|
|
|
|
|
def test_get_community_names(self):
|
|
|
|
'''
|
|
|
|
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}):
|
|
|
|
self.assertEqual(win_snmp.get_community_names(),
|
|
|
|
COMMUNITY_NAMES)
|
|
|
|
|
|
|
|
def test_set_community_names(self):
|
|
|
|
'''
|
|
|
|
Test - Manage the SNMP accepted community names and their permissions.
|
|
|
|
'''
|
|
|
|
mock_value = MagicMock(return_value=True)
|
|
|
|
kwargs = {'communities': COMMUNITY_NAMES}
|
2017-04-10 13:00:57 +00:00
|
|
|
with patch.dict(win_snmp.__salt__, {'reg.set_value': mock_value}), \
|
|
|
|
patch('salt.modules.win_snmp.get_community_names',
|
|
|
|
MagicMock(return_value=COMMUNITY_NAMES)):
|
2016-09-03 19:34:28 +00:00
|
|
|
self.assertTrue(win_snmp.set_community_names(**kwargs))
|