test_win_shadow.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # -*- coding: utf-8 -*-
  2. '''
  3. :codeauthor: Jayesh Kariya <jayeshk@saltstack.com>
  4. '''
  5. # Import Python Libs
  6. from __future__ import absolute_import, unicode_literals, print_function
  7. # Import Salt Testing Libs
  8. from tests.support.mixins import LoaderModuleMockMixin
  9. from tests.support.unit import TestCase
  10. from tests.support.mock import (
  11. MagicMock,
  12. patch
  13. )
  14. # Import Salt Libs
  15. import salt.modules.win_shadow as win_shadow
  16. class WinShadowTestCase(TestCase, LoaderModuleMockMixin):
  17. '''
  18. Test cases for salt.modules.win_shadow
  19. '''
  20. def setup_loader_modules(self):
  21. return {
  22. win_shadow: {
  23. '__salt__': {
  24. # 'user.info': MagicMock(return_value=True),
  25. 'user.update': MagicMock(return_value=True)
  26. }
  27. }
  28. }
  29. # 'info' function tests: 1
  30. def test_info(self):
  31. '''
  32. Test if it return information for the specified user
  33. '''
  34. mock_user_info = MagicMock(return_value={'name': 'SALT',
  35. 'password_changed': '',
  36. 'expiration_date': ''})
  37. with patch.dict(win_shadow.__salt__, {'user.info': mock_user_info}):
  38. self.assertDictEqual(win_shadow.info('SALT'), {'name': 'SALT',
  39. 'passwd': 'Unavailable',
  40. 'lstchg': '',
  41. 'min': '',
  42. 'max': '',
  43. 'warn': '',
  44. 'inact': '',
  45. 'expire': ''})
  46. # 'set_password' function tests: 1
  47. def test_set_password(self):
  48. '''
  49. Test if it set the password for a named user.
  50. '''
  51. mock_cmd = MagicMock(return_value={'retcode': False})
  52. mock_user_info = MagicMock(return_value={'name': 'SALT',
  53. 'password_changed': '',
  54. 'expiration_date': ''})
  55. with patch.dict(win_shadow.__salt__, {'cmd.run_all': mock_cmd,
  56. 'user.info': mock_user_info}):
  57. self.assertTrue(win_shadow.set_password('root', 'mysecretpassword'))