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/gitweb.js?a=blobdiff_plain;f=tests%2Fprocesses.py;h=539d86f47bea49d639ff7ae377272e89059a9dcf;hb=34741b65438149b4e02f1e2bb4f8fdba5df5a667;hp=ac519c8fc1b1b75700a8442cfe55132b43dadda6;hpb=c6bc1fddcf12ae9523cf5b1b595638c762677c52;p=plomtask diff --git a/tests/processes.py b/tests/processes.py index ac519c8..539d86f 100644 --- a/tests/processes.py +++ b/tests/processes.py @@ -2,7 +2,8 @@ from unittest import TestCase from typing import Any from tests.utils import TestCaseWithDB, TestCaseWithServer -from plomtask.processes import Process +from plomtask.processes import Process, ProcessStep +from plomtask.conditions import Condition from plomtask.exceptions import NotFoundException, BadFormatException @@ -39,17 +40,6 @@ class TestsWithDB(TestCaseWithDB): self.assertEqual(p.id_, Process.by_id(self.db_conn, 5, create=False).id_) - def test_Process_versioned_attributes(self) -> None: - """Test behavior of VersionedAttributes on saving (with .title).""" - p = Process(None) - p.save_without_steps(self.db_conn) - p.title.set('named') - p_loaded = Process.by_id(self.db_conn, p.id_) - self.assertNotEqual(p.title.history, p_loaded.title.history) - p.save_without_steps(self.db_conn) - p_loaded = Process.by_id(self.db_conn, p.id_) - self.assertEqual(p.title.history, p_loaded.title.history) - def test_Process_steps(self) -> None: """Test addition, nesting, and non-recursion of ProcessSteps""" p_1 = Process(1) @@ -64,42 +54,102 @@ class TestsWithDB(TestCaseWithDB): p_1.add_step(self.db_conn, None, p_2.id_, None) p_1_dict: dict[int, dict[str, Any]] = {1: { 'process': p_2, 'parent_id': None, - 'is_explicit': True, 'steps': {} + 'is_explicit': True, 'steps': {}, 'seen': False }} self.assertEqual(p_1.get_steps(self.db_conn, None), p_1_dict) s_b = p_1.add_step(self.db_conn, None, p_3.id_, None) p_1_dict[2] = { 'process': p_3, 'parent_id': None, - 'is_explicit': True, 'steps': {} + 'is_explicit': True, 'steps': {}, 'seen': False } self.assertEqual(p_1.get_steps(self.db_conn, None), p_1_dict) s_c = p_2.add_step(self.db_conn, None, p_3.id_, None) assert s_c.id_ is not None p_1_dict[1]['steps'] = {3: { 'process': p_3, 'parent_id': None, - 'is_explicit': False, 'steps': {} + 'is_explicit': False, 'steps': {}, 'seen': False }} self.assertEqual(p_1.get_steps(self.db_conn, None), p_1_dict) p_1.add_step(self.db_conn, None, p_2.id_, s_b.id_) p_1_dict[2]['steps'][4] = { - 'process': p_2, 'parent_id': s_b.id_, + 'process': p_2, 'parent_id': s_b.id_, 'seen': False, 'is_explicit': True, 'steps': {3: { 'process': p_3, 'parent_id': None, - 'is_explicit': False, 'steps': {} + 'is_explicit': False, 'steps': {}, 'seen': True }}} self.assertEqual(p_1.get_steps(self.db_conn, None), p_1_dict) p_1.add_step(self.db_conn, None, p_3.id_, 999) p_1_dict[5] = { 'process': p_3, 'parent_id': None, - 'is_explicit': True, 'steps': {} + 'is_explicit': True, 'steps': {}, 'seen': False } self.assertEqual(p_1.get_steps(self.db_conn, None), p_1_dict) p_1.add_step(self.db_conn, None, p_3.id_, 3) p_1_dict[6] = { 'process': p_3, 'parent_id': None, - 'is_explicit': True, 'steps': {} + 'is_explicit': True, 'steps': {}, 'seen': False } self.assertEqual(p_1.get_steps(self.db_conn, None), p_1_dict) + self.assertEqual(p_1.used_as_step_by(self.db_conn), []) + self.assertEqual(p_2.used_as_step_by(self.db_conn), [p_1]) + self.assertEqual(p_3.used_as_step_by(self.db_conn), [p_1, p_2]) + + def test_Process_undoes(self) -> None: + """Test setting Process.undoes""" + p = Process(None) + p.set_undoes(self.db_conn, []) + p.set_undoes(self.db_conn, []) + self.assertEqual(p.undoes, []) + c1 = Condition(None, False) + c1.save(self.db_conn) + assert c1.id_ is not None + p.set_undoes(self.db_conn, [c1.id_]) + self.assertEqual(p.undoes, [c1]) + c2 = Condition(None, False) + c2.save(self.db_conn) + assert c2.id_ is not None + p.set_undoes(self.db_conn, [c2.id_]) + self.assertEqual(p.undoes, [c2]) + p.set_undoes(self.db_conn, [c1.id_, c2.id_]) + self.assertEqual(p.undoes, [c1, c2]) + + def test_Process_fulfills(self) -> None: + """Test setting Process.fulfills""" + p = Process(None) + p.set_fulfills(self.db_conn, []) + p.set_fulfills(self.db_conn, []) + self.assertEqual(p.fulfills, []) + c1 = Condition(None, False) + c1.save(self.db_conn) + assert c1.id_ is not None + p.set_fulfills(self.db_conn, [c1.id_]) + self.assertEqual(p.fulfills, [c1]) + c2 = Condition(None, False) + c2.save(self.db_conn) + assert c2.id_ is not None + p.set_fulfills(self.db_conn, [c2.id_]) + self.assertEqual(p.fulfills, [c2]) + p.set_fulfills(self.db_conn, [c1.id_, c2.id_]) + self.assertEqual(p.fulfills, [c1, c2]) + + def test_Process_conditions(self) -> None: + """Test setting Process.conditions""" + p = Process(None) + p.set_conditions(self.db_conn, []) + p.set_conditions(self.db_conn, []) + self.assertEqual(p.conditions, []) + c1 = Condition(None, False) + c1.save(self.db_conn) + assert c1.id_ is not None + p.set_conditions(self.db_conn, [c1.id_]) + self.assertEqual(p.conditions, [c1]) + c2 = Condition(None, False) + c2.save(self.db_conn) + assert c2.id_ is not None + p.set_conditions(self.db_conn, [c2.id_]) + self.assertEqual(p.conditions, [c2]) + p.set_conditions(self.db_conn, [c1.id_, c2.id_]) + self.assertEqual(p.conditions, [c1, c2]) def test_Process_by_id(self) -> None: """Test Process.by_id().""" @@ -125,6 +175,38 @@ class TestsWithDB(TestCaseWithDB): self.assertEqual({p_1.id_, p_2.id_}, set(p.id_ for p in Process.all(self.db_conn))) + def test_ProcessStep_singularity(self) -> None: + """Test pointers made for single object keep pointing to it.""" + p_1 = Process(None) + p_1.save_without_steps(self.db_conn) + p_2 = Process(None) + p_2.save_without_steps(self.db_conn) + assert p_2.id_ is not None + step = p_1.add_step(self.db_conn, None, p_2.id_, None) + assert step.id_ is not None + step_retrieved = ProcessStep.by_id(self.db_conn, step.id_) + step.parent_step_id = 99 + self.assertEqual(step.parent_step_id, step_retrieved.parent_step_id) + + def test_Process_singularity(self) -> None: + """Test pointers made for single object keep pointing to it.""" + p_1 = Process(None) + p_1.save_without_steps(self.db_conn) + p_2 = Process(None) + p_2.save_without_steps(self.db_conn) + assert p_2.id_ is not None + p_1.add_step(self.db_conn, None, p_2.id_, None) + p_retrieved = Process.by_id(self.db_conn, p_1.id_) + self.assertEqual(p_1.explicit_steps, p_retrieved.explicit_steps) + + def test_Process_versioned_attributes_singularity(self) -> None: + """Test behavior of VersionedAttributes on saving (with .title).""" + p = Process(None) + p.save_without_steps(self.db_conn) + p.title.set('named') + p_loaded = Process.by_id(self.db_conn, p.id_) + self.assertEqual(p.title.history, p_loaded.title.history) + class TestsWithServer(TestCaseWithServer): """Module tests against our HTTP server/handler (and database).""" @@ -146,6 +228,18 @@ class TestsWithServer(TestCaseWithServer): form_data = {'description': '', 'effort': 1.0} self.check_post(form_data, '/process?id=', 400) self.assertEqual(1, len(Process.all(self.db_conn))) + form_data = {'title': 'foo', 'description': 'foo', 'effort': 1.0, + 'condition': []} + self.check_post(form_data, '/process?id=', 302, '/') + form_data['condition'] = [1] + self.check_post(form_data, '/process?id=', 404) + form_data_cond = {'title': 'foo', 'description': 'foo'} + self.check_post(form_data_cond, '/condition', 302, '/') + self.check_post(form_data, '/process?id=', 302, '/') + form_data['undoes'] = [1] + self.check_post(form_data, '/process?id=', 302, '/') + form_data['fulfills'] = [1] + self.check_post(form_data, '/process?id=', 302, '/') def test_do_GET(self) -> None: """Test /process and /processes response codes."""