mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Fixed several issues with the test
* Removed redundant import. * No longer inheriting from LogSettingsParserTests. * Replaced test class description with somethin meaninful. * Fixed identation. I've also moved the class to the bottom, since all the classes inheriting from LogSettingsParserTests are in the block above.
This commit is contained in:
parent
3a089e450f
commit
08fba98735
1 changed files with 42 additions and 57 deletions
|
@ -21,7 +21,6 @@ import salt.utils.parsers
|
|||
import salt.log.setup as log
|
||||
import salt.config
|
||||
import salt.syspaths
|
||||
from salt.utils.parsers import DaemonMixIn
|
||||
|
||||
ensure_in_syspath('../../')
|
||||
|
||||
|
@ -804,62 +803,6 @@ class SaltRunOptionParserTestCase(LogSettingsParserTests):
|
|||
self.parser = salt.utils.parsers.SaltRunOptionParser
|
||||
|
||||
|
||||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||
class DaemonMixInTestCase(LogSettingsParserTests):
|
||||
'''
|
||||
Tests parsing Salt Master options
|
||||
'''
|
||||
def setUp(self):
|
||||
'''
|
||||
Setting up
|
||||
'''
|
||||
# Set defaults
|
||||
self.default_config = salt.config.DEFAULT_MASTER_OPTS
|
||||
|
||||
# Log file
|
||||
self.log_file = '/tmp/salt_run_parser_test'
|
||||
# Function to patch
|
||||
self.config_func = 'salt.config.master_config'
|
||||
|
||||
# Mock log setup
|
||||
self.setup_log()
|
||||
|
||||
# Assign parser
|
||||
self.parser = salt.utils.parsers.SaltRunOptionParser
|
||||
|
||||
# Set PID
|
||||
self.pid = '/some/fake.pid'
|
||||
|
||||
# Setup mixin
|
||||
self.mixin = DaemonMixIn()
|
||||
self.mixin.info = None
|
||||
self.mixin.config = {}
|
||||
self.mixin.config['pidfile'] = self.pid
|
||||
|
||||
def test_pid_file_deletion(self):
|
||||
'''
|
||||
PIDfile deletion without exception.
|
||||
'''
|
||||
with patch('os.unlink', MagicMock()) as os_unlink:
|
||||
with patch('os.path.isfile', MagicMock(return_value=True)):
|
||||
with patch.object(self.mixin, 'info', MagicMock()):
|
||||
self.mixin._mixin_before_exit()
|
||||
assert self.mixin.info.call_count == 0
|
||||
assert os_unlink.call_count == 1
|
||||
|
||||
def test_pid_file_deletion_with_oserror(self):
|
||||
'''
|
||||
PIDfile deletion with exception
|
||||
'''
|
||||
with patch('os.unlink', MagicMock(side_effect=OSError())) as os_unlink:
|
||||
with patch('os.path.isfile', MagicMock(return_value=True)):
|
||||
with patch.object(self.mixin, 'info', MagicMock()):
|
||||
self.mixin._mixin_before_exit()
|
||||
assert os_unlink.call_count == 1
|
||||
self.mixin.info.assert_called_with(
|
||||
'PIDfile could not be deleted: {}'.format(self.pid))
|
||||
|
||||
|
||||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||
class SaltSSHOptionParserTestCase(LogSettingsParserTests):
|
||||
'''
|
||||
|
@ -983,6 +926,48 @@ class SaltAPIParserTestCase(LogSettingsParserTests):
|
|||
self.parser = salt.utils.parsers.SaltAPIParser
|
||||
|
||||
|
||||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||
class DaemonMixInTestCase(TestCase):
|
||||
'''
|
||||
Tests the PIDfile deletion in the DaemonMixIn.
|
||||
'''
|
||||
|
||||
def setUp(self):
|
||||
'''
|
||||
Setting up
|
||||
'''
|
||||
# Set PID
|
||||
self.pid = '/some/fake.pid'
|
||||
|
||||
# Setup mixin
|
||||
self.mixin = salt.utils.parsers.DaemonMixIn()
|
||||
self.mixin.info = None
|
||||
self.mixin.config = {}
|
||||
self.mixin.config['pidfile'] = self.pid
|
||||
|
||||
def test_pid_file_deletion(self):
|
||||
'''
|
||||
PIDfile deletion without exception.
|
||||
'''
|
||||
with patch('os.unlink', MagicMock()) as os_unlink:
|
||||
with patch('os.path.isfile', MagicMock(return_value=True)):
|
||||
with patch.object(self.mixin, 'info', MagicMock()):
|
||||
self.mixin._mixin_before_exit()
|
||||
assert self.mixin.info.call_count == 0
|
||||
assert os_unlink.call_count == 1
|
||||
|
||||
def test_pid_file_deletion_with_oserror(self):
|
||||
'''
|
||||
PIDfile deletion with exception
|
||||
'''
|
||||
with patch('os.unlink', MagicMock(side_effect=OSError())) as os_unlink:
|
||||
with patch('os.path.isfile', MagicMock(return_value=True)):
|
||||
with patch.object(self.mixin, 'info', MagicMock()):
|
||||
self.mixin._mixin_before_exit()
|
||||
assert os_unlink.call_count == 1
|
||||
self.mixin.info.assert_called_with(
|
||||
'PIDfile could not be deleted: {}'.format(self.pid))
|
||||
|
||||
# Hide the class from unittest framework when it searches for TestCase classes in the module
|
||||
del LogSettingsParserTests
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue