home · contact · privacy
Minor improvements to query parameter handling/defaulting.
authorChristian Heller <c.heller@plomlompom.de>
Fri, 9 Aug 2024 14:51:35 +0000 (16:51 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Fri, 9 Aug 2024 14:51:35 +0000 (16:51 +0200)
plomtask/http.py
tests/days.py
tests/utils.py

index ef9438adf59ce23f04281f41add6e2fcc8764635..c2e1f5deea8abbaef4208e8370595319ef69a237 100644 (file)
@@ -327,6 +327,7 @@ class TaskHandler(BaseHTTPRequestHandler):
         start = self._params.get_str_or_fail('start', '')
         end = self._params.get_str_or_fail('end', '')
         end = end if end != '' else date_in_n_days(366)
+        #
         days, start, end = Day.by_date_range_with_limits(self._conn,
                                                          (start, end), 'id')
         days = Day.with_filled_gaps(days, start, end)
@@ -344,8 +345,9 @@ class TaskHandler(BaseHTTPRequestHandler):
     def do_GET_day(self) -> dict[str, object]:
         """Show single Day of ?date=."""
         date = self._params.get_str_or_fail('date', date_in_n_days(0))
+        make_type = self._params.get_str_or_fail('make_type', 'full')
+        #
         day = Day.by_id_or_create(self._conn, date)
-        make_type = self._params.get_str_or_fail('make_type', '')
         conditions_present = []
         enablers_for = {}
         disablers_for = {}
@@ -444,11 +446,12 @@ class TaskHandler(BaseHTTPRequestHandler):
 
     def do_GET_todos(self) -> dict[str, object]:
         """Show Todos from ?start= to ?end=, of ?process=, ?comment= pattern"""
-        sort_by = self._params.get_str_or_fail('sort_by', '')
+        sort_by = self._params.get_str_or_fail('sort_by', 'title')
         start = self._params.get_str_or_fail('start', '')
         end = self._params.get_str_or_fail('end', '')
         process_id = self._params.get_int_or_none('process_id')
         comment_pattern = self._params.get_str_or_fail('comment_pattern', '')
+        #
         todos = []
         ret = Todo.by_date_range_with_limits(self._conn, (start, end))
         todos_by_date_range, start, end = ret
@@ -463,7 +466,8 @@ class TaskHandler(BaseHTTPRequestHandler):
     def do_GET_conditions(self) -> dict[str, object]:
         """Show all Conditions."""
         pattern = self._params.get_str_or_fail('pattern', '')
-        sort_by = self._params.get_str_or_fail('sort_by', '')
+        sort_by = self._params.get_str_or_fail('sort_by', 'title')
+        #
         conditions = Condition.matching(self._conn, pattern)
         sort_by = Condition.sort_by(conditions, sort_by)
         return {'conditions': conditions,
@@ -496,6 +500,7 @@ class TaskHandler(BaseHTTPRequestHandler):
         owner_ids = self._params.get_all_int('step_to')
         owned_ids = self._params.get_all_int('has_step')
         title_64 = self._params.get_str('title_b64')
+        #
         if title_64:
             try:
                 title = b64decode(title_64.encode()).decode()
@@ -536,7 +541,8 @@ class TaskHandler(BaseHTTPRequestHandler):
     def do_GET_processes(self) -> dict[str, object]:
         """Show all Processes."""
         pattern = self._params.get_str_or_fail('pattern', '')
-        sort_by = self._params.get_str_or_fail('sort_by', '')
+        sort_by = self._params.get_str_or_fail('sort_by', 'title')
+        #
         processes = Process.matching(self._conn, pattern)
         sort_by = Process.sort_by(processes, sort_by)
         return {'processes': processes, 'sort_by': sort_by, 'pattern': pattern}
@@ -592,6 +598,7 @@ class TaskHandler(BaseHTTPRequestHandler):
         comments = self._form.get_all_str('comment')
         efforts = self._form.get_all_floats_or_nones('effort')
         done_todos = self._form.get_all_int('done')
+        #
         for _ in [id_ for id_ in done_todos if id_ not in old_todos]:
             raise BadFormatException('"done" field refers to unknown Todo')
         is_done = [t_id in done_todos for t_id in old_todos]
@@ -638,6 +645,7 @@ class TaskHandler(BaseHTTPRequestHandler):
         cond_rels = [self._form.get_all_int(name) for name in
                      ['conditions', 'blockers', 'enables', 'disables']]
         effort_or_not = self._form.get_str('effort')
+        #
         if effort_or_not is not None:
             if effort_or_not == '':
                 to_update['effort'] = None
@@ -719,6 +727,7 @@ class TaskHandler(BaseHTTPRequestHandler):
         for step_id in kept_steps:
             name = f'new_step_to_{step_id}'
             new_steps_to[step_id] = self._form.get_all_int(name)
+        #
         for k, v in versioned.items():
             getattr(process, k).set(v)
         process.set_condition_relations(self._conn, *cond_rels)
@@ -784,6 +793,7 @@ class TaskHandler(BaseHTTPRequestHandler):
         title = self._form.get_str_or_fail('title')
         description = self._form.get_str_or_fail('description')
         is_active = self._form.get_bool_or_none('is_active')
+        #
         if is_active is not None:
             condition.is_active = is_active
         condition.title.set(title)
index 0c6ee72a787a4cf13aff5cb764828d923f92f5a9..aac150b91e62ac56a7ed6837172fa0b3fd16c797 100644 (file)
@@ -123,7 +123,7 @@ class ExpectedGetCalendar(Expected):
 
 class ExpectedGetDay(Expected):
     """Builder of expectations for GET /day."""
-    _default_dict = {'make_type': ''}
+    _default_dict = {'make_type': 'full'}
     _on_empty_make_temp = ('Day', 'day_as_dict')
 
     def __init__(self, date: str, *args: Any, **kwargs: Any) -> None:
@@ -163,6 +163,7 @@ class TestsWithServer(TestCaseWithServer):
     def test_basic_GET_day(self) -> None:
         """Test basic (no Processes/Conditions/Todos) GET /day basics."""
         # check illegal date parameters
+        self.check_get('/day?date=', 400)
         self.check_get('/day?date=foo', 400)
         self.check_get('/day?date=2024-02-30', 400)
         # check undefined day
index e04fba6ac84ef66dfe02eb5611d9dd115c0be848..71da9fbedd8c33faff74c081803597d0260abba2 100644 (file)
@@ -1015,9 +1015,9 @@ class TestCaseWithServer(TestCaseWithDB):
         try:
             self.assertEqual(cmp, retrieved)
         except AssertionError as e:
-            print('EXPECTED:')
-            pprint(cmp)
-            print('RETRIEVED:')
-            pprint(retrieved)
-            walk_diffs('', cmp, retrieved)
+            print('EXPECTED:')
+            pprint(cmp)
+            print('RETRIEVED:')
+            pprint(retrieved)
+            walk_diffs('', cmp, retrieved)
             raise e