mirror of
https://github.com/valitydev/salt.git
synced 2024-11-06 16:45:27 +00:00
Make them non-destructive tests
This commit is contained in:
parent
d8bede07df
commit
a7d41a85a7
@ -5,21 +5,19 @@
|
||||
# Import Python Libs
|
||||
from __future__ import absolute_import, unicode_literals, print_function
|
||||
import os
|
||||
import tempfile
|
||||
import sys
|
||||
|
||||
# Import Salt Testing Libs
|
||||
from tests.support.helpers import destructiveTest
|
||||
from tests.support.mixins import LoaderModuleMockMixin
|
||||
from tests.support.mock import patch, NO_MOCK, NO_MOCK_REASON
|
||||
from tests.support.mock import MagicMock, NO_MOCK, NO_MOCK_REASON, patch
|
||||
from tests.support.paths import TMP
|
||||
from tests.support.unit import TestCase, skipIf
|
||||
from tests.support.mock import MagicMock
|
||||
|
||||
# Import Salt Libs
|
||||
import salt.modules.win_file as win_file
|
||||
import salt.utils.win_dacl as win_dacl
|
||||
import salt.modules.temp as temp
|
||||
import salt.modules.win_file as win_file
|
||||
import salt.utils.platform
|
||||
import salt.utils.win_dacl as win_dacl
|
||||
from salt.exceptions import CommandExecutionError
|
||||
|
||||
try:
|
||||
@ -78,14 +76,13 @@ class WinFileTestCase(TestCase, LoaderModuleMockMixin):
|
||||
self.assertRaises(
|
||||
CommandExecutionError, win_file.check_perms, self.FAKE_PATH)
|
||||
|
||||
@destructiveTest
|
||||
@skipIf(not salt.utils.platform.is_windows(), 'Skip on Non-Windows systems')
|
||||
@skipIf(WIN_VER < 6, 'Symlinks not supported on Vista an lower')
|
||||
def test_issue_52002_check_file_remove_symlink(self):
|
||||
'''
|
||||
Make sure that directories including symlinks or symlinks can be removed
|
||||
'''
|
||||
base = temp.dir(prefix='base-')
|
||||
base = temp.dir(prefix='base-', parent=TMP)
|
||||
target = os.path.join(base, 'child 1', 'target\\')
|
||||
symlink = os.path.join(base, 'child 2', 'link')
|
||||
try:
|
||||
@ -105,7 +102,6 @@ class WinFileTestCase(TestCase, LoaderModuleMockMixin):
|
||||
win_file.remove(base)
|
||||
|
||||
|
||||
@destructiveTest
|
||||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||
@skipIf(not salt.utils.platform.is_windows(), 'Skip on Non-Windows systems')
|
||||
class WinFileCheckPermsTestCase(TestCase, LoaderModuleMockMixin):
|
||||
@ -128,18 +124,17 @@ class WinFileCheckPermsTestCase(TestCase, LoaderModuleMockMixin):
|
||||
}
|
||||
|
||||
def setUp(self):
|
||||
self.temp_file = tempfile.NamedTemporaryFile(delete=False)
|
||||
self.temp_file.close()
|
||||
salt.utils.win_dacl.set_owner(obj_name=self.temp_file.name,
|
||||
self.temp_file = temp.file(parent=TMP)
|
||||
salt.utils.win_dacl.set_owner(obj_name=self.temp_file,
|
||||
principal=self.current_user)
|
||||
salt.utils.win_dacl.set_inheritance(obj_name=self.temp_file.name,
|
||||
salt.utils.win_dacl.set_inheritance(obj_name=self.temp_file,
|
||||
enabled=True)
|
||||
self.assertEqual(
|
||||
salt.utils.win_dacl.get_owner(obj_name=self.temp_file.name),
|
||||
salt.utils.win_dacl.get_owner(obj_name=self.temp_file),
|
||||
self.current_user)
|
||||
|
||||
def tearDown(self):
|
||||
os.remove(self.temp_file.name)
|
||||
os.remove(self.temp_file)
|
||||
|
||||
def test_check_perms_set_owner_test_true(self):
|
||||
'''
|
||||
@ -147,10 +142,10 @@ class WinFileCheckPermsTestCase(TestCase, LoaderModuleMockMixin):
|
||||
'''
|
||||
expected = {'comment': '',
|
||||
'changes': {'owner': 'Administrators'},
|
||||
'name': self.temp_file.name,
|
||||
'name': self.temp_file,
|
||||
'result': None}
|
||||
with patch.dict(win_dacl.__opts__, {'test': True}):
|
||||
ret = win_file.check_perms(path=self.temp_file.name,
|
||||
ret = win_file.check_perms(path=self.temp_file,
|
||||
owner='Administrators',
|
||||
inheritance=None)
|
||||
self.assertDictEqual(expected, ret)
|
||||
@ -161,9 +156,9 @@ class WinFileCheckPermsTestCase(TestCase, LoaderModuleMockMixin):
|
||||
'''
|
||||
expected = {'comment': '',
|
||||
'changes': {'owner': 'Administrators'},
|
||||
'name': self.temp_file.name,
|
||||
'name': self.temp_file,
|
||||
'result': True}
|
||||
ret = win_file.check_perms(path=self.temp_file.name,
|
||||
ret = win_file.check_perms(path=self.temp_file,
|
||||
owner='Administrators',
|
||||
inheritance=None)
|
||||
self.assertDictEqual(expected, ret)
|
||||
@ -174,11 +169,11 @@ class WinFileCheckPermsTestCase(TestCase, LoaderModuleMockMixin):
|
||||
'''
|
||||
expected = {'comment': '',
|
||||
'changes': {'perms': {'Users': {'deny': 'read_execute'}}},
|
||||
'name': self.temp_file.name,
|
||||
'name': self.temp_file,
|
||||
'result': None}
|
||||
with patch.dict(win_dacl.__opts__, {'test': True}):
|
||||
ret = win_file.check_perms(
|
||||
path=self.temp_file.name,
|
||||
path=self.temp_file,
|
||||
deny_perms={'Users': {'perms': 'read_execute'}},
|
||||
inheritance=None)
|
||||
self.assertDictEqual(expected, ret)
|
||||
@ -189,10 +184,10 @@ class WinFileCheckPermsTestCase(TestCase, LoaderModuleMockMixin):
|
||||
'''
|
||||
expected = {'comment': '',
|
||||
'changes': {'perms': {'Users': {'deny': 'read_execute'}}},
|
||||
'name': self.temp_file.name,
|
||||
'name': self.temp_file,
|
||||
'result': True}
|
||||
ret = win_file.check_perms(
|
||||
path=self.temp_file.name,
|
||||
path=self.temp_file,
|
||||
deny_perms={'Users': {'perms': 'read_execute'}},
|
||||
inheritance=None)
|
||||
self.assertDictEqual(expected, ret)
|
||||
@ -203,11 +198,11 @@ class WinFileCheckPermsTestCase(TestCase, LoaderModuleMockMixin):
|
||||
'''
|
||||
expected = {'comment': '',
|
||||
'changes': {'perms': {'Users': {'grant': 'read_execute'}}},
|
||||
'name': self.temp_file.name,
|
||||
'name': self.temp_file,
|
||||
'result': None}
|
||||
with patch.dict(win_dacl.__opts__, {'test': True}):
|
||||
ret = win_file.check_perms(
|
||||
path=self.temp_file.name,
|
||||
path=self.temp_file,
|
||||
grant_perms={'Users': {'perms': 'read_execute'}},
|
||||
inheritance=None)
|
||||
self.assertDictEqual(expected, ret)
|
||||
@ -218,10 +213,10 @@ class WinFileCheckPermsTestCase(TestCase, LoaderModuleMockMixin):
|
||||
'''
|
||||
expected = {'comment': '',
|
||||
'changes': {'perms': {'Users': {'grant': 'read_execute'}}},
|
||||
'name': self.temp_file.name,
|
||||
'name': self.temp_file,
|
||||
'result': True}
|
||||
ret = win_file.check_perms(
|
||||
path=self.temp_file.name,
|
||||
path=self.temp_file,
|
||||
grant_perms={'Users': {'perms': 'read_execute'}},
|
||||
inheritance=None)
|
||||
self.assertDictEqual(expected, ret)
|
||||
@ -232,10 +227,10 @@ class WinFileCheckPermsTestCase(TestCase, LoaderModuleMockMixin):
|
||||
'''
|
||||
expected = {'comment': '',
|
||||
'changes': {'inheritance': False},
|
||||
'name': self.temp_file.name,
|
||||
'name': self.temp_file,
|
||||
'result': None}
|
||||
with patch.dict(win_dacl.__opts__, {'test': True}):
|
||||
ret = win_file.check_perms(path=self.temp_file.name,
|
||||
ret = win_file.check_perms(path=self.temp_file,
|
||||
inheritance=False)
|
||||
self.assertDictEqual(expected, ret)
|
||||
|
||||
@ -245,9 +240,9 @@ class WinFileCheckPermsTestCase(TestCase, LoaderModuleMockMixin):
|
||||
'''
|
||||
expected = {'comment': '',
|
||||
'changes': {'inheritance': False},
|
||||
'name': self.temp_file.name,
|
||||
'name': self.temp_file,
|
||||
'result': True}
|
||||
ret = win_file.check_perms(path=self.temp_file.name,
|
||||
ret = win_file.check_perms(path=self.temp_file,
|
||||
inheritance=False)
|
||||
self.assertDictEqual(expected, ret)
|
||||
|
||||
@ -257,9 +252,9 @@ class WinFileCheckPermsTestCase(TestCase, LoaderModuleMockMixin):
|
||||
'''
|
||||
expected = {'comment': '',
|
||||
'changes': {},
|
||||
'name': self.temp_file.name,
|
||||
'name': self.temp_file,
|
||||
'result': True}
|
||||
ret = win_file.check_perms(path=self.temp_file.name,
|
||||
ret = win_file.check_perms(path=self.temp_file,
|
||||
inheritance=True)
|
||||
self.assertDictEqual(expected, ret)
|
||||
|
||||
@ -268,11 +263,11 @@ class WinFileCheckPermsTestCase(TestCase, LoaderModuleMockMixin):
|
||||
Test resetting perms with test=True. This shows minimal changes
|
||||
'''
|
||||
# Turn off inheritance
|
||||
salt.utils.win_dacl.set_inheritance(obj_name=self.temp_file.name,
|
||||
salt.utils.win_dacl.set_inheritance(obj_name=self.temp_file,
|
||||
enabled=False,
|
||||
clear=True)
|
||||
# Set some permissions
|
||||
salt.utils.win_dacl.set_permissions(obj_name=self.temp_file.name,
|
||||
salt.utils.win_dacl.set_permissions(obj_name=self.temp_file,
|
||||
principal='Administrator',
|
||||
permissions='full_control')
|
||||
expected = {'comment': '',
|
||||
@ -284,11 +279,11 @@ class WinFileCheckPermsTestCase(TestCase, LoaderModuleMockMixin):
|
||||
'Administrator': {
|
||||
'grant': {'applies to': 'Not Inherited (file)',
|
||||
'permissions': 'Full control'}}}},
|
||||
'name': self.temp_file.name,
|
||||
'name': self.temp_file,
|
||||
'result': None}
|
||||
with patch.dict(win_dacl.__opts__, {'test': True}):
|
||||
ret = win_file.check_perms(
|
||||
path=self.temp_file.name,
|
||||
path=self.temp_file,
|
||||
grant_perms={'Users': {'perms': 'read_execute'},
|
||||
'Administrators': {'perms': 'full_control'}},
|
||||
inheritance=False,
|
||||
@ -300,11 +295,11 @@ class WinFileCheckPermsTestCase(TestCase, LoaderModuleMockMixin):
|
||||
Test resetting perms on a File
|
||||
'''
|
||||
# Turn off inheritance
|
||||
salt.utils.win_dacl.set_inheritance(obj_name=self.temp_file.name,
|
||||
salt.utils.win_dacl.set_inheritance(obj_name=self.temp_file,
|
||||
enabled=False,
|
||||
clear=True)
|
||||
# Set some permissions
|
||||
salt.utils.win_dacl.set_permissions(obj_name=self.temp_file.name,
|
||||
salt.utils.win_dacl.set_permissions(obj_name=self.temp_file,
|
||||
principal='Administrator',
|
||||
permissions='full_control')
|
||||
expected = {'comment': '',
|
||||
@ -316,10 +311,10 @@ class WinFileCheckPermsTestCase(TestCase, LoaderModuleMockMixin):
|
||||
'Administrator': {
|
||||
'grant': {'applies to': 'Not Inherited (file)',
|
||||
'permissions': 'Full control'}}}},
|
||||
'name': self.temp_file.name,
|
||||
'name': self.temp_file,
|
||||
'result': True}
|
||||
ret = win_file.check_perms(
|
||||
path=self.temp_file.name,
|
||||
path=self.temp_file,
|
||||
grant_perms={'Users': {'perms': 'read_execute'},
|
||||
'Administrators': {'perms': 'full_control'}},
|
||||
inheritance=False,
|
||||
|
Loading…
Reference in New Issue
Block a user