mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #3 from jfindlay/win_sys
update win_system exec mod unit tests
This commit is contained in:
commit
4195803e56
1 changed files with 33 additions and 6 deletions
|
@ -5,6 +5,7 @@
|
|||
|
||||
# Import Python Libs
|
||||
from __future__ import absolute_import
|
||||
from datetime import datetime
|
||||
|
||||
# Import Salt Testing Libs
|
||||
from salttesting import TestCase, skipIf
|
||||
|
@ -20,6 +21,16 @@ ensure_in_syspath('../../')
|
|||
# Import Salt Libs
|
||||
from salt.modules import win_system
|
||||
|
||||
# Import 3rd Party Libs
|
||||
try:
|
||||
import win32net
|
||||
import win32api
|
||||
import pywintypes
|
||||
from ctypes import windll
|
||||
HAS_WIN32NET_MODS = True
|
||||
except ImportError:
|
||||
HAS_WIN32NET_MODS = False
|
||||
|
||||
win_system.__salt__ = {}
|
||||
|
||||
|
||||
|
@ -43,6 +54,7 @@ class WinSystemTestCase(TestCase):
|
|||
self.assertEqual(win_system.init(3),
|
||||
'Not implemented on Windows at this time.')
|
||||
|
||||
@skipIf(not HAS_WIN32NET_MODS, 'this test needs the w32net library')
|
||||
def test_poweroff(self):
|
||||
'''
|
||||
Test to poweroff a running system
|
||||
|
@ -51,6 +63,7 @@ class WinSystemTestCase(TestCase):
|
|||
with patch.object(win_system, 'shutdown', mock):
|
||||
self.assertEqual(win_system.poweroff(), 'salt')
|
||||
|
||||
@skipIf(not HAS_WIN32NET_MODS, 'this test needs the w32net library')
|
||||
def test_reboot(self):
|
||||
'''
|
||||
Test to reboot the system
|
||||
|
@ -59,6 +72,7 @@ class WinSystemTestCase(TestCase):
|
|||
with patch.dict(win_system.__salt__, {'cmd.run': mock}):
|
||||
self.assertEqual(win_system.reboot(), 'salt')
|
||||
|
||||
@skipIf(not HAS_WIN32NET_MODS, 'this test needs the w32net library')
|
||||
def test_shutdown(self):
|
||||
'''
|
||||
Test to shutdown a running system
|
||||
|
@ -67,6 +81,7 @@ class WinSystemTestCase(TestCase):
|
|||
with patch.dict(win_system.__salt__, {'cmd.run': mock}):
|
||||
self.assertEqual(win_system.shutdown(), 'salt')
|
||||
|
||||
@skipIf(not HAS_WIN32NET_MODS, 'this test needs the w32net library')
|
||||
def test_shutdown_hard(self):
|
||||
'''
|
||||
Test to shutdown a running system with no timeout or warning
|
||||
|
@ -75,6 +90,7 @@ class WinSystemTestCase(TestCase):
|
|||
with patch.dict(win_system.__salt__, {'cmd.run': mock}):
|
||||
self.assertEqual(win_system.shutdown_hard(), 'salt')
|
||||
|
||||
@skipIf(not HAS_WIN32NET_MODS, 'this test needs the w32net library')
|
||||
def test_set_computer_name(self):
|
||||
'''
|
||||
Test to set the Windows computer name
|
||||
|
@ -94,6 +110,7 @@ class WinSystemTestCase(TestCase):
|
|||
|
||||
self.assertFalse(win_system.set_computer_name("salt"))
|
||||
|
||||
@skipIf(not HAS_WIN32NET_MODS, 'this test needs the w32net library')
|
||||
def test_get_pending_computer_name(self):
|
||||
'''
|
||||
Test to get a pending computer name.
|
||||
|
@ -108,6 +125,7 @@ class WinSystemTestCase(TestCase):
|
|||
self.assertEqual(win_system.get_pending_computer_name(),
|
||||
'(salt)')
|
||||
|
||||
@skipIf(not HAS_WIN32NET_MODS, 'this test needs the w32net library')
|
||||
def test_get_computer_name(self):
|
||||
'''
|
||||
Test to get the Windows computer name
|
||||
|
@ -118,6 +136,7 @@ class WinSystemTestCase(TestCase):
|
|||
|
||||
self.assertFalse(win_system.get_computer_name())
|
||||
|
||||
@skipIf(not HAS_WIN32NET_MODS, 'this test needs the w32net library')
|
||||
def test_set_computer_desc(self):
|
||||
'''
|
||||
Test to set the Windows computer description
|
||||
|
@ -131,6 +150,7 @@ class WinSystemTestCase(TestCase):
|
|||
),
|
||||
{'Computer Description': "Salt's comp"})
|
||||
|
||||
@skipIf(not HAS_WIN32NET_MODS, 'this test needs the w32net library')
|
||||
def test_get_computer_desc(self):
|
||||
'''
|
||||
Test to get the Windows computer description
|
||||
|
@ -141,6 +161,7 @@ class WinSystemTestCase(TestCase):
|
|||
|
||||
self.assertFalse(win_system.get_computer_desc())
|
||||
|
||||
@skipIf(not HAS_WIN32NET_MODS, 'this test needs w32net and other windows libraries')
|
||||
def test_join_domain(self):
|
||||
'''
|
||||
Test to join a computer to an Active Directory domain
|
||||
|
@ -161,10 +182,16 @@ class WinSystemTestCase(TestCase):
|
|||
'''
|
||||
Test to get system time
|
||||
'''
|
||||
mock = MagicMock(return_value="11:31:15 AM")
|
||||
with patch.dict(win_system.__salt__, {'cmd.run': mock}):
|
||||
self.assertEqual(win_system.get_system_time(), '11:31:15 AM')
|
||||
tm = datetime.strftime(datetime.now(), "%I:%M %p")
|
||||
win_tm = win_system.get_system_time()
|
||||
try:
|
||||
self.assertEqual(win_tm, tm)
|
||||
except AssertionError:
|
||||
# handle race condition
|
||||
import re
|
||||
self.assertTrue(re.search(r'^\d{2}:\d{2} \w{2}$', win_tm))
|
||||
|
||||
@skipIf(not HAS_WIN32NET_MODS, 'this test needs the w32net library')
|
||||
def test_set_system_time(self):
|
||||
'''
|
||||
Test to set system time
|
||||
|
@ -181,10 +208,10 @@ class WinSystemTestCase(TestCase):
|
|||
'''
|
||||
Test to get system date
|
||||
'''
|
||||
mock = MagicMock(return_value="03-28-13")
|
||||
with patch.dict(win_system.__salt__, {'cmd.run': mock}):
|
||||
self.assertEqual(win_system.get_system_date(), '03-28-13')
|
||||
date = datetime.strftime(datetime.now(), "%a %m/%d/%Y")
|
||||
self.assertEqual(win_system.get_system_date(), date)
|
||||
|
||||
@skipIf(not HAS_WIN32NET_MODS, 'this test needs the w32net library')
|
||||
def test_set_system_date(self):
|
||||
'''
|
||||
Test to set system date
|
||||
|
|
Loading…
Add table
Reference in a new issue