3
0
Fork 0

fix: bugfix for bool simple settings with default value

This commit is contained in:
Lance Edgar 2025-01-06 19:29:58 -06:00
parent 49b13306c4
commit b5b88e2a7b
2 changed files with 35 additions and 0 deletions

View file

@ -1329,6 +1329,9 @@ class MasterView(View):
if name in data:
value = data[name]
elif simple.get('type') is bool:
# nb. bool false will be *missing* from data
value = False
else:
value = simple.get('default')

View file

@ -1565,6 +1565,38 @@ class TestMasterView(WebTestCase):
count = self.session.query(model.Setting).count()
self.assertEqual(count, 0)
def test_configure_gather_settings(self):
view = self.make_view()
simple_settings = [
{'name': 'wutta.app_title'},
{'name': 'wutta.foo'},
{'name': 'wutta.flag', 'type': bool, 'default': True},
{'name': 'wutta.number', 'type': int, 'default': 42},
{'name': 'wutta.value1', 'save_if_empty': True},
{'name': 'wutta.value2', 'save_if_empty': False},
{'name': 'wutta.value3', 'save_if_empty': False, 'default': 'baz'},
]
data = {
'wutta.app_title': 'Poser',
'wutta.foo': 'bar',
'wutta.number': 44,
'wutta.value1': None,
}
with patch.object(view, 'configure_get_simple_settings', return_value=simple_settings):
settings = view.configure_gather_settings(data)
self.assertEqual(len(settings), 6)
self.assertEqual(settings, [
{'name': 'wutta.app_title', 'value': 'Poser'},
{'name': 'wutta.foo', 'value': 'bar'},
{'name': 'wutta.flag', 'value': 'false'},
{'name': 'wutta.number', 'value': '44'},
{'name': 'wutta.value1', 'value': ''},
{'name': 'wutta.value3', 'value': 'baz'},
])
##############################
# row methods
##############################