Skip to content

Commit 9a18374

Browse files
committed
update tests for cases where geopackage is modified
1 parent 5891088 commit 9a18374

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

mergin/test/test_mergin_project.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,33 @@ def test_get_local_delta():
177177
with tempfile.TemporaryDirectory() as tmp_dir:
178178
test_project = "delta_test_project"
179179
project_dir = os.path.join(tmp_dir, test_project)
180+
# prepare mergin project with base geopackage
180181
os.makedirs(project_dir, exist_ok=True)
181-
shutil.copyfile(os.path.join(TEST_DATA_DIR, "inserted_1_A.gpkg"), os.path.join(project_dir, "base.gpkg"))
182182
mp = MerginProject(project_dir)
183183
shutil.copyfile(os.path.join(TEST_DATA_DIR, "base.gpkg"), os.path.join(project_dir, ".mergin", "base.gpkg"))
184+
# Mock files() to return origin info for version lookup
185+
mp.files = lambda: []
186+
mp.inspect_files = lambda: [] # Dummy return
187+
188+
# check if geopackage is updated (is_open) but missing - geodiff lib error, than updated file is reported
189+
mock_changes = {
190+
"updated": [
191+
{"path": "base.gpkg", "size": 40, "checksum": "c4"},
192+
],
193+
}
194+
mp.compare_file_sets = lambda origin, server: mock_changes
195+
delta_items = mp.get_local_delta(project_dir)
196+
assert len(delta_items) == 1
197+
assert delta_items[0].path == "base.gpkg"
198+
assert delta_items[0].change == DeltaChangeType.UPDATE
184199

200+
# check if geopackage is updated (is_open) but not diffable - no changes should be reported
201+
shutil.copyfile(os.path.join(TEST_DATA_DIR, "base.gpkg"), os.path.join(project_dir, "base.gpkg"))
202+
delta_items = mp.get_local_delta(project_dir)
203+
assert len(delta_items) == 0
204+
205+
# now test with real changes
206+
shutil.copyfile(os.path.join(TEST_DATA_DIR, "inserted_1_A.gpkg"), os.path.join(project_dir, "base.gpkg"))
185207
# Mock compare_file_sets return value
186208
mock_changes = {
187209
"added": [{"path": "new.txt", "size": 10, "checksum": "c1"}],
@@ -191,12 +213,7 @@ def test_get_local_delta():
191213
{"path": "base.gpkg", "size": 40, "checksum": "c4"},
192214
],
193215
}
194-
mp.compare_file_sets = lambda local, server: mock_changes
195-
196-
# Mock files() to return origin info for version lookup
197-
mp.files = lambda: []
198-
199-
mp.inspect_files = lambda: [] # Dummy return
216+
mp.compare_file_sets = lambda origin, server: mock_changes
200217

201218
delta_items = mp.get_local_delta(project_dir)
202219
assert len(delta_items) == 4

0 commit comments

Comments
 (0)