From: Christian Heller Date: Mon, 5 Aug 2024 05:57:34 +0000 (+0200) Subject: Minor fixes of freshly introduced bugs. X-Git-Url: https://plomlompom.com/repos/%22https:/validator.w3.org/%7B%7Bdb.prefix%7D%7D/process?a=commitdiff_plain;h=24ba8263349bff3ba7ca89016c3928d2d4751d1c;p=plomtask Minor fixes of freshly introduced bugs. --- diff --git a/plomtask/processes.py b/plomtask/processes.py index b68ffd8..56dd282 100644 --- a/plomtask/processes.py +++ b/plomtask/processes.py @@ -14,11 +14,13 @@ class ProcessStepsNode(DictableNode): """Collects what's useful to know for ProcessSteps tree display.""" # pylint: disable=too-few-public-methods step: ProcessStep + process: Process is_explicit: bool steps: list[ProcessStepsNode] seen: bool = False is_suppressed: bool = False - _to_dict = ['step', 'is_explicit', 'steps', 'seen', 'is_suppressed'] + _to_dict = ['step', 'process', 'is_explicit', 'steps', 'seen', + 'is_suppressed'] class Process(BaseModel[int], ConditionsRelations): @@ -98,8 +100,8 @@ class Process(BaseModel[int], ConditionsRelations): step_steps = [] if not suppressed: step_steps = process.get_steps(db_conn, external_owner) - return ProcessStepsNode(step, is_explicit, step_steps, False, - suppressed) + return ProcessStepsNode(step, process, is_explicit, step_steps, + False, suppressed) def walk_steps(node: ProcessStepsNode) -> None: node.seen = node.step.id_ in seen_step_ids diff --git a/plomtask/todos.py b/plomtask/todos.py index 3291107..9f9fdb4 100644 --- a/plomtask/todos.py +++ b/plomtask/todos.py @@ -94,26 +94,24 @@ class Todo(BaseModel[int], ConditionsRelations): adoptables = [t for t in Todo.by_date(db_conn, parent.date) if (t not in parent.children) and (t != parent) - and step_node.step.step_process_id == t.process.id_] + and step_node.process.id_ == t.process_id] satisfier = None for adoptable in adoptables: satisfier = adoptable break if not satisfier: - proc = Process.by_id(db_conn, step_node.step.step_process_id) - satisfier = Todo(None, proc, False, parent.date) + satisfier = Todo(None, step_node.process, False, parent.date) satisfier.save(db_conn) - sub_step_nodes = sorted(step_node.steps, - key=lambda s: s.step.step_process_id) + sub_step_nodes = sorted( + step_node.steps, + key=lambda s: s.process.id_ if s.process.id_ else 0) for sub_node in sub_step_nodes: if sub_node.is_suppressed: continue n_slots = len([n for n in sub_step_nodes - if n.step.step_process_id - == sub_node.step.step_process_id]) + if n.process == sub_node.process]) filled_slots = len([t for t in satisfier.children - if t.process.id_ - == sub_node.step.step_process_id_]) + if t.process.id_ == sub_node.process.id_]) # if we did not newly create satisfier, it may already fill # some step dependencies, so only fill what remains open if n_slots - filled_slots > 0: diff --git a/tests/processes.py b/tests/processes.py index 9affa84..6f2dc42 100644 --- a/tests/processes.py +++ b/tests/processes.py @@ -252,12 +252,15 @@ class ExpectedGetProcess(Expected): @staticmethod def stepnode_as_dict(step_id: int, + proc_id: int, seen: bool = False, steps: None | list[dict[str, object]] = None, is_explicit: bool = True, is_suppressed: bool = False) -> dict[str, object]: + # pylint: disable=too-many-arguments """Return JSON of ProcessStepNode to expect.""" return {'step': step_id, + 'process': proc_id, 'seen': seen, 'steps': steps if steps else [], 'is_explicit': is_explicit, @@ -352,7 +355,7 @@ class TestsWithServer(TestCaseWithServer): # post first (top-level) step of proc 2 to proc 1 by 'step_of' in 2 self.post_exp_process([exp], {'step_of': 1}, 2) exp.lib_set('ProcessStep', [exp.procstep_as_dict(1, 1, 2)]) - exp.set('steps', [exp.stepnode_as_dict(1)]) + exp.set('steps', [exp.stepnode_as_dict(1, 2)]) self.check_json_get(url, exp) # post empty/absent steps list to process, expect clean slate, and old # step to completely disappear @@ -364,7 +367,7 @@ class TestsWithServer(TestCaseWithServer): self.post_exp_process([exp], {'new_top_step': 2}, 1) exp.lib_set('ProcessStep', [exp.procstep_as_dict(1, 1, 2)]) self.post_exp_process([exp], {'kept_steps': [1]}, 1) - exp.set('steps', [exp.stepnode_as_dict(1)]) + exp.set('steps', [exp.stepnode_as_dict(1, 2)]) self.check_json_get(url, exp) # fail on single- and multi-step recursion p_min = {'title': '', 'description': '', 'effort': 0} @@ -381,15 +384,16 @@ class TestsWithServer(TestCaseWithServer): self.post_exp_process([exp], {'kept_steps': [1], 'new_top_step': 4}, 1) exp.lib_set('ProcessStep', [exp.procstep_as_dict(1, 1, 4), exp.procstep_as_dict(2, 1, 4)]) - exp.set('steps', [exp.stepnode_as_dict(1), exp.stepnode_as_dict(2)]) + exp.set('steps', [exp.stepnode_as_dict(1, 4), + exp.stepnode_as_dict(2, 4)]) self.check_json_get(url, exp) # post sub-step chain p = {'kept_steps': [1, 2], 'new_step_to_2': 4} self.post_exp_process([exp], p, 1) exp.lib_set('ProcessStep', [exp.procstep_as_dict(3, 1, 4, 2)]) - exp.set('steps', [exp.stepnode_as_dict(1), - exp.stepnode_as_dict(2, steps=[ - exp.stepnode_as_dict(3)])]) + exp.set('steps', [exp.stepnode_as_dict(1, 4), + exp.stepnode_as_dict(2, 4, steps=[ + exp.stepnode_as_dict(3, 4)])]) self.check_json_get(url, exp) # fail posting sub-step that would cause recursion self.post_exp_process([exp], {}, 6)