fix: bugfix for bool simple settings with default value
This commit is contained in:
parent
49b13306c4
commit
b5b88e2a7b
|
@ -1329,6 +1329,9 @@ class MasterView(View):
|
||||||
|
|
||||||
if name in data:
|
if name in data:
|
||||||
value = data[name]
|
value = data[name]
|
||||||
|
elif simple.get('type') is bool:
|
||||||
|
# nb. bool false will be *missing* from data
|
||||||
|
value = False
|
||||||
else:
|
else:
|
||||||
value = simple.get('default')
|
value = simple.get('default')
|
||||||
|
|
||||||
|
|
|
@ -1565,6 +1565,38 @@ class TestMasterView(WebTestCase):
|
||||||
count = self.session.query(model.Setting).count()
|
count = self.session.query(model.Setting).count()
|
||||||
self.assertEqual(count, 0)
|
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
|
# row methods
|
||||||
##############################
|
##############################
|
||||||
|
|
Loading…
Reference in a new issue