home · contact · privacy
Extend Conditions POST test to use new JSON interface.
[plomtask] / tests / utils.py
index a9a4e80418a54f288281999b964ce8364474c177..13e4f949d177a7d73456d2546db9f49de3e33fb1 100644 (file)
@@ -217,6 +217,7 @@ class TestCaseWithServer(TestCaseWithDB):
         self.server_thread.start()
         self.conn = HTTPConnection(str(self.httpd.server_address[0]),
                                    self.httpd.server_address[1])
+        self.httpd.set_json_mode()
 
     def tearDown(self) -> None:
         self.httpd.shutdown()
@@ -267,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)