Skip to content

Commit 92d5340

Browse files
committed
Merge remote-tracking branch 'origin/push-v2-integration' into changes_limits
2 parents cf232a6 + 7dbed14 commit 92d5340

File tree

3 files changed

+24
-22
lines changed

3 files changed

+24
-22
lines changed

mergin/client_push.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import time
2323
from typing import List, Tuple, Optional, ByteString
2424

25-
from .local_changes import ChangesValidationError, FileChange, LocalPojectChanges
25+
from .local_changes import ChangesValidationError, FileChange, LocalProjectChanges
2626

2727
from .common import (
2828
MAX_UPLOAD_VERSIONED_SIZE,
@@ -140,10 +140,10 @@ class UploadJob:
140140
"""Keeps all the important data about a pending upload job"""
141141

142142
def __init__(
143-
self, version: str, changes: LocalPojectChanges, transaction_id: Optional[str], mp: MerginProject, mc, tmp_dir
143+
self, version: str, changes: LocalProjectChanges, transaction_id: Optional[str], mp: MerginProject, mc, tmp_dir
144144
):
145145
self.version = version
146-
self.changes: LocalPojectChanges = changes # dictionary of local changes to the project
146+
self.changes: LocalProjectChanges = changes # dictionary of local changes to the project
147147
self.transaction_id = transaction_id # ID of the transaction assigned by the server
148148
self.total_size = 0 # size of data to upload (in bytes)
149149
self.transferred_size = 0 # size of data already uploaded (in bytes)
@@ -186,7 +186,7 @@ def update_chunks_from_items(self):
186186
Update chunks in LocalProjectChanges from the upload queue items.
187187
Used just before finalizing the transaction to set the server_chunk_id in v2 API.
188188
"""
189-
self.changes.update_chunks([(item.chunk_id, item.server_chunk_id) for item in self.upload_queue_items])
189+
self.changes.update_chunk_ids([(item.chunk_id, item.server_chunk_id) for item in self.upload_queue_items])
190190

191191

192192
def _do_upload(item: UploadQueueItem, job: UploadJob):
@@ -231,7 +231,7 @@ def create_upload_chunks(mc, mp: MerginProject, local_changes: List[FileChange])
231231

232232

233233
def create_upload_job(
234-
mc, mp: MerginProject, changes: LocalPojectChanges, tmp_dir: tempfile.TemporaryDirectory
234+
mc, mp: MerginProject, changes: LocalProjectChanges, tmp_dir: tempfile.TemporaryDirectory
235235
) -> Optional[UploadJob]:
236236
"""
237237
Prepare transaction and create an upload job for the project using the v1 API.
@@ -479,7 +479,7 @@ def remove_diff_files(job: UploadJob) -> None:
479479
os.remove(diff_file)
480480

481481

482-
def get_push_changes_batch(mc, mp: MerginProject) -> Tuple[LocalPojectChanges, int]:
482+
def get_push_changes_batch(mc, mp: MerginProject) -> Tuple[LocalProjectChanges, int]:
483483
"""
484484
Get changes that need to be pushed to the server.
485485
"""
@@ -488,7 +488,7 @@ def get_push_changes_batch(mc, mp: MerginProject) -> Tuple[LocalPojectChanges, i
488488
changes = filter_changes(mc, project_role, changes)
489489

490490
try:
491-
local_changes = LocalPojectChanges(
491+
local_changes = LocalProjectChanges(
492492
added=[FileChange(**change) for change in changes["added"]],
493493
updated=[FileChange(**change) for change in changes["updated"]],
494494
removed=[FileChange(**change) for change in changes["removed"]],

mergin/local_changes.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class FileChange:
4141
chunks: List[str] = field(default_factory=list)
4242
# optional diff information for geopackage files with geodiff metadata
4343
diff: Optional[dict] = None
44+
# File path to be used for reading a file by creating and uploading file in chunks
4445
upload_file: Optional[str] = None
4546
# some functions (MerginProject.compare_file_sets) are adding version to the change from project info
4647
version: Optional[str] = None
@@ -59,6 +60,7 @@ def get_diff(self) -> Optional[FileDiffChange]:
5960
)
6061

6162
def to_server_data(self) -> dict:
63+
"""Convert the FileChange instance to a dictionary format suitable for server payload."""
6264
result = {
6365
"path": self.path,
6466
"checksum": self.checksum,
@@ -75,7 +77,7 @@ def to_server_data(self) -> dict:
7577

7678

7779
@dataclass
78-
class LocalPojectChanges:
80+
class LocalProjectChanges:
7981
added: List[FileChange] = field(default_factory=list)
8082
updated: List[FileChange] = field(default_factory=list)
8183
removed: List[FileChange] = field(default_factory=list)
@@ -132,7 +134,7 @@ def _map_unique_chunks(self, change_chunks: List[str], server_chunks: List[Tuple
132134
seen.add(server_chunk_id)
133135
return mapped
134136

135-
def update_chunks(self, server_chunks: List[Tuple[str, str]]) -> None:
137+
def update_chunk_ids(self, server_chunks: List[Tuple[str, str]]) -> None:
136138
"""
137139
Map chunk ids to chunks returned from server (server_chunk_id).
138140

mergin/test/test_local_changes.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
import pytest
33
from unittest.mock import patch
44

5-
from ..local_changes import ChangesValidationError, FileChange, LocalPojectChanges, MAX_UPLOAD_CHANGES
5+
from ..local_changes import ChangesValidationError, FileChange, LocalProjectChanges, MAX_UPLOAD_CHANGES
66

77

88
def test_local_changes_from_dict():
9-
"""Test generating LocalChanges from a dictionary."""
9+
"""Test generating LocalProjectChanges from a dictionary."""
1010
changes_dict = {
1111
"added": [{"path": "file1.txt", "checksum": "abc123", "size": 1024, "mtime": datetime.now()}],
1212
"updated": [{"path": "file2.txt", "checksum": "xyz789", "size": 2048, "mtime": datetime.now()}],
@@ -37,7 +37,7 @@ def test_local_changes_from_dict():
3737
updated = [FileChange(**file) for file in changes_dict["updated"]]
3838
removed = [FileChange(**file) for file in changes_dict["removed"]]
3939

40-
local_changes = LocalPojectChanges(added=added, updated=updated, removed=removed)
40+
local_changes = LocalProjectChanges(added=added, updated=updated, removed=removed)
4141

4242
# Assertions
4343
assert len(local_changes.added) == 1
@@ -74,7 +74,7 @@ def test_local_changes_to_server_payload():
7474
updated = [FileChange(path="file2.txt", checksum="xyz789", size=2048, mtime=datetime.now())]
7575
removed = [FileChange(path="file3.txt", checksum="lmn456", size=512, mtime=datetime.now())]
7676

77-
local_changes = LocalPojectChanges(added=added, updated=updated, removed=removed)
77+
local_changes = LocalProjectChanges(added=added, updated=updated, removed=removed)
7878
server_request = local_changes.to_server_payload()
7979

8080
assert "added" in server_request
@@ -85,33 +85,33 @@ def test_local_changes_to_server_payload():
8585
assert server_request["removed"][0]["path"] == "file3.txt"
8686

8787

88-
def test_local_changes_update_chunks():
88+
def test_local_changes_update_chunk_ids():
8989
"""Test the update_chunks method of LocalChanges."""
9090
added = [
9191
FileChange(path="file1.txt", checksum="abc123", size=1024, mtime=datetime.now(), chunks=["abc123"]),
9292
FileChange(path="file2.txt", checksum="abc123", size=1024, mtime=datetime.now(), chunks=["abc123"]),
9393
]
9494
updated = [FileChange(path="file2.txt", checksum="xyz789", size=2048, mtime=datetime.now(), chunks=["xyz789"])]
9595

96-
local_changes = LocalPojectChanges(added=added, updated=updated)
96+
local_changes = LocalProjectChanges(added=added, updated=updated)
9797
chunks = [("abc123", "chunk1"), ("abc123", "chunk1"), ("xyz789", "chunk2")]
9898

99-
local_changes.update_chunks(chunks)
99+
local_changes.update_chunk_ids(chunks)
100100

101101
assert local_changes.added[0].chunks == ["chunk1"]
102102
assert local_changes.added[1].chunks == ["chunk1"]
103103
assert local_changes.updated[0].chunks == ["chunk2"]
104104

105105

106106
def test_local_changes_get_upload_changes():
107-
"""Test the get_upload_changes method of LocalChanges."""
107+
"""Test the get_upload_changes method of LocalProjectChanges."""
108108
# Create sample LocalChange instances
109109
added = [FileChange(path="file1.txt", checksum="abc123", size=1024, mtime=datetime.now())]
110110
updated = [FileChange(path="file2.txt", checksum="xyz789", size=2048, mtime=datetime.now())]
111111
removed = [FileChange(path="file3.txt", checksum="lmn456", size=512, mtime=datetime.now())]
112112

113113
# Initialize LocalChanges with added, updated, and removed changes
114-
local_changes = LocalPojectChanges(added=added, updated=updated, removed=removed)
114+
local_changes = LocalProjectChanges(added=added, updated=updated, removed=removed)
115115

116116
# Call get_upload_changes
117117
upload_changes = local_changes.get_upload_changes()
@@ -143,7 +143,7 @@ def test_local_changes_post_init_validation_media():
143143
# Initialize LocalProjectChanges
144144
with patch("mergin.local_changes.MAX_UPLOAD_MEDIA_SIZE", SIZE_LIMIT_BYTES):
145145
with pytest.raises(ChangesValidationError, match="Some files exceed") as err:
146-
LocalPojectChanges(added=added, updated=updated)
146+
LocalProjectChanges(added=added, updated=updated)
147147
print(err.value.invalid_changes)
148148
assert len(err.value.invalid_changes) == 1
149149
assert "file2.jpg" == err.value.invalid_changes[0].path
@@ -179,14 +179,14 @@ def test_local_changes_post_init_validation_gpgkg():
179179
# Initialize LocalProjectChanges
180180
with patch("mergin.local_changes.MAX_UPLOAD_VERSIONED_SIZE", SIZE_LIMIT_BYTES):
181181
with pytest.raises(ChangesValidationError) as err:
182-
LocalPojectChanges(added=added, updated=updated)
182+
LocalProjectChanges(added=added, updated=updated)
183183
assert len(err.value.invalid_changes) == 1
184184
assert "file2.gpkg" == err.value.invalid_changes[0].path
185185
assert err.value.invalid_changes[0].size == LARGE_FILE_SIZE
186186

187187

188188
def test_local_changes_post_init():
189-
"""Test the __post_init__ method of LocalChanges."""
189+
"""Test the __post_init__ method of LocalProjectChanges."""
190190
# Define constants
191191
ADDED_COUNT = 80
192192
UPDATED_COUNT = 21
@@ -204,7 +204,7 @@ def test_local_changes_post_init():
204204
]
205205

206206
# Initialize LocalProjectChanges
207-
local_changes = LocalPojectChanges(added=added, updated=updated)
207+
local_changes = LocalProjectChanges(added=added, updated=updated)
208208

209209
# Assertions
210210
assert len(local_changes.added) == ADDED_COUNT # All added changes are included

0 commit comments

Comments
 (0)