Skip to content

Commit 60effde

Browse files
authored
Merge pull request #168 from MerginMaps/fix-project_version_info
Fix project version info
2 parents 21bd876 + 91b2975 commit 60effde

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
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: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def user_agent_info(self):
163163
try:
164164
from pip._vendor import distro
165165

166-
system_version = distro.linux_distribution()[0]
166+
system_version = distro.id().capitalize()
167167
except ModuleNotFoundError: # pip may not be installed...
168168
system_version = "Linux"
169169
elif platform.system() == "Windows":
@@ -831,8 +831,10 @@ 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 = {"page": version, "per_page": 1, "descending": False}
835+
resp = self.get(f"/v1/project/versions/paginated/{project_path}", params)
836+
j = json.load(resp)
837+
return j["versions"]
836838

837839
def project_file_history_info(self, project_path, file_path):
838840
"""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+
1865+
def test_version_info(mc):
1866+
"""Check retrieving detailed information about single project version."""
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)