Skip to content

Commit 8c1b42d

Browse files
committed
use versions/paginated endpoint to retrieve detailed version information
(fix #167)
1 parent 21bd876 commit 8c1b42d

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

mergin/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ def show_version(ctx, version):
493493
project_path = mp.metadata["name"]
494494
# TODO: handle exception when version not found
495495
version_info_dict = mc.project_version_info(project_path, version)[0]
496-
click.secho("Project: " + version_info_dict["project"]["namespace"] + "/" + version_info_dict["project"]["name"])
496+
click.secho("Project: " + version_info_dict["namespace"] + "/" + version_info_dict["project_name"])
497497
click.secho("Version: " + version_info_dict["name"] + " by " + version_info_dict["author"])
498498
click.secho("Time: " + version_info_dict["created"])
499499
pretty_diff(version_info_dict["changes"])

mergin/client.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,8 +831,14 @@ def project_status(self, directory):
831831
def project_version_info(self, project_path, version):
832832
"""Returns JSON with detailed information about a single project version"""
833833
params = {"version_id": version}
834-
resp = self.get("/v1/project/version/{}".format(project_path), params)
835-
return json.load(resp)
834+
params = {
835+
"page": version,
836+
"per_page": 1,
837+
"descending": False
838+
}
839+
resp = self.get(f"/v1/project/versions/paginated/{project_path}", params)
840+
j = json.load(resp)
841+
return j["versions"]
836842

837843
def project_file_history_info(self, project_path, file_path):
838844
"""Returns JSON with full history of a single file within a project"""

mergin/test/test_client.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import tempfile
55
import subprocess
66
import shutil
7-
from datetime import datetime, timedelta
7+
from datetime import datetime, timedelta, date
88
import pytest
99
import pytz
1010
import sqlite3
@@ -1860,3 +1860,33 @@ def test_changesets_download(mc):
18601860
assert os.path.exists(diff_file)
18611861
assert mp.geodiff.has_changes(diff_file)
18621862
assert mp.geodiff.changes_count(diff_file) == 3
1863+
1864+
def test_version_info(mc):
1865+
"""Check retrieving detailed information about single project version.
1866+
"""
1867+
test_project = "test_version_info"
1868+
project = API_USER + "/" + test_project
1869+
project_dir = os.path.join(TMP_DIR, test_project) # primary project dir
1870+
test_gpkg = "test.gpkg"
1871+
file_path = os.path.join(project_dir, "test.gpkg")
1872+
1873+
cleanup(mc, project, [project_dir])
1874+
1875+
os.makedirs(project_dir, exist_ok=True)
1876+
shutil.copy(os.path.join(TEST_DATA_DIR, "base.gpkg"), file_path)
1877+
mc.create_project_and_push(test_project, project_dir)
1878+
1879+
shutil.copy(os.path.join(TEST_DATA_DIR, "inserted_1_A.gpkg"), file_path)
1880+
mc.push_project(project_dir)
1881+
1882+
shutil.copy(os.path.join(TEST_DATA_DIR, "inserted_1_A_mod.gpkg"), file_path)
1883+
mc.push_project(project_dir)
1884+
1885+
info = mc.project_version_info(project, 2)[0]
1886+
assert info["namespace"] == API_USER
1887+
assert info["project_name"] == test_project
1888+
assert info["name"] == "v2"
1889+
assert info["author"] == API_USER
1890+
created = datetime.strptime(info["created"], "%Y-%m-%dT%H:%M:%SZ")
1891+
assert created.date() == date.today()
1892+
assert info["changes"]["updated"][0]["size"] == 98304

0 commit comments

Comments
 (0)