X-Git-Url: https://plomlompom.com/repos/feed.xml?a=blobdiff_plain;ds=inline;f=tests%2Fprocesses.py;h=539d86f47bea49d639ff7ae377272e89059a9dcf;hb=34741b65438149b4e02f1e2bb4f8fdba5df5a667;hp=87b0b09809398ab1a5aa59af78bf1ac11d8bf1e4;hpb=b3ff25deb388919c9a205ceb1997ff3c42e93bc8;p=plomtask diff --git a/tests/processes.py b/tests/processes.py index 87b0b09..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) @@ -104,6 +94,63 @@ class TestsWithDB(TestCaseWithDB): 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().""" with self.assertRaises(NotFoundException): @@ -128,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).""" @@ -149,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."""