2015-02-13 11:33:26 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
|
|
|
:codeauthor: :email:`Jayesh Kariya <jayeshk@saltstack.com>`
|
|
|
|
'''
|
|
|
|
|
2015-02-13 18:30:45 +00:00
|
|
|
# Import Python Libs
|
2018-01-26 14:23:44 +00:00
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
2015-02-13 18:30:45 +00:00
|
|
|
|
2015-02-13 11:33:26 +00:00
|
|
|
# Import Salt Testing Libs
|
2017-03-21 18:27:29 +00:00
|
|
|
from tests.support.mixins import LoaderModuleMockMixin
|
|
|
|
from tests.support.unit import TestCase
|
2017-02-27 13:58:07 +00:00
|
|
|
from tests.support.mock import (
|
2015-02-13 11:33:26 +00:00
|
|
|
MagicMock,
|
|
|
|
patch
|
|
|
|
)
|
|
|
|
|
|
|
|
# Import Salt Libs
|
2017-03-21 17:15:36 +00:00
|
|
|
import salt.modules.rdp as rdp
|
2015-02-13 11:33:26 +00:00
|
|
|
|
|
|
|
|
2017-03-21 18:27:29 +00:00
|
|
|
class RdpTestCase(TestCase, LoaderModuleMockMixin):
|
2015-02-13 11:33:26 +00:00
|
|
|
'''
|
|
|
|
Test cases for salt.modules.rdp
|
|
|
|
'''
|
2017-03-22 12:12:36 +00:00
|
|
|
def setup_loader_modules(self):
|
|
|
|
return {rdp: {}}
|
2017-03-21 18:27:29 +00:00
|
|
|
|
2015-02-13 11:33:26 +00:00
|
|
|
# 'enable' function tests: 1
|
|
|
|
|
|
|
|
def test_enable(self):
|
|
|
|
'''
|
|
|
|
Test if it enables RDP the service on the server
|
|
|
|
'''
|
|
|
|
mock = MagicMock(return_value=True)
|
2017-04-10 13:00:57 +00:00
|
|
|
with patch.dict(rdp.__salt__, {'cmd.run': mock}), \
|
|
|
|
patch('salt.modules.rdp._parse_return_code_powershell',
|
|
|
|
MagicMock(return_value=0)):
|
2015-02-13 11:33:26 +00:00
|
|
|
self.assertTrue(rdp.enable())
|
|
|
|
|
|
|
|
# 'disable' function tests: 1
|
|
|
|
|
|
|
|
def test_disable(self):
|
|
|
|
'''
|
|
|
|
Test if it disables RDP the service on the server
|
|
|
|
'''
|
|
|
|
mock = MagicMock(return_value=True)
|
2017-04-10 13:00:57 +00:00
|
|
|
with patch.dict(rdp.__salt__, {'cmd.run': mock}), \
|
|
|
|
patch('salt.modules.rdp._parse_return_code_powershell',
|
|
|
|
MagicMock(return_value=0)):
|
2015-02-13 11:33:26 +00:00
|
|
|
self.assertTrue(rdp.disable())
|
|
|
|
|
|
|
|
# 'status' function tests: 1
|
|
|
|
|
|
|
|
def test_status(self):
|
|
|
|
'''
|
|
|
|
Test if it shows rdp is enabled on the server
|
|
|
|
'''
|
|
|
|
mock = MagicMock(return_value='1')
|
|
|
|
with patch.dict(rdp.__salt__, {'cmd.run': mock}):
|
|
|
|
self.assertTrue(rdp.status())
|