|
5 | 5 | import pytest |
6 | 6 | from mergin.merginproject import MerginProject |
7 | 7 | from mergin.common import DeltaChangeType, PullActionType, ClientError |
8 | | -from mergin.models import ProjectDeltaItem, ProjectDeltaItemDiff, ProjectDeltaItemDiff, PullAction |
| 8 | +from mergin.models import ProjectDeltaItem, ProjectDeltaItemDiff |
| 9 | +from mergin.client_pull import PullAction |
9 | 10 | from mergin.utils import edit_conflict_file_name |
10 | 11 |
|
11 | 12 | TEST_DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "test_data") |
@@ -171,40 +172,47 @@ def test_get_pull_delta(): |
171 | 172 | assert len(diff_item.diffs) == 2 |
172 | 173 |
|
173 | 174 |
|
174 | | -def test_get_local_delta_mocked(): |
| 175 | +def test_get_local_delta(): |
175 | 176 | """Test get_local_delta with mocked compare_file_sets.""" |
176 | 177 | with tempfile.TemporaryDirectory() as tmp_dir: |
177 | 178 | test_project = "delta_test_project" |
178 | 179 | project_dir = os.path.join(tmp_dir, test_project) |
179 | 180 | os.makedirs(project_dir, exist_ok=True) |
180 | | - shutil.copyfile(os.path.join(TEST_DATA_DIR, "inseAted_1_A.gpkg"), os.path.join(project_dir, "base. |
| 181 | + shutil.copyfile(os.path.join(TEST_DATA_DIR, "inserted_1_A.gpkg"), os.path.join(project_dir, "base.gpkg")) |
181 | 182 | mp = MerginProject(project_dir) |
182 | | - shutil.copyfile(os.path.join(TEST_DATA_DIR, "base.gpkg"), os.path.join(project_dir, ".mergin", "base.gpkg"))gp ) |
| 183 | + shutil.copyfile(os.path.join(TEST_DATA_DIR, "base.gpkg"), os.path.join(project_dir, ".mergin", "base.gpkg")) |
| 184 | + |
| 185 | + # Mock compare_file_sets return value |
| 186 | + mock_changes = { |
| 187 | + "added": [{"path": "new.txt", "size": 10, "checksum": "c1"}], |
| 188 | + "removed": [{"path": "deleted.txt", "size": 20, "checksum": "c2"}], |
| 189 | + "updated": [ |
| 190 | + {"path": "updated.txt", "size": 30, "checksum": "c3"}, |
| 191 | + {"path": "base.gpkg", "size": 40, "checksum": "c4"}, |
| 192 | + ], |
| 193 | + } |
| 194 | + mp.compare_file_sets = lambda local, server: mock_changes |
183 | 195 |
|
184 | | - # Mock compare_file_sets return ue |
185 | | - mock_chang "added": [{"path": "new.txt", "size": 10, "checksum": " "removed": [{"path": "deleted.txt", "size": 20, "checksum": " "updat {"path": "updated.txt", "size": 30, "checksum": {"path": "base.gpkg", "size": 40, "checksum": ], } |
186 | | - mp.compare_file_sets = lambda local, server: mock_c |
187 | 196 | # Mock files() to return origin info for version lookup |
188 | 197 | mp.files = lambda: [] |
189 | 198 |
|
190 | | - mp.inspect_files = lambda: [] # Dummy returnf |
191 | | - w |
| 199 | + mp.inspect_files = lambda: [] # Dummy return |
192 | 200 |
|
193 | | - delta_items = mp.get_local_delta(projec r) |
194 | | - assert len(delta_items) 4 |
| 201 | + delta_items = mp.get_local_delta(project_dir) |
| 202 | + assert len(delta_items) == 4 |
195 | 203 |
|
196 | | - # Verify ms |
197 | | - create_item = next(i for i in delta_items if i.path == "new ") |
198 | | - assert create_item.change == DeltaChangeType.C E |
| 204 | + # Verify items |
| 205 | + create_item = next(i for i in delta_items if i.path == "new.txt") |
| 206 | + assert create_item.change == DeltaChangeType.CREATE |
199 | 207 |
|
200 | | - delete_item = next(i for i in delta_items if i.path == "deleted ") |
201 | | - assert delete_item.change == DeltaChangeType.D E |
| 208 | + delete_item = next(i for i in delta_items if i.path == "deleted.txt") |
| 209 | + assert delete_item.change == DeltaChangeType.DELETE |
202 | 210 |
|
203 | | - update_item = next(i for i in delta_items if i.path == "updated ") |
204 | | - assert update_item.change == DeltaChangeType.U E |
| 211 | + update_item = next(i for i in delta_items if i.path == "updated.txt") |
| 212 | + assert update_item.change == DeltaChangeType.UPDATE |
205 | 213 |
|
206 | | - update_diff_item = next(i for i in delta_items if i.path == "base. ") |
207 | | - assert update_diff_item.change == DeltaChangeType.UPDA |
| 214 | + update_diff_item = next(i for i in delta_items if i.path == "base.gpkg") |
| 215 | + assert update_diff_item.change == DeltaChangeType.UPDATE_DIFF |
208 | 216 |
|
209 | 217 |
|
210 | 218 | def test_apply_pull_actions_apply_diff(): |
@@ -445,4 +453,3 @@ def username(self): |
445 | 453 | assert not mp.geodiff.has_changes(os.path.join(tmp_dir, "live-server.diff")) |
446 | 454 | assert not mp.geodiff.has_changes(os.path.join(tmp_dir, "live-base.diff")) |
447 | 455 | assert mp.geodiff.has_changes(os.path.join(tmp_dir, "live-conflict.diff")) |
448 | | -E_DIFF |
|
0 commit comments