mirror of
https://github.com/certbot/certbot.git
synced 2026-06-03 13:59:02 -04:00
Finetuning and renaming
This commit is contained in:
parent
5ad44d6126
commit
7ac82ab5ff
3 changed files with 12 additions and 16 deletions
|
|
@ -18,7 +18,7 @@ from certbot import interfaces
|
|||
from certbot import reverter
|
||||
from certbot import util
|
||||
|
||||
from certbot.plugins.pluginstorage import PluginStorage
|
||||
from certbot.plugins.storage import PluginStorage
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
|
|
|||
|
|
@ -17,8 +17,6 @@ class PluginStorage(object):
|
|||
:param .configuration.NamespaceConfig config: Configuration object
|
||||
:param str classkey: class name to use as root key in storage file
|
||||
|
||||
:returns: Plugin storage object
|
||||
|
||||
"""
|
||||
|
||||
self._config = config
|
||||
|
|
@ -31,10 +29,9 @@ class PluginStorage(object):
|
|||
"""Initializes PluginStorage data and reads current state from the disk
|
||||
if the storage json exists."""
|
||||
|
||||
if hasattr(self._config, "config_dir") and os.path.isdir(self._config.config_dir):
|
||||
self._storagepath = os.path.join(self._config.config_dir, ".pluginstorage.json")
|
||||
self._load()
|
||||
self._initialized = True
|
||||
self._storagepath = os.path.join(self._config.config_dir, ".pluginstorage.json")
|
||||
self._load()
|
||||
self._initialized = True
|
||||
|
||||
def _load(self):
|
||||
"""Reads PluginStorage content from the disk to a dict structure
|
||||
|
|
@ -73,7 +70,7 @@ class PluginStorage(object):
|
|||
or write it to the filesystem
|
||||
"""
|
||||
if not self._initialized:
|
||||
errmsg = "Unable to save, the PluginStorage was never initialized"
|
||||
errmsg = "Unable to save, no values have been added to PluginStorage."
|
||||
logger.error(errmsg)
|
||||
raise errors.PluginStorageError(errmsg)
|
||||
|
||||
|
|
@ -1,8 +1,7 @@
|
|||
"""Tests for certbot.plugins.common.PluginStorage"""
|
||||
"""Tests for certbot.plugins.storage.PluginStorage"""
|
||||
import json
|
||||
import mock
|
||||
import os
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
from certbot import errors
|
||||
|
|
@ -11,12 +10,12 @@ from certbot.plugins import common
|
|||
from certbot.tests import util as test_util
|
||||
|
||||
class PluginStorageTest(test_util.ConfigTestCase):
|
||||
"""Test for certbot.plugins.common.PluginStorage"""
|
||||
"""Test for certbot.plugins.storage.PluginStorage"""
|
||||
|
||||
def setUp(self):
|
||||
super(PluginStorageTest, self).setUp()
|
||||
self.plugin_cls = common.Installer
|
||||
self.config.config_dir = tempfile.mkdtemp()
|
||||
os.mkdir(self.config.config_dir)
|
||||
with mock.patch("certbot.reverter.util"):
|
||||
self.plugin = self.plugin_cls(config=self.config, name="mockplugin")
|
||||
|
||||
|
|
@ -38,7 +37,7 @@ class PluginStorageTest(test_util.ConfigTestCase):
|
|||
def test_load_errors_empty(self):
|
||||
with open(os.path.join(self.config.config_dir, ".pluginstorage.json"), "w") as fh:
|
||||
fh.write('')
|
||||
with mock.patch("certbot.plugins.pluginstorage.logger.debug") as mock_log:
|
||||
with mock.patch("certbot.plugins.storage.logger.debug") as mock_log:
|
||||
# Should not error out but write a debug log line instead
|
||||
with mock.patch("certbot.reverter.util"):
|
||||
nocontent = self.plugin_cls(self.config, "mockplugin")
|
||||
|
|
@ -51,7 +50,7 @@ class PluginStorageTest(test_util.ConfigTestCase):
|
|||
with open(os.path.join(self.config.config_dir,
|
||||
".pluginstorage.json"), "w") as fh:
|
||||
fh.write('invalid json')
|
||||
with mock.patch("certbot.plugins.pluginstorage.logger.error") as mock_log:
|
||||
with mock.patch("certbot.plugins.storage.logger.error") as mock_log:
|
||||
with mock.patch("certbot.reverter.util"):
|
||||
corrupted = self.plugin_cls(self.config, "mockplugin")
|
||||
self.assertRaises(errors.PluginError,
|
||||
|
|
@ -60,7 +59,7 @@ class PluginStorageTest(test_util.ConfigTestCase):
|
|||
self.assertTrue("is corrupted" in mock_log.call_args[0][0])
|
||||
|
||||
def test_save_errors_cant_serialize(self):
|
||||
with mock.patch("certbot.plugins.pluginstorage.logger.error") as mock_log:
|
||||
with mock.patch("certbot.plugins.storage.logger.error") as mock_log:
|
||||
# Set data as something that can't be serialized
|
||||
self.plugin.storage._initialized = True # pylint: disable=protected-access
|
||||
self.plugin.storage.storagepath = "/tmp/whatever"
|
||||
|
|
@ -73,7 +72,7 @@ class PluginStorageTest(test_util.ConfigTestCase):
|
|||
mock_open = mock.mock_open()
|
||||
mock_open.side_effect = IOError
|
||||
with mock.patch("os.open", mock_open):
|
||||
with mock.patch("certbot.plugins.pluginstorage.logger.error") as mock_log:
|
||||
with mock.patch("certbot.plugins.storage.logger.error") as mock_log:
|
||||
self.plugin.storage._data = {"valid": "data"} # pylint: disable=protected-access
|
||||
self.plugin.storage._initialized = True # pylint: disable=protected-access
|
||||
self.assertRaises(errors.PluginStorageError,
|
||||
Loading…
Reference in a new issue