return []
return self.inputs[key]
- def get_all_int(self, key: str) -> list[int]:
+ def get_all_int(self, key: str, fail_on_empty: bool = False) -> list[int]:
"""Retrieve list of int values at key."""
all_str = self.get_all_str(key)
try:
- return [int(s) for s in all_str]
+ return [int(s) for s in all_str if fail_on_empty or s != '']
except ValueError as e:
msg = f'cannot int a form field value for key {key} in: {all_str}'
raise BadFormatException(msg) from e
# (because pylint here fails to detect the use of wrapper as a
# method to self with respective access privileges)
id_ = None
- for val in self._params.get_all_int('id'):
+ for val in self._params.get_all_int('id', fail_on_empty=True):
id_ = val
if target_class.can_create_by_id:
item = target_class.by_id_or_create(self._conn, id_)
"""Test basic (no Processes/Conditions/Todos) POST /day.
Check POST requests properly parse 'today', 'tomorrow', 'yesterday',
- and actual date strings;
- preserve 'make_type' setting in redirect even if nonsensical;
- and store 'day_comment'.
+ and actual date strings; store 'day_comment'; preserve 'make_type'
+ setting in redirect even if nonsensical; and allow '' as 'new_todo'.
"""
for name, dist, test_str in [('2024-01-01', None, 'a'),
('today', 0, 'b'),
('yesterday', -1, 'c'),
('tomorrow', +1, 'd')]:
date = name if dist is None else _testing_date_in_n_days(dist)
- post = {'day_comment': test_str, 'make_type': f'x:{test_str}'}
+ post = {'day_comment': test_str, 'make_type': f'x:{test_str}',
+ 'new_todo': ['', '']}
post_url = f'/day?date={name}'
redir_url = f'{post_url}&make_type={post["make_type"]}'
self.check_post(post, post_url, 302, redir_url)
parser = InputsParser({'foo': ['bar', 'baz']})
self.assertEqual(['bar', 'baz'], parser.get_all_str('foo'))
- def test_InputsParser_strict_get_all_int(self) -> None:
+ def test_InputsParser_get_all_int(self) -> None:
"""Test InputsParser.get_all_int."""
parser = InputsParser({})
self.assertEqual([], parser.get_all_int('foo'))
parser = InputsParser({'foo': []})
self.assertEqual([], parser.get_all_int('foo'))
parser = InputsParser({'foo': ['']})
+ parser.get_all_int('foo')
with self.assertRaises(BadFormatException):
- parser.get_all_int('foo')
+ parser.get_all_int('foo', fail_on_empty=True)
parser = InputsParser({'foo': ['0']})
self.assertEqual([0], parser.get_all_int('foo'))
parser = InputsParser({'foo': ['0', '17']})
for todo in self.lib_all('Todo'):
if next_id <= todo['id']:
next_id = todo['id'] + 1
- for proc_id in sorted(v):
+ for proc_id in sorted([id_ for id_ in v if id_]):
todo = self.todo_as_dict(next_id, proc_id, date)
self.lib_set('Todo', [todo])
next_id += 1