Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions mergin/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,10 @@ def create_project_and_push(self, project_name, directory, is_public=False, name
namespace = self.username()
self.create_project(project_name, is_public, namespace)
if directory:
mp = MerginProject(directory)
full_project_name = "{}/{}".format(namespace, project_name)
mp.metadata = {"name": full_project_name, "version": "v0", "files": []}
project_info = self.project_info(full_project_name)
mp = MerginProject(directory)
mp.metadata = {"name": full_project_name, "version": "v0", "files": [], "project_id": project_info["id"]}
if mp.inspect_files():
self.push_project(directory)

Expand Down
8 changes: 7 additions & 1 deletion mergin/client_pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,12 @@ def download_project_finalize(job):

# final update of project metadata
# TODO: why not exact copy of project info JSON ?
job.mp.metadata = {"name": job.project_path, "version": job.version, "files": job.project_info["files"]}
job.mp.metadata = {
"name": job.project_path,
"version": job.version,
"project_id": job.project_info["id"],
"files": job.project_info["files"],
}


def download_project_cancel(job):
Expand Down Expand Up @@ -610,6 +615,7 @@ def pull_project_finalize(job):
job.mp.metadata = {
"name": job.project_path,
"version": job.version if job.version else "v0", # for new projects server version is ""
"project_id": job.project_info["id"],
"files": job.project_info["files"],
}

Expand Down
1 change: 1 addition & 0 deletions mergin/client_push.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ def push_project_finalize(job):
job.mp.metadata = {
"name": job.project_path,
"version": job.server_resp["version"],
"project_id": job.server_resp["id"],
"files": job.server_resp["files"],
}
try:
Expand Down
8 changes: 7 additions & 1 deletion mergin/test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,13 @@ def test_create_remote_project_from_local(mc):

# create remote project
mc.create_project_and_push(test_project, directory=project_dir)

source_mp = MerginProject(project_dir)
# check basic metadata about created project
project_info = mc.project_info(project)
assert project_info["version"] == "v1"
assert project_info["name"] == test_project
assert project_info["namespace"] == API_USER
assert project_info["id"] == source_mp.metadata["project_id"]

versions = mc.project_versions(project)
assert len(versions) == 1
Expand Down Expand Up @@ -191,6 +192,7 @@ def test_push_pull_changes(mc):
f_remote_checksum = next((f["checksum"] for f in project_info["files"] if f["path"] == f_updated), None)
assert generate_checksum(os.path.join(project_dir, f_updated)) == f_remote_checksum
mp = MerginProject(project_dir)
assert project_info["id"] == mp.metadata["project_id"]
assert len(project_info["files"]) == len(mp.inspect_files())
project_versions = mc.project_versions(project)
assert len(project_versions) == 2
Expand Down Expand Up @@ -330,6 +332,7 @@ def test_sync_diff(mc):
# check project after push
project_info = mc.project_info(project)
assert project_info["version"] == "v3"
assert project_info["id"] == mp.metadata["project_id"]
f_remote = next((f for f in project_info["files"] if f["path"] == f_updated), None)
assert next((f for f in project_info["files"] if f["path"] == "renamed.gpkg"), None)
assert not next((f for f in project_info["files"] if f["path"] == f_removed), None)
Expand Down Expand Up @@ -863,6 +866,7 @@ def test_get_versions_with_file_changes(mc):

project_info = mc.project_info(project)
assert project_info["version"] == "v4"
assert project_info["id"] == mp.metadata["project_id"]
file_history = mc.project_file_history_info(project, f_updated)

with pytest.raises(ClientError) as e:
Expand Down Expand Up @@ -897,6 +901,7 @@ def test_download_file(mc):

project_info = mc.project_info(project)
assert project_info["version"] == "v5"
assert project_info["id"] == mp.metadata["project_id"]

# Versioned file should have the following content at versions 2-4
expected_content = ("inserted_1_A.gpkg", "inserted_1_A_mod.gpkg", "inserted_1_B.gpkg")
Expand Down Expand Up @@ -926,6 +931,7 @@ def test_download_diffs(mc):

project_info = mc.project_info(project)
assert project_info["version"] == "v4"
assert project_info["id"] == mp.metadata["project_id"]

# Download diffs of updated file between versions 1 and 2
mc.get_file_diff(project_dir, f_updated, diff_file, "v1", "v2")
Expand Down