2017-09-07 19:33:21 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
2018-05-28 21:13:12 +00:00
|
|
|
:codeauthor: Shane Lee <slee@saltstack.com>
|
2017-09-07 19:33:21 +00:00
|
|
|
'''
|
|
|
|
# Import Python Libs
|
2018-01-24 20:47:14 +00:00
|
|
|
from __future__ import absolute_import, unicode_literals, print_function
|
2017-09-07 19:33:21 +00:00
|
|
|
import os
|
|
|
|
|
|
|
|
# Import Salt Testing Libs
|
|
|
|
from tests.support.unit import TestCase, skipIf
|
2018-10-17 22:45:32 +00:00
|
|
|
from tests.support.mock import patch, NO_MOCK, NO_MOCK_REASON
|
2017-09-07 19:33:21 +00:00
|
|
|
|
|
|
|
# Import Salt Libs
|
|
|
|
import salt.modules.win_file as win_file
|
|
|
|
from salt.exceptions import CommandExecutionError
|
2017-12-11 23:43:33 +00:00
|
|
|
import salt.utils.platform
|
2018-10-03 00:18:55 +00:00
|
|
|
import salt.utils.win_dacl
|
2017-09-07 19:33:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
2017-09-07 19:38:52 +00:00
|
|
|
class WinFileTestCase(TestCase):
|
2017-09-07 19:33:21 +00:00
|
|
|
'''
|
|
|
|
Test cases for salt.modules.win_file
|
|
|
|
'''
|
|
|
|
FAKE_RET = {'fake': 'ret data'}
|
2017-12-11 23:43:33 +00:00
|
|
|
if salt.utils.platform.is_windows():
|
2017-09-07 19:38:52 +00:00
|
|
|
FAKE_PATH = os.sep.join(['C:', 'path', 'does', 'not', 'exist'])
|
|
|
|
else:
|
|
|
|
FAKE_PATH = os.sep.join(['path', 'does', 'not', 'exist'])
|
2017-09-07 19:33:21 +00:00
|
|
|
|
|
|
|
def test_issue_43328_stats(self):
|
|
|
|
'''
|
2017-09-13 23:10:15 +00:00
|
|
|
Make sure that a CommandExecutionError is raised if the file does NOT
|
|
|
|
exist
|
2017-09-07 19:33:21 +00:00
|
|
|
'''
|
|
|
|
with patch('os.path.exists', return_value=False):
|
2017-09-11 17:30:18 +00:00
|
|
|
self.assertRaises(CommandExecutionError,
|
|
|
|
win_file.stats,
|
|
|
|
self.FAKE_PATH)
|
2017-09-07 19:33:21 +00:00
|
|
|
|
|
|
|
def test_issue_43328_check_perms_no_ret(self):
|
|
|
|
'''
|
2017-09-13 23:10:15 +00:00
|
|
|
Make sure that a CommandExecutionError is raised if the file does NOT
|
|
|
|
exist
|
2017-09-07 19:33:21 +00:00
|
|
|
'''
|
|
|
|
with patch('os.path.exists', return_value=False):
|
|
|
|
self.assertRaises(
|
|
|
|
CommandExecutionError, win_file.check_perms, self.FAKE_PATH)
|