From d3276c5ee133286814d3fa6e24893e4b710a0d83 Mon Sep 17 00:00:00 2001 From: Mathieu Leplatre Date: Mon, 2 Dec 2024 19:20:43 +0100 Subject: [PATCH] Switch from changesets.zip to changesets.json.mzlz4 --- commands/build_bundles.py | 20 +++++++++----------- tests/test_build_bundles.py | 30 +++++++++++++----------------- 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/commands/build_bundles.py b/commands/build_bundles.py index d4f4503e..135efe28 100644 --- a/commands/build_bundles.py +++ b/commands/build_bundles.py @@ -136,7 +136,7 @@ def build_bundles(event, context): """ Main command entry point that: - fetches all collections changesets - - builds a `changesets.zip` + - builds a `changesets.json.mozlz4` - builds a `startup.json.mozlz4` - fetches attachments of all collections with bundle flag - builds `{bid}--{cid}.zip` for each of them @@ -212,23 +212,21 @@ def build_bundles(event, context): print(f"Latest server change was at {highest_timestamp}") existing_bundle_timestamp = get_modified_timestamp( - f"{base_url}{DESTINATION_FOLDER}/changesets.zip" + f"{base_url}{DESTINATION_FOLDER}/changesets.json.mozlz4" ) - print(f"'changesets.zip' was published at {existing_bundle_timestamp}") + print(f"'changesets.json.mozlz4' was published at {existing_bundle_timestamp}") if BUILD_ALL or (existing_bundle_timestamp < highest_timestamp): - write_zip( - "changesets.zip", + write_json_mozlz4( + "changesets.json.mozlz4", [ - ( - "{metadata[bucket]}--{metadata[id]}.json".format(**changeset), - json.dumps(changeset), - ) + changeset for changeset in all_changesets + if "preview" not in changeset["metadata"]["bucket"] ], ) - bundles_to_upload.append("changesets.zip") + bundles_to_upload.append("changesets.json.mozlz4") else: - print("Existing 'changesets.zip' bundle up-to-date. Nothing to do.") + print("Existing 'changesets.json.mozlz4' bundle up-to-date. Nothing to do.") # Build a bundle for collections that are marked with "startup" flag. startup_file = "startup.json.mozlz4" diff --git a/tests/test_build_bundles.py b/tests/test_build_bundles.py index aa83e176..69402a5a 100644 --- a/tests/test_build_bundles.py +++ b/tests/test_build_bundles.py @@ -156,7 +156,7 @@ def test_build_bundles( ) responses.add(responses.GET, f"{server_url}/attachments/file.jpg", body=b"jpeg_content") - for bundle in ["changesets.zip", "startup.json.mozlz4"] + [ + for bundle in ["changesets.json.mozlz4", "startup.json.mozlz4"] + [ f"bucket{i}--collection{i}.zip" for i in range(5) ]: responses.add( @@ -230,7 +230,7 @@ def test_build_bundles( build_bundles(event, context={}) - assert mock_write_zip.call_count == 2 # changesets.zip, and only one for the attachments + assert mock_write_zip.call_count == 1 # only one for the attachments calls = mock_write_zip.call_args_list # Assert the first call (attachments zip) @@ -241,23 +241,19 @@ def test_build_bundles( assert attachments_zip_files[1][0] == "record1" assert attachments_zip_files[1][1] == b"jpeg_content" - # Assert the second call (changesets.zip) - changesets_zip_path, changesets_zip_files = calls[1][0] - assert changesets_zip_path == "changesets.zip" - assert len(changesets_zip_files) == 8 - assert changesets_zip_files[0][0] == "bucket0--collection0.json" - assert changesets_zip_files[1][0] == "bucket1--collection1.json" - assert changesets_zip_files[2][0] == "bucket2--collection2.json" - assert changesets_zip_files[3][0] == "bucket3--collection3.json" - assert changesets_zip_files[4][0] == "bucket4--collection4.json" - assert changesets_zip_files[5][0] == "bucket5--collection5.json" - assert changesets_zip_files[6][0] == "preview-bucket5--collection5.json" - # Assert the mozlz4 call - assert mock_write_json_mozlz4.call_count == 1 # startup.json.mozlz + assert mock_write_json_mozlz4.call_count == 2 # changesets.json.mozlz4 and startup.json.mozlz calls = mock_write_json_mozlz4.call_args_list - startup_mozlz4_path, startup_changesets = calls[0][0] + changesets_mozlz4_path, changesets_mozlz4 = calls[0][0] + assert changesets_mozlz4_path == "changesets.json.mozlz4" + assert len(changesets_mozlz4) == 7 + assert changesets_mozlz4[0]["metadata"]["bucket"] == "bucket0" + assert changesets_mozlz4[0]["metadata"]["id"] == "collection0" + assert changesets_mozlz4[6]["metadata"]["bucket"] == "bucket6" + assert changesets_mozlz4[6]["metadata"]["id"] == "collection6" + + startup_mozlz4_path, startup_changesets = calls[1][0] assert startup_mozlz4_path == "startup.json.mozlz4" assert len(startup_changesets) == 1 assert startup_changesets[0]["metadata"]["bucket"] == "bucket5" @@ -268,7 +264,7 @@ def test_build_bundles( "bundles", [ "bucket1--collection1.zip", - "changesets.zip", + "changesets.json.mozlz4", "startup.json.mozlz4", ], [