salt/tests/unit/modules/test_win_shadow.py

67 lines
2.4 KiB
Python
Raw Normal View History

2015-02-25 13:18:05 +00:00
# -*- coding: utf-8 -*-
'''
:codeauthor: :email:`Jayesh Kariya <jayeshk@saltstack.com>`
'''
# Import Python Libs
from __future__ import absolute_import
# Import Salt Testing Libs
2017-03-22 16:42:17 +00:00
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import TestCase
from tests.support.mock import (
2015-02-25 13:18:05 +00:00
MagicMock,
patch
)
# Import Salt Libs
import salt.modules.win_shadow as win_shadow
2015-02-25 13:18:05 +00:00
2017-03-22 16:42:17 +00:00
class WinShadowTestCase(TestCase, LoaderModuleMockMixin):
2015-02-25 13:18:05 +00:00
'''
Test cases for salt.modules.win_shadow
'''
2017-03-22 16:42:17 +00:00
def setup_loader_modules(self):
return {
win_shadow: {
'__salt__': {
# 'user.info': MagicMock(return_value=True),
'user.update': MagicMock(return_value=True)
}
}
}
2015-02-25 13:18:05 +00:00
# 'info' function tests: 1
def test_info(self):
'''
Test if it return information for the specified user
'''
2017-03-22 16:42:17 +00:00
mock_user_info = MagicMock(return_value={'name': 'SALT',
'password_changed': '',
'expiration_date': ''})
with patch.dict(win_shadow.__salt__, {'user.info': mock_user_info}):
self.assertDictEqual(win_shadow.info('SALT'), {'name': 'SALT',
'passwd': 'Unavailable',
'lstchg': '',
'min': '',
'max': '',
'warn': '',
'inact': '',
'expire': ''})
2015-02-25 13:18:05 +00:00
# 'set_password' function tests: 1
def test_set_password(self):
'''
Test if it set the password for a named user.
'''
mock_cmd = MagicMock(return_value={'retcode': False})
2017-03-22 16:42:17 +00:00
mock_user_info = MagicMock(return_value={'name': 'SALT',
'password_changed': '',
'expiration_date': ''})
with patch.dict(win_shadow.__salt__, {'cmd.run_all': mock_cmd,
'user.info': mock_user_info}):
2015-02-25 13:18:05 +00:00
self.assertTrue(win_shadow.set_password('root', 'mysecretpassword'))