home · contact · privacy
Simplify JSON-ification of VersionedAttributes.
[plomtask] / tests / utils.py
index 86d049dac2387b97f441d228ecc3c33e9bfe6552..d6c5b20ac7882281d4958e99e3dbcd6a35de708b 100644 (file)
@@ -274,22 +274,23 @@ class TestCaseWithServer(TestCaseWithDB):
         """Compare JSON on GET path with expected.
 
         To simplify comparison of VersionedAttribute histories, transforms
-        keys under "history"-named dicts into bracketed integer strings
-        counting upwards in chronology.
+        timestamp keys of VersionedAttribute history keys into integers
+        counting chronologically forward from 0.
         """
         def rewrite_history_keys_in(item: Any) -> Any:
             if isinstance(item, dict):
-                if 'history' in item.keys():
-                    vals = item['history'].values()
-                    history = {}
-                    for i, val in enumerate(vals):
-                        history[f'[{i}]'] = val
-                    item['history'] = history
+                if '_versioned' in item.keys():
+                    for k in item['_versioned']:
+                        vals = item['_versioned'][k].values()
+                        history = {}
+                        for i, val in enumerate(vals):
+                            history[i] = val
+                        item['_versioned'][k] = history
                 for k in list(item.keys()):
                     rewrite_history_keys_in(item[k])
             elif isinstance(item, list):
                 item[:] = [rewrite_history_keys_in(i) for i in item]
-            return item 
+            return item
         self.conn.request('GET', path)
         response = self.conn.getresponse()
         self.assertEqual(response.status, 200)