Skip to content

Commit

Permalink
Proper mocking. Code is mocked! Runs on non windows too.
Browse files Browse the repository at this point in the history
  • Loading branch information
s0undt3ch committed Mar 28, 2017
1 parent 5c13f7b commit 93ad2cc
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 60 deletions.
14 changes: 5 additions & 9 deletions tests/unit/modules/test_rdp.py
Expand Up @@ -7,7 +7,8 @@
from __future__ import absolute_import

# Import Salt Testing Libs
from tests.support.unit import TestCase, skipIf
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import TestCase
from tests.support.mock import (
MagicMock,
patch
Expand All @@ -16,18 +17,13 @@
# Import Salt Libs
import salt.modules.rdp as rdp

# Globals
rdp.__salt__ = {}

# Make sure this module runs on Windows system
IS_RDP = rdp.__virtual__()


@skipIf(not IS_RDP, "This test case runs only on Windows system")
class RdpTestCase(TestCase):
class RdpTestCase(TestCase, LoaderModuleMockMixin):
'''
Test cases for salt.modules.rdp
'''
loader_module = rdp

# 'enable' function tests: 1

@patch('salt.modules.rdp._parse_return_code_powershell',
Expand Down
16 changes: 6 additions & 10 deletions tests/unit/modules/test_win_autoruns.py
Expand Up @@ -7,7 +7,8 @@
from __future__ import absolute_import

# Import Salt Testing Libs
from tests.support.unit import TestCase, skipIf
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import TestCase
from tests.support.mock import (
MagicMock,
patch
Expand All @@ -16,23 +17,18 @@
# Import Salt Libs
import salt.modules.win_autoruns as win_autoruns

# Globals
win_autoruns.__salt__ = {}
win_autoruns.__grains__ = {}

# Make sure this module runs on Windows system
IS_WIN = win_autoruns.__virtual__()

KEY = ['HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Run',
'HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Run /reg:64',
'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run']


@skipIf(not IS_WIN, "This test case runs only on Windows system")
class WinAutorunsTestCase(TestCase):
class WinAutorunsTestCase(TestCase, LoaderModuleMockMixin):
'''
Test cases for salt.modules.win_autoruns
'''
def setup_loader_modules(self):
return {win_autoruns: {}}

# 'list_' function tests: 1

@patch('os.listdir', MagicMock(return_value=[]))
Expand Down
13 changes: 6 additions & 7 deletions tests/unit/modules/test_win_firewall.py
Expand Up @@ -7,7 +7,8 @@
from __future__ import absolute_import

# Import Salt Testing Libs
from tests.support.unit import TestCase, skipIf
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import TestCase
from tests.support.mock import (
MagicMock,
patch,
Expand All @@ -16,17 +17,15 @@

# Import Salt Libs
import salt.modules.win_firewall as win_firewall
import salt.utils

# Globals
win_firewall.__salt__ = {}


@skipIf(not salt.utils.is_windows(), 'This test case runs only on Windows system')
class WinFirewallTestCase(TestCase):
class WinFirewallTestCase(TestCase, LoaderModuleMockMixin):
'''
Test cases for salt.modules.win_firewall
'''
def setup_loader_modules(self):
return {win_firewall: {}}

# 'get_config' function tests: 1

def test_get_config(self):
Expand Down
13 changes: 5 additions & 8 deletions tests/unit/modules/test_win_iis.py
Expand Up @@ -15,6 +15,7 @@
import salt.modules.win_iis as win_iis

# Import Salt Testing Libs
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import TestCase, skipIf
from tests.support.mock import (
MagicMock,
Expand All @@ -23,12 +24,6 @@
NO_MOCK_REASON,
)

# Globals
win_iis.__salt__ = {}

# Make sure this module runs on Windows system
HAS_IIS = win_iis.__virtual__()

APP_LIST = {
'testApp': {
'apppool': 'MyTestPool',
Expand Down Expand Up @@ -121,13 +116,15 @@
CERT_BINDING_INFO = '*:443:mytestsite.local'


@skipIf(not HAS_IIS, 'This test case runs only on Windows systems')
@skipIf(NO_MOCK, NO_MOCK_REASON)
class WinIisTestCase(TestCase):
class WinIisTestCase(TestCase, LoaderModuleMockMixin):
'''
Test cases for salt.modules.win_iis
'''

def setup_loader_modules(self):
return {win_iis: {}}

@patch('salt.modules.win_iis._srvmgr',
MagicMock(return_value={'retcode': 0}))
@patch('salt.modules.win_iis.list_apppools',
Expand Down
15 changes: 6 additions & 9 deletions tests/unit/modules/test_win_ntp.py
Expand Up @@ -7,7 +7,8 @@
from __future__ import absolute_import

# Import Salt Testing Libs
from tests.support.unit import TestCase, skipIf
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import TestCase
from tests.support.mock import (
MagicMock,
patch
Expand All @@ -16,18 +17,14 @@
# Import Salt Libs
import salt.modules.win_ntp as win_ntp

# Globals
win_ntp.__salt__ = {}

# Make sure this module runs on Windows system
IS_WIN = win_ntp.__virtual__()


@skipIf(not IS_WIN, "This test case runs only on Windows system")
class WinNtpTestCase(TestCase):
class WinNtpTestCase(TestCase, LoaderModuleMockMixin):
'''
Test cases for salt.modules.win_ntp
'''
def setup_loader_modules(self):
return {win_ntp: {}}

# 'set_servers' function tests: 1

def test_set_servers(self):
Expand Down
12 changes: 4 additions & 8 deletions tests/unit/modules/test_win_snmp.py
Expand Up @@ -13,6 +13,7 @@
import salt.modules.win_snmp as win_snmp

# Import Salt Testing Libs
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import TestCase, skipIf
from tests.support.mock import (
MagicMock,
Expand All @@ -21,21 +22,16 @@
NO_MOCK_REASON,
)

# Globals
win_snmp.__salt__ = {}

# Make sure this module runs on Windows system
HAS_SNMP = win_snmp.__virtual__()

COMMUNITY_NAMES = {'TestCommunity': 'Read Create'}


@skipIf(not HAS_SNMP, 'This test case runs only on Windows systems')
@skipIf(NO_MOCK, NO_MOCK_REASON)
class WinSnmpTestCase(TestCase):
class WinSnmpTestCase(TestCase, LoaderModuleMockMixin):
'''
Test cases for salt.modules.win_snmp
'''
def setup_loader_modules(self):
return {win_snmp: {}}

def test_get_agent_service_types(self):
'''
Expand Down
15 changes: 6 additions & 9 deletions tests/unit/modules/test_win_timezone.py
Expand Up @@ -7,7 +7,8 @@
from __future__ import absolute_import

# Import Salt Testing Libs
from tests.support.unit import TestCase, skipIf
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import TestCase
from tests.support.mock import (
MagicMock,
patch
Expand All @@ -16,18 +17,14 @@
# Import Salt Libs
import salt.modules.win_timezone as win_timezone

# Globals
win_timezone.__salt__ = {}

# Make sure this module runs on Windows system
IS_WIN = win_timezone.__virtual__()


@skipIf(not IS_WIN, "This test case runs only on Windows system")
class WinTimezoneTestCase(TestCase):
class WinTimezoneTestCase(TestCase, LoaderModuleMockMixin):
'''
Test cases for salt.modules.win_timezone
'''
def setup_loader_modules(self):
return {win_timezone: {}}

# 'get_zone' function tests: 1

def test_get_zone(self):
Expand Down

0 comments on commit 93ad2cc

Please sign in to comment.