X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=tests%2Fconditions.py;h=40d7c486fe7b05f2ed7f447e2cf58cd435546ebb;hb=8c0cbef8f467d125ba7c987b3eb1f5bef7d38120;hp=3b95de1f3fe7e89cc30a14f149983d14ad690962;hpb=e14580b4ee47363cad317e4ec1de91affe03d53a;p=plomtask diff --git a/tests/conditions.py b/tests/conditions.py index 3b95de1..40d7c48 100644 --- a/tests/conditions.py +++ b/tests/conditions.py @@ -1,7 +1,8 @@ """Test Conditions module.""" from tests.utils import TestCaseWithDB, TestCaseWithServer from plomtask.conditions import Condition -from plomtask.exceptions import NotFoundException +from plomtask.processes import Process +from plomtask.exceptions import NotFoundException, HandledException class TestsWithDB(TestCaseWithDB): @@ -36,6 +37,22 @@ class TestsWithDB(TestCaseWithDB): condition_retrieved = Condition.by_id(self.db_conn, 1) self.assertEqual(True, condition_retrieved.is_active) + def test_Condition_removal(self) -> None: + """Test removal of Condition.""" + cond = Condition(None, False) + cond.save(self.db_conn) + assert isinstance(cond.id_, int) + proc = Process(None) + proc.save(self.db_conn) + proc.set_conditions(self.db_conn, [cond.id_], 'conditions') + proc.save(self.db_conn) + with self.assertRaises(HandledException): + cond.remove(self.db_conn) + proc.set_conditions(self.db_conn, [], 'conditions') + proc.save(self.db_conn) + cond.remove(self.db_conn) + self.assertEqual(Condition.all(self.db_conn), []) + class TestsWithServer(TestCaseWithServer): """Module tests against our HTTP server/handler (and database).""" @@ -45,11 +62,15 @@ class TestsWithServer(TestCaseWithServer): form_data = {'title': 'foo', 'description': 'foo'} self.check_post(form_data, '/condition', 302, '/condition?id=1') self.assertEqual(1, len(Condition.all(self.db_conn))) + form_data['delete'] = '' + self.check_post(form_data, '/condition?id=', 404) + self.check_post(form_data, '/condition?id=2', 404) + self.check_post(form_data, '/condition?id=1', 302, '/conditions') + self.assertEqual(0, len(Condition.all(self.db_conn))) def test_do_GET(self) -> None: """Test /condition and /conditions response codes.""" - self.check_get('/condition', 200) - self.check_get('/condition?id=', 200) - self.check_get('/condition?id=0', 500) - self.check_get('/condition?id=FOO', 400) + form_data = {'title': 'foo', 'description': 'foo'} + self.check_post(form_data, '/condition', 302, '/condition?id=1') + self.check_get_defaults('/condition') self.check_get('/conditions', 200)