X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/%7B%7Bdeck_id%7D%7D/cards/%7B%7Bcard_id%7D%7D/static/git-logo.png?a=blobdiff_plain;f=tests%2Fprocesses.py;h=0f43a4dc5685ba79b690b3d4ae6d1a09955283d6;hb=25b71c6f0b10db05907128daf50c6e543e514c35;hp=930e56032191feb047f4662f96a0d8d68a2dfe48;hpb=0952d4a17e7df265cf0c50b66df1e1391075b821;p=plomtask diff --git a/tests/processes.py b/tests/processes.py index 930e560..0f43a4d 100644 --- a/tests/processes.py +++ b/tests/processes.py @@ -58,15 +58,14 @@ class TestsWithDB(TestCaseWithDB): def test_Process_conditions_saving(self) -> None: """Test .save/.save_core.""" p, set1, set2, set3 = self.p_of_conditions() - p.uncache() r = Process.by_id(self.db_conn, p.id_) self.assertEqual(sorted(r.conditions), sorted(set1)) self.assertEqual(sorted(r.enables), sorted(set2)) self.assertEqual(sorted(r.disables), sorted(set3)) - def test_Process_from_table_row(self) -> None: + def test_from_table_row(self) -> None: """Test .from_table_row() properly reads in class from DB""" - self.check_from_table_row() + super().test_from_table_row() self.check_versioned_from_table_row('title', str) self.check_versioned_from_table_row('description', str) self.check_versioned_from_table_row('effort', float) @@ -75,7 +74,6 @@ class TestsWithDB(TestCaseWithDB): assert isinstance(p.id_, int) for row in self.db_conn.row_where(self.checked_class.table_name, 'id', p.id_): - # pylint: disable=no-member r = Process.from_table_row(self.db_conn, row) self.assertEqual(sorted(r.conditions), sorted(set1)) self.assertEqual(sorted(r.enables), sorted(set2)) @@ -84,6 +82,7 @@ class TestsWithDB(TestCaseWithDB): def test_Process_steps(self) -> None: """Test addition, nesting, and non-recursion of ProcessSteps""" # pylint: disable=too-many-locals + # pylint: disable=too-many-statements p1, p2, p3 = self.three_processes() assert isinstance(p1.id_, int) assert isinstance(p2.id_, int) @@ -94,13 +93,13 @@ class TestsWithDB(TestCaseWithDB): steps_p1 += [s_p2_to_p1] p1.set_steps(self.db_conn, steps_p1) p1_dict: dict[int, ProcessStepsNode] = {} - p1_dict[1] = ProcessStepsNode(p2, None, True, {}, False) + p1_dict[1] = ProcessStepsNode(p2, None, True, {}) self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict) # add step of process p3 as second (top-level) step to p1 s_p3_to_p1 = ProcessStep(None, p1.id_, p3.id_, None) steps_p1 += [s_p3_to_p1] p1.set_steps(self.db_conn, steps_p1) - p1_dict[2] = ProcessStepsNode(p3, None, True, {}, False) + p1_dict[2] = ProcessStepsNode(p3, None, True, {}) self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict) # add step of process p3 as first (top-level) step to p2, steps_p2: list[ProcessStep] = [] @@ -108,30 +107,31 @@ class TestsWithDB(TestCaseWithDB): steps_p2 += [s_p3_to_p2] p2.set_steps(self.db_conn, steps_p2) # expect it as implicit sub-step of p1's second (p3) step - p2_dict = {3: ProcessStepsNode(p3, None, False, {}, False)} + p2_dict = {3: ProcessStepsNode(p3, None, False, {})} p1_dict[1].steps[3] = p2_dict[3] self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict) # add step of process p2 as explicit sub-step to p1's second sub-step s_p2_to_p1_first = ProcessStep(None, p1.id_, p2.id_, s_p3_to_p1.id_) steps_p1 += [s_p2_to_p1_first] p1.set_steps(self.db_conn, steps_p1) - seen_3 = ProcessStepsNode(p3, None, False, {}, True) + seen_3 = ProcessStepsNode(p3, None, False, {}, False) + p1_dict[1].steps[3].seen = True p1_dict[2].steps[4] = ProcessStepsNode(p2, s_p3_to_p1.id_, True, - {3: seen_3}, False) + {3: seen_3}) self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict) # add step of process p3 as explicit sub-step to non-existing p1 # sub-step (of id=999), expect it to become another p1 top-level step s_p3_to_p1_999 = ProcessStep(None, p1.id_, p3.id_, 999) steps_p1 += [s_p3_to_p1_999] p1.set_steps(self.db_conn, steps_p1) - p1_dict[5] = ProcessStepsNode(p3, None, True, {}, False) + p1_dict[5] = ProcessStepsNode(p3, None, True, {}) self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict) # add step of process p3 as explicit sub-step to p1's implicit p3 # sub-step, expect it to become another p1 top-level step s_p3_to_p1_impl_p3 = ProcessStep(None, p1.id_, p3.id_, s_p3_to_p2.id_) steps_p1 += [s_p3_to_p1_impl_p3] p1.set_steps(self.db_conn, steps_p1) - p1_dict[6] = ProcessStepsNode(p3, None, True, {}, False) + p1_dict[6] = ProcessStepsNode(p3, None, True, {}) self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict) self.assertEqual(p1.used_as_step_by(self.db_conn), []) self.assertEqual(p2.used_as_step_by(self.db_conn), [p1]) @@ -140,7 +140,7 @@ class TestsWithDB(TestCaseWithDB): # # expect it to eliminate implicit p3 sub-step # s_p3_to_p1_first_explicit = ProcessStep(None, p1.id_, p3.id_, # s_p2_to_p1.id_) - # p1_dict[1].steps = {7: ProcessStepsNode(p3, 1, True, {}, False)} + # p1_dict[1].steps = {7: ProcessStepsNode(p3, 1, True, {})} # p1_dict[2].steps[4].steps[3].seen = False # steps_p1 += [s_p3_to_p1_first_explicit] # p1.set_steps(self.db_conn, steps_p1) @@ -149,11 +149,18 @@ class TestsWithDB(TestCaseWithDB): s_p3_to_p2_first = ProcessStep(None, p2.id_, p3.id_, s_p3_to_p2.id_) steps_p2 += [s_p3_to_p2_first] p2.set_steps(self.db_conn, steps_p2) - p1_dict[1].steps[3].steps[7] = ProcessStepsNode(p3, 3, False, {}, - False) + p1_dict[1].steps[3].steps[7] = ProcessStepsNode(p3, 3, False, {}, True) p1_dict[2].steps[4].steps[3].steps[7] = ProcessStepsNode(p3, 3, False, - {}, True) + {}, False) self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict) + # ensure suppressed step nodes are hidden + assert isinstance(s_p3_to_p2.id_, int) + p1.set_step_suppressions(self.db_conn, [s_p3_to_p2.id_]) + p1_dict[1].steps[3].steps = {} + p1_dict[1].steps[3].is_suppressed = True + p1_dict[2].steps[4].steps[3].steps = {} + p1_dict[2].steps[4].steps[3].is_suppressed = True + self.assertEqual(p1.get_steps(self.db_conn), p1_dict) def test_Process_conditions(self) -> None: """Test setting Process.conditions/enables/disables.""" @@ -175,18 +182,6 @@ class TestsWithDB(TestCaseWithDB): method(self.db_conn, [c1.id_, c2.id_]) self.assertEqual(getattr(p, target), [c1, c2]) - def test_Process_by_id(self) -> None: - """Test .by_id(), including creation""" - self.check_by_id() - - def test_Process_all(self) -> None: - """Test .all().""" - self.check_all() - - def test_Process_singularity(self) -> None: - """Test pointers made for single object keep pointing to it.""" - self.check_singularity('conditions', [Condition(None)]) - def test_Process_versioned_attributes_singularity(self) -> None: """Test behavior of VersionedAttributes on saving (with .title).""" self.check_versioned_singularity() @@ -200,17 +195,19 @@ class TestsWithDB(TestCaseWithDB): assert isinstance(p3.id_, int) step = ProcessStep(None, p2.id_, p1.id_, None) p2.set_steps(self.db_conn, [step]) + step_id = step.id_ with self.assertRaises(HandledException): p1.remove(self.db_conn) p2.set_steps(self.db_conn, []) with self.assertRaises(NotFoundException): - ProcessStep.by_id(self.db_conn, step.id_) + ProcessStep.by_id(self.db_conn, step_id) p1.remove(self.db_conn) step = ProcessStep(None, p2.id_, p3.id_, None) + step_id = step.id_ p2.set_steps(self.db_conn, [step]) p2.remove(self.db_conn) with self.assertRaises(NotFoundException): - ProcessStep.by_id(self.db_conn, step.id_) + ProcessStep.by_id(self.db_conn, step_id) todo = Todo(None, p3, False, '2024-01-01') todo.save(self.db_conn) with self.assertRaises(HandledException): @@ -225,13 +222,16 @@ class TestsWithDBForProcessStep(TestCaseWithDB): default_init_kwargs = {'owner_id': 2, 'step_process_id': 3, 'parent_step_id': 4} - def test_ProcessStep_from_table_row(self) -> None: - """Test .from_table_row() properly reads in class from DB""" - self.check_from_table_row(2, 3, None) + def setUp(self) -> None: + super().setUp() + p = Process(1) + p.save(self.db_conn) + p = Process(2) + p.save(self.db_conn) - def test_ProcessStep_singularity(self) -> None: - """Test pointers made for single object keep pointing to it.""" - self.check_singularity('parent_step_id', 1, 2, 3, None) + def test_saving_and_caching(self) -> None: + """Test storage and initialization of instances and attributes.""" + self.check_saving_and_caching(id_=1, **self.default_init_kwargs) def test_ProcessStep_remove(self) -> None: """Test .remove and unsetting of owner's .explicit_steps entry.""" @@ -245,7 +245,7 @@ class TestsWithDBForProcessStep(TestCaseWithDB): p1.set_steps(self.db_conn, [step]) step.remove(self.db_conn) self.assertEqual(p1.explicit_steps, []) - self.check_storage([]) + self.check_identity_with_cache_and_db([]) class TestsWithServer(TestCaseWithServer): @@ -267,7 +267,8 @@ class TestsWithServer(TestCaseWithServer): form_data = {'title': 'foo', 'description': 'foo', 'effort': 1.0} self.post_process(2, form_data | {'condition': []}) self.check_post(form_data | {'condition': [1]}, '/process?id=', 404) - self.check_post({'title': 'foo', 'description': 'foo'}, + self.check_post({'title': 'foo', 'description': 'foo', + 'is_active': False}, '/condition', 302, '/condition?id=1') self.post_process(3, form_data | {'condition': [1]}) self.post_process(4, form_data | {'disables': [1]}) @@ -289,6 +290,7 @@ class TestsWithServer(TestCaseWithServer): retrieved_process = Process.by_id(self.db_conn, 1) self.assertEqual(len(retrieved_process.explicit_steps), 1) retrieved_step = retrieved_process.explicit_steps[0] + retrieved_step_id = retrieved_step.id_ self.assertEqual(retrieved_step.step_process_id, 2) self.assertEqual(retrieved_step.owner_id, 1) self.assertEqual(retrieved_step.parent_step_id, None) @@ -299,7 +301,7 @@ class TestsWithServer(TestCaseWithServer): retrieved_process = Process.by_id(self.db_conn, 1) self.assertEqual(retrieved_process.explicit_steps, []) with self.assertRaises(NotFoundException): - ProcessStep.by_id(self.db_conn, retrieved_step.id_) + ProcessStep.by_id(self.db_conn, retrieved_step_id) # post new first (top_level) step of process 3 to process 1 form_data_1['new_top_step'] = [3] self.post_process(1, form_data_1) @@ -316,14 +318,14 @@ class TestsWithServer(TestCaseWithServer): self.assertEqual(retrieved_process.explicit_steps, []) # post to process empty steps list but keep, expect 400 form_data_1['steps'] = [] - form_data_1['keep_step'] = [retrieved_step.id_] + form_data_1['keep_step'] = [retrieved_step_id] self.check_post(form_data_1, '/process?id=1', 400, '/process?id=1') # post to process steps list with keep on non-created step, expect 400 - form_data_1['steps'] = [retrieved_step.id_] - form_data_1['keep_step'] = [retrieved_step.id_] + form_data_1['steps'] = [retrieved_step_id] + form_data_1['keep_step'] = [retrieved_step_id] self.check_post(form_data_1, '/process?id=1', 400, '/process?id=1') # post to process steps list with keep and process ID, expect 200 - form_data_1[f'step_{retrieved_step.id_}_process_id'] = [2] + form_data_1[f'step_{retrieved_step_id}_process_id'] = [2] self.post_process(1, form_data_1) retrieved_process = Process.by_id(self.db_conn, 1) self.assertEqual(len(retrieved_process.explicit_steps), 1) @@ -331,10 +333,8 @@ class TestsWithServer(TestCaseWithServer): self.assertEqual(retrieved_step.step_process_id, 2) self.assertEqual(retrieved_step.owner_id, 1) self.assertEqual(retrieved_step.parent_step_id, None) - # post nonsensical new_top_step id and otherwise zero'd steps, expect - # 400 and preservation of previous state - form_data_1['new_top_step'] = ['foo'] - form_data_1['steps'] = [] + # post nonsense, expect 400 and preservation of previous state + form_data_1['steps'] = ['foo'] form_data_1['keep_step'] = [] self.check_post(form_data_1, '/process?id=1', 400, '/process?id=1') retrieved_process = Process.by_id(self.db_conn, 1) @@ -351,11 +351,11 @@ class TestsWithServer(TestCaseWithServer): retrieved_process = Process.by_id(self.db_conn, 1) self.assertEqual(len(retrieved_process.explicit_steps), 2) retrieved_step_0 = retrieved_process.explicit_steps[0] - self.assertEqual(retrieved_step_0.step_process_id, 2) + self.assertEqual(retrieved_step_0.step_process_id, 3) self.assertEqual(retrieved_step_0.owner_id, 1) self.assertEqual(retrieved_step_0.parent_step_id, None) retrieved_step_1 = retrieved_process.explicit_steps[1] - self.assertEqual(retrieved_step_1.step_process_id, 3) + self.assertEqual(retrieved_step_1.step_process_id, 2) self.assertEqual(retrieved_step_1.owner_id, 1) self.assertEqual(retrieved_step_1.parent_step_id, None) # post to process steps list with keeps etc., but trigger recursion @@ -376,9 +376,9 @@ class TestsWithServer(TestCaseWithServer): self.assertEqual(retrieved_step_1.step_process_id, 3) self.assertEqual(retrieved_step_1.owner_id, 1) self.assertEqual(retrieved_step_1.parent_step_id, None) - form_data_1[f'step_{retrieved_step_1.id_}_process_id'] = [3] # post sub-step to step - form_data_1[f'new_step_to_{retrieved_step_1.id_}'] = [3] + form_data_1[f'step_{retrieved_step_0.id_}_process_id'] = [3] + form_data_1[f'new_step_to_{retrieved_step_0.id_}'] = [3] self.post_process(1, form_data_1) retrieved_process = Process.by_id(self.db_conn, 1) self.assertEqual(len(retrieved_process.explicit_steps), 3)