2017-09-07 19:33:21 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
|
|
|
:codeauthor: :email:`Shane Lee <slee@saltstack.com>`
|
|
|
|
'''
|
|
|
|
# Import Python Libs
|
|
|
|
from __future__ import absolute_import
|
|
|
|
import os
|
|
|
|
|
|
|
|
# Import Salt Testing Libs
|
|
|
|
from tests.support.unit import TestCase, skipIf
|
|
|
|
from tests.support.mock import (
|
|
|
|
patch,
|
|
|
|
NO_MOCK,
|
|
|
|
NO_MOCK_REASON
|
|
|
|
)
|
|
|
|
|
|
|
|
# Import Salt Libs
|
|
|
|
import salt.modules.win_file as win_file
|
|
|
|
from salt.exceptions import CommandExecutionError
|
2017-09-07 19:38:52 +00:00
|
|
|
import salt.utils
|
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-09-07 19:38:52 +00:00
|
|
|
if salt.utils.is_windows():
|
|
|
|
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)
|