"""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)