|
4 | 4 | import os |
5 | 5 | import pytest |
6 | 6 | import shutil |
| 7 | +from sqlalchemy import tuple_ |
7 | 8 | from sqlalchemy.orm.attributes import flag_modified |
8 | 9 |
|
9 | 10 | from ..app import db |
|
15 | 16 | Project, |
16 | 17 | GeodiffActionHistory, |
17 | 18 | ) |
| 19 | +from ..sync.utils import Checkpoint |
18 | 20 | from . import test_project_dir, TMP_DIR |
19 | 21 | from .utils import ( |
20 | 22 | create_project, |
@@ -250,11 +252,46 @@ def test_version_file_restore(diff_project): |
250 | 252 | test_file = os.path.join(diff_project.storage.project_dir, "v30", "test.gpkg") |
251 | 253 | os.rename(test_file, test_file + "_backup") |
252 | 254 | diff_project.storage.restore_versioned_file("test.gpkg", 30) |
| 255 | + checkpoints = Checkpoint.get_checkpoints(9, 30) |
253 | 256 | assert os.path.exists(test_file) |
254 | 257 | assert gpkgs_are_equal(test_file, test_file + "_backup") |
255 | | - assert ( |
256 | | - FileDiff.query.filter_by(file_path_id=file_path_id) |
257 | | - .filter(FileDiff.rank > 0) |
258 | | - .count() |
259 | | - > 0 |
| 258 | + assert FileDiff.query.filter_by(file_path_id=file_path_id).filter( |
| 259 | + tuple_(FileDiff.rank, FileDiff.version).in_( |
| 260 | + [(item.rank, item.end) for item in checkpoints] |
| 261 | + ) |
| 262 | + ).count() == len(checkpoints) |
| 263 | + |
| 264 | + # let's create new project with basefile at v1 (which can be start of multiple checkpoints) |
| 265 | + working_dir = os.path.join(TMP_DIR, "restore_from_diffs") |
| 266 | + basefile = os.path.join(working_dir, "base.gpkg") |
| 267 | + project = _prepare_restore_project(working_dir) |
| 268 | + file_path_id = ( |
| 269 | + ProjectFilePath.query.filter_by(project_id=project.id, path="base.gpkg") |
| 270 | + .first() |
| 271 | + .id |
260 | 272 | ) |
| 273 | + |
| 274 | + for i in range(17): |
| 275 | + sql = "INSERT INTO simple (geometry, name) VALUES (GeomFromText('POINT(24.5, 38.2)', 4326), 'insert_test')" |
| 276 | + execute_query(basefile, sql) |
| 277 | + pv_latest = push_change(project, "updated", "base.gpkg", working_dir) |
| 278 | + assert project.latest_version == pv_latest.name |
| 279 | + assert os.path.exists( |
| 280 | + os.path.join( |
| 281 | + project.storage.project_dir, |
| 282 | + ProjectVersion.to_v_name(pv_latest.name), |
| 283 | + "base.gpkg", |
| 284 | + ) |
| 285 | + ) |
| 286 | + |
| 287 | + test_file = os.path.join(project.storage.project_dir, "v17", "base.gpkg") |
| 288 | + os.rename(test_file, test_file + "_backup") |
| 289 | + project.storage.restore_versioned_file("base.gpkg", 17) |
| 290 | + checkpoints = Checkpoint.get_checkpoints(1, 17) |
| 291 | + assert os.path.exists(test_file) |
| 292 | + assert gpkgs_are_equal(test_file, test_file + "_backup") |
| 293 | + assert FileDiff.query.filter_by(file_path_id=file_path_id).filter( |
| 294 | + tuple_(FileDiff.rank, FileDiff.version).in_( |
| 295 | + [(item.rank, item.end) for item in checkpoints] |
| 296 | + ) |
| 297 | + ).count() == len(checkpoints) |
0 commit comments