Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
harminius committed Nov 20, 2024
1 parent c824498 commit 91cb604
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion server/mergin/sync/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ def __init__(
fh.path: fh.id
for fh in FileHistory.query.filter(
FileHistory.id.in_(
self.project.latest_project_files.file_history_ids or {}
self.project.latest_project_files.file_history_ids
)
).all()
}
Expand Down
21 changes: 20 additions & 1 deletion server/mergin/tests/test_project_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
ProjectFilePath,
)
from ..sync.files import ChangesSchema
from ..sync.schemas import ProjectListSchema, ProjectSchema
from ..sync.schemas import ProjectListSchema
from ..sync.utils import generate_checksum, is_versioned_file
from ..auth.models import User, UserProfile

Expand All @@ -58,6 +58,7 @@
login,
file_info,
login_as_admin,
upload_file_to_project,
)
from ..config import Configuration
from ..sync.config import Configuration as SyncConfiguration
Expand Down Expand Up @@ -2461,3 +2462,21 @@ def test_delete_diff_file(client):
change=PushChangeType.DELETE.value,
).first()
assert fh.path == "base.gpkg" and fh.diff is None


def test_cache_files_ids(client):
"""Test caching latest project files when it is None"""
user = User.query.filter_by(username="mergin").first()
test_workspace = create_workspace()
project = create_project("no_file_history", test_workspace, user)
db.session.commit()
assert project.latest_project_files.file_history_ids is not None
project.latest_project_files.file_history_ids = None
db.session.commit()
assert project.latest_project_files.file_history_ids is None
# uploading to project caches
filename = "test.txt"
upload_file_to_project(project, filename, client)
fp = ProjectFilePath.query.filter_by(project_id=project.id, path=filename).first()
fh = FileHistory.query.filter_by(file_path_id=fp.id).first()
assert project.latest_project_files.file_history_ids == [fh.id]

0 comments on commit 91cb604

Please sign in to comment.