msg = f'cannot float form field value for key {key}: {val}'
raise BadFormatException(msg) from e
+ def get_bool(self, key: str) -> bool:
+ """Return if key occurs and maps to a boolean Truth."""
+ return bool(self.get_all_str(key))
+
def get_all_str(self, key: str) -> list[str]:
"""Retrieve list of string values at key."""
if key not in self.inputs.keys():
processes_to_make_full = self._form_data.get_all_int('make_full')
processes_to_make_empty = self._form_data.get_all_int('make_empty')
step_fillers = self._form_data.get_all_str('step_filler')
- d: dict[str, str | float | None] = {}
+ to_update = {
+ 'is_done': self._form_data.get_bool('done'),
+ 'calendarize': self._form_data.get_bool('calendarize'),
+ 'comment': self._form_data.get_str('comment', ignore_strict=True)}
try:
- d['effort'] = self._form_data.get_float_or_none('effort')
+ to_update['effort'] = self._form_data.get_float_or_none('effort')
except NotFoundException:
pass
cond_rel_id_lists = [self._form_data.get_all_int(name) for name in
['conditions', 'blockers', 'enables', 'disables']]
- d['is_done'] = len(self._form_data.get_all_str('done')) > 0
- d['calendarize'] = len(self._form_data.get_all_str('calendarize')) > 0
- d['comment'] = self._form_data.get_str('comment', ignore_strict=True)
for filler in [f for f in step_fillers if f != 'ignore']:
target_id: int
to_int = filler
made = Todo.create_with_children(self.conn, process_id, todo.date)
todo.add_child(made)
todo.set_condition_relations(self.conn, *cond_rel_id_lists)
- todo.update_attrs(**d)
+ todo.update_attrs(**to_update)
# todo.save() may destroy Todo if .effort < 0, so retrieve .id_ early
url = f'/todo?id={todo.id_}'
todo.save(self.conn)
blockers = self._form_data.get_all_int('blockers')
enables = self._form_data.get_all_int('enables')
disables = self._form_data.get_all_int('disables')
- calendarize = self._form_data.get_all_str('calendarize') != []
+ calendarize = self._form_data.get_bool('calendarize')
suppresses = self._form_data.get_all_int('suppresses')
step_of = self._form_data.get_all_str('step_of')
keep_steps = self._form_data.get_all_int('keep_step')
parser = InputsParser({'foo': []}, strictness)
self.assertEqual(None, parser.get_float_or_none('foo'))
+ def test_InputsParser_get_bool(self) -> None:
+ """Test InputsParser.get_all_str on strict and non-strict."""
+ for strictness in (False, True):
+ parser = InputsParser({}, strictness)
+ self.assertEqual(False, parser.get_bool('foo'))
+ parser = InputsParser({'val': ['true']}, strictness)
+ self.assertEqual(False, parser.get_bool('foo'))
+ parser = InputsParser({'val': ['True']}, strictness)
+ self.assertEqual(False, parser.get_bool('foo'))
+ parser = InputsParser({'val': ['1']}, strictness)
+ self.assertEqual(False, parser.get_bool('foo'))
+ parser = InputsParser({'val': ['foo']}, strictness)
+ self.assertEqual(False, parser.get_bool('foo'))
+ parser = InputsParser({'foo': []}, strictness)
+ self.assertEqual(False, parser.get_bool('foo'))
+ parser = InputsParser({'foo': ['None']}, strictness)
+ self.assertEqual(True, parser.get_bool('foo'))
+ parser = InputsParser({'foo': ['0']}, strictness)
+ self.assertEqual(True, parser.get_bool('foo'))
+ parser = InputsParser({'foo': ['']}, strictness)
+ self.assertEqual(True, parser.get_bool('foo'))
+ parser = InputsParser({'foo': ['bar']}, strictness)
+ self.assertEqual(True, parser.get_bool('foo'))
+ parser = InputsParser({'foo': ['bar', 'baz']}, strictness)
+ self.assertEqual(True, parser.get_bool('foo'))
+ parser = InputsParser({'foo': ['False']}, strictness)
+ self.assertEqual(True, parser.get_bool('foo'))
+
def test_InputsParser_get_all_str(self) -> None:
"""Test InputsParser.get_all_str on strict and non-strict."""
for strictness in (False, True):