home · contact · privacy
Extend Conditions POST test to use new JSON interface.
[plomtask] / tests / utils.py
index 15a53ae0ddc0b78835b5baacea15f43d3a81cba0..13e4f949d177a7d73456d2546db9f49de3e33fb1 100644 (file)
@@ -268,3 +268,21 @@ class TestCaseWithServer(TestCaseWithDB):
         self.check_post(form_data, f'/process?id={id_}', 302,
                         f'/process?id={id_}')
         return form_data
+
+    @staticmethod
+    def blank_history_keys_in(d: dict[str, object]) -> None:
+        """Re-write "history" object keys to bracketed integer strings."""
+        def walk_tree(d: Any) -> Any:
+            if isinstance(d, dict):
+                if 'history' in d.keys():
+                    vals = d['history'].values()
+                    history = {}
+                    for i, val in enumerate(vals):
+                        history[f'[{i}]'] = val
+                    d['history'] = history
+                for k in list(d.keys()):
+                    walk_tree(d[k])
+            elif isinstance(d, list):
+                d[:] = [walk_tree(i) for i in d]
+            return d
+        walk_tree(d)