bugfix; caught by @jdlcdl

This commit is contained in:
kdmukai
2023-09-02 08:02:05 -05:00
parent 892c3538a4
commit d810d12d64
3 changed files with 21 additions and 7 deletions
+6
View File
@@ -87,6 +87,12 @@ class Settings(Singleton):
values = value
for v in values:
if v not in [opt[0] for opt in settings_entry.selection_options]:
if settings_entry.attr_name == SettingsConstants.SETTING__PERSISTENT_SETTINGS and v == SettingsConstants.OPTION__ENABLED:
# Special case: trying to enable Persistent Settings when
# DISABLED is the only option allowed (because the SD card is not
# inserted. Explicitly set to DISABLED.
value = SettingsConstants.OPTION__DISABLED
break
raise InvalidSettingsQRData(f"""{abbreviated_name} = '{v}' is not valid""")
updated_settings[settings_entry.attr_name] = value
-7
View File
@@ -197,13 +197,6 @@ class SettingsIngestSettingsQRView(View):
# user.
self.config_name, settings_update_dict = Settings.parse_settingsqr(data)
persistent_settings = settings_update_dict.get(SettingsConstants.SETTING__PERSISTENT_SETTINGS)
if persistent_settings == SettingsConstants.OPTION__ENABLED and not MicroSD.get_instance().is_inserted:
# SettingsQR wants to enable persistent settings, but no MicroSD is inserted.
# For the sake of simplicity we just ignore that setting for now.
# TODO: Can consider a warning screen instead that gives the user some options.
del settings_update_dict[SettingsConstants.SETTING__PERSISTENT_SETTINGS]
self.settings.update(settings_update_dict)
if MicroSD.get_instance().is_inserted and self.settings.get_value(SettingsConstants.SETTING__PERSISTENT_SETTINGS) == SettingsConstants.OPTION__ENABLED:
+15
View File
@@ -1,6 +1,8 @@
import os
from typing import Callable
from mock import PropertyMock, patch
# Must import test base before the Controller
from base import FlowTest, FlowStep
@@ -116,6 +118,19 @@ class TestSettingsFlows(FlowTest):
self.mock_microsd.is_inserted = False
assert MicroSD.get_instance().is_inserted is False
# Have to jump through some hoops to completely simulate the SD card being
# removed; we need Settings to restrict Persistent Settings to only allow
# DISABLED.
with patch('seedsigner.models.settings.Settings.HOSTNAME', new_callable=PropertyMock) as mock_hostname:
# Must identify itself as SeedSigner OS to trigger the SD card removal logic
mock_hostname.return_value = Settings.SEEDSIGNER_OS
Settings.handle_microsd_state_change(MicroSD.ACTION__REMOVED)
selection_options = SettingsDefinition.get_settings_entry(SettingsConstants.SETTING__PERSISTENT_SETTINGS).selection_options
assert len(selection_options) == 1
assert selection_options[0][0] == SettingsConstants.OPTION__DISABLED
assert self.settings.get_value(SettingsConstants.SETTING__PERSISTENT_SETTINGS) == SettingsConstants.OPTION__DISABLED
_run_test(
initial_setting_state=SettingsConstants.OPTION__DISABLED,
load_settingsqr_into_decoder=load_persistent_settingsqr_into_decoder,