Skip to content

Commit

Permalink
Build a small bundle for collections that have the startup flag (#1481)
Browse files Browse the repository at this point in the history
  • Loading branch information
leplatrem authored Jul 18, 2024
1 parent 48a4e4a commit af5f8f7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
12 changes: 12 additions & 0 deletions commands/build_bundles.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,18 @@ def build_bundles(event, context):
)
bundles_to_upload.append("changesets.zip")

# Build a bundle for collections that are marked with "startup" flag.
write_zip(
"startup.zip",
[
("{bucket}--{metadata[id]}.json".format(**changeset), json.dumps(changeset))
for changeset in all_changesets
if "startup" in changeset["metadata"].get("flags", [])
],
)
bundles_to_upload.append("startup.zip")

# Build attachments bundle for collections which have the option set.
for changeset in all_changesets:
bid = changeset["bucket"]
cid = changeset["metadata"]["id"]
Expand Down
26 changes: 22 additions & 4 deletions tests/test_build_bundles.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,24 +197,40 @@ def test_build_bundles(mock_fetch_all_changesets, mock_write_zip, mock_sync_clou
"metadata": {"id": "collection4", "attachment": {"bundle": True}},
"timestamp": 1720004688000 + 10,
},
{ # collection with startup flag
"bucket": "bucket5",
"changes": [{"id": "record5"}],
"metadata": {"id": "collection5", "flags": ["startup"]},
"timestamp": 1720004688000 + 10,
},
]

build_bundles(event, context={})

assert mock_write_zip.call_count == 2 # One for changesets and only one for the attachments
assert (
mock_write_zip.call_count == 3
) # changesets.zip, startup.zip, and only one for the attachments
calls = mock_write_zip.call_args_list

# Assert the first call (changesets.zip)
changesets_zip_path, changesets_zip_files = calls[0][0]
assert changesets_zip_path == "changesets.zip"
assert len(changesets_zip_files) == 5
assert len(changesets_zip_files) == 6
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 the second call (startup.zip)
startup_zip_path, startup_zip_files = calls[1][0]
assert startup_zip_path == "startup.zip"
assert len(startup_zip_files) == 1
assert startup_zip_files[0][0] == "bucket5--collection5.json"

# Assert the second call (attachments zip)
attachments_zip_path, attachments_zip_files = calls[1][0]
# Assert the third call (attachments zip)
attachments_zip_path, attachments_zip_files = calls[2][0]
assert attachments_zip_path == "bucket1--collection1.zip"
assert len(attachments_zip_files) == 2
assert attachments_zip_files[0][0] == "record1.meta.json"
Expand All @@ -226,11 +242,13 @@ def test_build_bundles(mock_fetch_all_changesets, mock_write_zip, mock_sync_clou
"bundles",
[
"changesets.zip",
"startup.zip",
"bucket1--collection1.zip",
],
[
"bucket2--collection2.zip",
"bucket3--collection3.zip",
"bucket5--collection5.zip",
],
)

Expand Down

0 comments on commit af5f8f7

Please sign in to comment.