Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions mergin/local_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ def __post_init__(self):
total_changes = len(upload_changes)
oversize_changes = []
for change in upload_changes:
if not is_versioned_file(change.path) and change.size > MAX_UPLOAD_MEDIA_SIZE:
oversize_changes.append(change)
elif not change.diff and change.size > MAX_UPLOAD_VERSIONED_SIZE:
if is_versioned_file(change.path):
if not change.diff and change.size > MAX_UPLOAD_VERSIONED_SIZE:
oversize_changes.append(change)
elif change.size > MAX_UPLOAD_MEDIA_SIZE:
oversize_changes.append(change)
if oversize_changes:
error = ChangesValidationError("Some files exceed the maximum upload size", oversize_changes)
Expand Down
40 changes: 39 additions & 1 deletion mergin/test/test_local_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def test_local_changes_post_init_validation_media():
assert err.value.invalid_changes[0].size == LARGE_FILE_SIZE


def test_local_changes_post_init_validation_gpgkg():
def test_local_changes_post_init_validation_gpkg():
"""Test the get_gpgk_upload_file method of LocalProjectChanges."""
# Define constants
SIZE_LIMIT_MB = 10
Expand Down Expand Up @@ -186,6 +186,44 @@ def test_local_changes_post_init_validation_gpgkg():
assert err.value.invalid_changes[0].size == LARGE_FILE_SIZE


def test_local_changes_post_init_validation_both_limits():
"""
Validate media and versioned size limits.
"""
VERSIONED_LIMIT = 5 * 1024 * 1024 # 5 MB
MEDIA_LIMIT = 10 * 1024 * 1024 # 10 MB
BETWEEN_SIZE = 7 * 1024 * 1024
OVER_MEDIA_SIZE = 15 * 1024 * 1024
OVER_VERSIONED_SIZE = 8 * 1024 * 1024

added = [
# media file between the limits: valid, must NOT be flagged
FileChange(path="between.jpg", checksum="a1", size=BETWEEN_SIZE, mtime=datetime.now()),
# media file over the media limit: flagged
FileChange(path="big.jpg", checksum="a2", size=OVER_MEDIA_SIZE, mtime=datetime.now()),
]
updated = [
# versioned full upload over the versioned limit: flagged
FileChange(path="big.gpkg", checksum="b1", size=OVER_VERSIONED_SIZE, mtime=datetime.now(), diff=None),
# versioned upload over the versioned limit but sent as a diff: valid
FileChange(
path="diffed.gpkg",
checksum="b2",
size=OVER_VERSIONED_SIZE,
mtime=datetime.now(),
diff={"path": "diffed-diff.gpkg", "checksum": "d1", "size": 1024, "mtime": datetime.now()},
),
]

with patch("mergin.local_changes.MAX_UPLOAD_MEDIA_SIZE", MEDIA_LIMIT):
with patch("mergin.local_changes.MAX_UPLOAD_VERSIONED_SIZE", VERSIONED_LIMIT):
with pytest.raises(ChangesValidationError) as err:
LocalProjectChanges(added=added, updated=updated)

flagged = {c.path for c in err.value.invalid_changes}
assert flagged == {"big.jpg", "big.gpkg"}


def test_local_changes_post_init():
"""Test the __post_init__ method of LocalProjectChanges."""
# Define constants
Expand Down
Loading