home · contact · privacy
Fix bug of /day POSTS breaking on empty new_todo fields. master
authorChristian Heller <c.heller@plomlompom.de>
Mon, 12 Aug 2024 13:24:39 +0000 (15:24 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Mon, 12 Aug 2024 13:24:39 +0000 (15:24 +0200)
plomtask/http.py
tests/days.py
tests/misc.py
tests/utils.py

index e242a3647f752ca9545f6d41752c538ace109f72..bb6e4edb9702248442da467ba3b7800e824eff1b 100644 (file)
@@ -46,11 +46,11 @@ class InputsParser:
             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
@@ -306,7 +306,7 @@ class TaskHandler(BaseHTTPRequestHandler):
                 # (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_)
index 5edec502ca5ef49ae811ac0da7d96940e98fd03b..f79284c4b8e2c4d0fcaa9855a7245b65deb2d49d 100644 (file)
@@ -240,16 +240,16 @@ class TestsWithServer(TestCaseWithServer):
         """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)
index 81591248c78b70c8b4592c10167e1061a4fb3ea5..3aa13140bc1cd2380098ea4bfe5d0fec1827b466 100644 (file)
@@ -140,15 +140,16 @@ class TestsSansServer(TestCase):
         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']})
index 75c7e50f0b32342cb1f114d572b077ed95612c26..9d5f88e6abb28ca1876188fc2d6264c6fda1cb8c 100644 (file)
@@ -679,7 +679,7 @@ class Expected:
                 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