Skip to content

Commit

Permalink
first pass at adding support for JSON Patch test operations.
Browse files Browse the repository at this point in the history
  • Loading branch information
jake authored and jake committed Feb 2, 2024
1 parent 6e23216 commit 942cfd6
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion internetarchive/iarequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,24 @@ def prepare_patch(metadata, source_metadata, append, append_list=None, insert=No
# Delete metadata items where value is REMOVE_TAG.
destination_metadata = delete_items_from_dict(destination_metadata, 'REMOVE_TAG')
patch = make_patch(source_metadata, destination_metadata).patch
return patch

# Add test operations to patch.
patch_tests = []
for p in patch:
patch_parts = p['path'].split('/')
if not source_metadata.get(patch_parts[1]):
continue
if len(patch_parts) == 2:
src_val = source_metadata.get(patch_parts[-1])
else:
index = int(patch_parts[-1]) - 1
src_val = source_metadata.get(patch_parts[1], [])[index]
p_test = {'op': 'test', 'path': p['path'], 'value': src_val}
patch_tests.append(p_test)
final_patch = patch_tests + patch
print(f"final patch being submitted to archive.org: {final_patch}")

return final_patch


def prepare_target_patch(metadata, source_metadata, append, target, append_list, key,
Expand Down

0 comments on commit 942cfd6

Please sign in to comment.