Unit tests and some fixes for improved plugin settings processing

(cherry picked from commit bcd0f34)
This commit is contained in:
Gina Häußge committed 2015-10-26 08:53:08 +01:00
1 parent 063251fe03
commit b4cb0dec87
3 files changed
+323 -6

No files matched your search

+8 -5
View File
@@ -784,7 +784,7 @@ class SettingsPlugin(OctoPrintPlugin):
:return: the current settings of the plugin, as a dictionary
"""
data = self._settings.get([], asdict=True, merged=True)
data = self._settings.get_all_data()
if self.config_version_key in data:
del data[self.config_version_key]
return data
@@ -815,6 +815,8 @@ class SettingsPlugin(OctoPrintPlugin):
# get the current data
current = self._settings.get_all_data()
if current is None:
current = dict()
# merge our new data on top of it
new_current = octoprint.util.dict_merge(current, data)
@@ -830,7 +832,11 @@ class SettingsPlugin(OctoPrintPlugin):
to_persist = dict(diff)
if version:
to_persist[self.config_version_key] = version
self._settings.set([], to_persist)
if to_persist:
self._settings.set([], to_persist)
else:
self._settings.clean_all_data()
return diff
@@ -958,9 +964,6 @@ class SettingsPlugin(OctoPrintPlugin):
# diff => persist only that
self._settings.set([], diff)
# finally save everything
self._settings.save()
def on_settings_initialized(self):
"""
Called after the settings have been initialized and - if necessary - also been migrated through a call to
+2 -1
View File
@@ -225,9 +225,10 @@ class Server():
if stored_version is None or stored_version < settings_version:
settings_migrator(settings_version, stored_version)
implementation._settings.set_int([octoprint.plugin.SettingsPlugin.config_version_key], settings_version)
implementation._settings.save()
implementation.on_settings_cleanup()
implementation._settings.save()
implementation.on_settings_initialized()
pluginManager.implementation_inject_factories=[octoprint_plugin_inject_factory, settings_plugin_inject_factory]