test(postfix): mypy

This commit is contained in:
sydneyli 2018-06-11 08:33:47 -07:00
parent 591125dcb5
commit 7d73788a3a
4 changed files with 18 additions and 11 deletions

View file

@ -59,9 +59,9 @@ class Installer(plugins_common.Installer):
self.postconf = None
# Files to save
self.save_notes = []
self.save_notes = [] # type: List[str]
self._enhance_func = {}
self._enhance_func = {} # type: Dict[str, Callable[[str, str]]]
# Since we only need to enable TLS once for all domains,
# keep track of whether this enhancement was already called.
self._tls_enabled = False

View file

@ -13,14 +13,14 @@ class ConfigMain(util.PostfixUtilBase):
# Whether to ignore overrides from master.
self._ignore_master_overrides = ignore_master_overrides
# List of all current Postfix parameters, from `postconf` command.
self._db = {}
self._db = {} # type: Dict[str, str]
# List of current master.cf overrides from Postfix config. Dictionary
# of parameter name => list of tuples (service name, paramter value)
# Note: We should never modify master without explicit permission.
self._master_db = {}
self._master_db = {} # Dict[str, List[Tuple[str, str]]]
# List of all changes requested to the Postfix parameters as they are now
# in _db. These changes are flushed to `postconf` on `flush`.
self._updated = {}
self._updated = {} # type: Dict[str, str]
self._read_from_conf()
def _read_from_conf(self):

View file

@ -158,6 +158,14 @@ class InstallerTest(certbot_test_util.ConfigTestCase):
installer.prepare)
certbot_test_util.lock_and_call(assert_raises, self.tempdir)
@mock.patch('certbot.util.lock_dir_until_exit')
def test_dir_locked(self, lock_dir):
with create_installer(self.config) as installer:
lock_dir.side_effect = errors.LockError
self.assertRaises(errors.PluginError, installer.prepare)
def test_more_info(self):
with create_installer(self.config) as installer:
installer.prepare()
@ -288,7 +296,6 @@ def create_installer(config, main_cf=DEFAULT_MAIN_CF):
from certbot_postfix import installer
def _mock_init_postconf(postconf, executable, ignore_master_overrides=False, config_dir=None):
# pylint: disable=protected-access
super(ConfigMain, postconf).__init__(executable, config_dir)
postconf._ignore_master_overrides = ignore_master_overrides
postconf._db = main_cf
postconf._master_db = {}

View file

@ -51,12 +51,12 @@ class PostfixUtilTest(unittest.TestCase):
self.mock_call.assert_called_with(['check'])
def test_test_raises_error_when_check_fails(self):
self.mock_call.side_effect = [subprocess.CalledProcessError(None, None, None)]
self.mock_call.side_effect = [subprocess.CalledProcessError(1, "")]
self.assertRaises(errors.MisconfigurationError, self.postfix.test)
self.mock_call.assert_called_with(['check'])
def test_restart_while_running(self):
self.mock_call.side_effect = [subprocess.CalledProcessError(None, None, None), None]
self.mock_call.side_effect = [subprocess.CalledProcessError(1, ""), None]
self.postfix.restart()
self.mock_call.assert_called_with(['start'])
@ -65,14 +65,14 @@ class PostfixUtilTest(unittest.TestCase):
self.mock_call.assert_called_with(['reload'])
def test_restart_raises_error_when_reload_fails(self):
self.mock_call.side_effect = [None, subprocess.CalledProcessError(None, None, None)]
self.mock_call.side_effect = [None, subprocess.CalledProcessError(1, "")]
self.assertRaises(errors.PluginError, self.postfix.restart)
self.mock_call.assert_called_with(['reload'])
def test_restart_raises_error_when_start_fails(self):
self.mock_call.side_effect = [
subprocess.CalledProcessError(None, None, None),
subprocess.CalledProcessError(None, None, None)]
subprocess.CalledProcessError(1, ""),
subprocess.CalledProcessError(1, "")]
self.assertRaises(errors.PluginError, self.postfix.restart)
self.mock_call.assert_called_with(['start'])