home · contact · privacy
Refactor request handler identifying items by ID param on GET.
[plomtask] / tests / conditions.py
index 7fdd4d44823d5b80b5a788267f82d26a8c53fa12..25a044fe88d87019334a70a9befd18c8e60818da 100644 (file)
@@ -42,27 +42,6 @@ class TestsWithDB(TestCaseWithDB):
 class TestsWithServer(TestCaseWithServer):
     """Module tests against our HTTP server/handler (and database)."""
 
-    @staticmethod
-    def cond_as_dict(id_: int = 1,
-                     is_active: bool = False,
-                     titles: None | list[str] = None,
-                     descriptions: None | list[str] = None
-                     ) -> dict[str, object]:
-        """Return JSON of Condition to expect."""
-        d = {'id': id_,
-             'is_active': is_active,
-             '_versioned': {
-                 'title': {},
-                 'description': {}}}
-        titles = titles if titles else []
-        descriptions = descriptions if descriptions else []
-        assert isinstance(d['_versioned'], dict)
-        for i, title in enumerate(titles):
-            d['_versioned']['title'][i] = title
-        for i, description in enumerate(descriptions):
-            d['_versioned']['description'][i] = description
-        return d
-
     def test_do_POST_condition(self) -> None:
         """Test POST /condition and its effect on GET /condition[s]."""
         # check empty POST fails
@@ -72,6 +51,7 @@ class TestsWithServer(TestCaseWithServer):
         self.check_post(post, '/condition', 302, '/condition?id=1')
         # … single /condition
         cond = self.cond_as_dict(titles=['foo'], descriptions=['oof'])
+        assert isinstance(cond['_versioned'], dict)
         expected_single: dict[str, object]
         expected_single = {'is_new': False,
                            'enabled_processes': [],
@@ -93,7 +73,6 @@ class TestsWithServer(TestCaseWithServer):
         # test effect of POST changing title and activeness
         post = {'title': 'bar', 'description': 'oof', 'is_active': True}
         self.check_post(post, '/condition?id=1', 302)
-        assert isinstance(cond['_versioned'], dict)
         cond['_versioned']['title'][1] = 'bar'
         cond['is_active'] = True
         self.check_json_get('/condition?id=1', expected_single)
@@ -117,14 +96,18 @@ class TestsWithServer(TestCaseWithServer):
         form_data = {'title': 'foo', 'description': 'oof', 'is_active': False}
         self.check_post(form_data, '/condition', 302, '/condition?id=1')
         proc_1_post = {'title': 'A', 'description': '', 'effort': 1.0,
-                       'condition': [1], 'disables': [1]}
+                       'conditions': [1], 'disables': [1]}
         self.post_process(1, proc_1_post)
         proc_2_post = {'title': 'B', 'description': '', 'effort': 1.0,
-                       'enables': [1], 'blocker': [1]}
+                       'enables': [1], 'blockers': [1]}
         self.post_process(2, proc_2_post)
         cond = self.cond_as_dict(titles=['foo'], descriptions=['oof'])
-        proc_1 = self.proc_as_dict(conditions=[cond], disables=[cond])
-        proc_2 = self.proc_as_dict(2, 'B', blockers=[cond], enables=[cond])
+        assert isinstance(cond['id'], int)
+        proc_1 = self.proc_as_dict(conditions=[cond['id']],
+                                   disables=[cond['id']])
+        proc_2 = self.proc_as_dict(2, 'B',
+                                   blockers=[cond['id']],
+                                   enables=[cond['id']])
         expected = {'is_new': False,
                     'enabled_processes': self.as_id_list([proc_1]),
                     'disabled_processes': self.as_id_list([proc_2]),