home · contact · privacy
Slightly improve and re-organize Condition tests.
[plomtask] / tests / utils.py
index b115793341bac427e1df1ec71ce4412c353e4f95..665436873c27af704a13827715d3c795e04e1fe1 100644 (file)
@@ -345,19 +345,39 @@ class TestCaseWithServer(TestCaseWithDB):
             refs[str(item['id'])] = item
         return refs
 
+    @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
+
     @staticmethod
     def proc_as_dict(id_: int = 1,
                      title: str = 'A',
                      description: str = '',
                      effort: float = 1.0,
-                     enables: None | list[dict[str, object]] = None,
-                     disables: None | list[dict[str, object]] = None,
-                     conditions: None | list[dict[str, object]] = None,
-                     blockers: None | list[dict[str, object]] = None
+                     conditions: None | list[int] = None,
+                     disables: None | list[int] = None,
+                     blockers: None | list[int] = None,
+                     enables: None | list[int] = None
                      ) -> dict[str, object]:
         """Return JSON of Process to expect."""
         # pylint: disable=too-many-arguments
-        as_id_list = TestCaseWithServer.as_id_list
         d = {'id': id_,
              'calendarize': False,
              'suppressed_steps': [],
@@ -366,10 +386,10 @@ class TestCaseWithServer(TestCaseWithDB):
                  'title': {0: title},
                  'description': {0: description},
                  'effort': {0: effort}},
-             'conditions': as_id_list(conditions) if conditions else [],
-             'disables': as_id_list(disables) if disables else [],
-             'enables': as_id_list(enables) if enables else [],
-             'blockers': as_id_list(blockers) if blockers else []}
+             'conditions': conditions if conditions else [],
+             'disables': disables if disables else [],
+             'enables': enables if enables else [],
+             'blockers': blockers if blockers else []}
         return d
 
     def check_redirect(self, target: str) -> None: