diff --git a/mergin/cli.py b/mergin/cli.py index 58cf31b3..ed3d578c 100755 --- a/mergin/cli.py +++ b/mergin/cli.py @@ -493,7 +493,7 @@ def show_version(ctx, version): project_path = mp.metadata["name"] # TODO: handle exception when version not found version_info_dict = mc.project_version_info(project_path, version)[0] - click.secho("Project: " + version_info_dict["project"]["namespace"] + "/" + version_info_dict["project"]["name"]) + click.secho("Project: " + version_info_dict["namespace"] + "/" + version_info_dict["project_name"]) click.secho("Version: " + version_info_dict["name"] + " by " + version_info_dict["author"]) click.secho("Time: " + version_info_dict["created"]) pretty_diff(version_info_dict["changes"]) diff --git a/mergin/client.py b/mergin/client.py index c43e13cd..8e098742 100644 --- a/mergin/client.py +++ b/mergin/client.py @@ -163,7 +163,7 @@ def user_agent_info(self): try: from pip._vendor import distro - system_version = distro.linux_distribution()[0] + system_version = distro.id().capitalize() except ModuleNotFoundError: # pip may not be installed... system_version = "Linux" elif platform.system() == "Windows": @@ -831,8 +831,10 @@ def project_status(self, directory): def project_version_info(self, project_path, version): """Returns JSON with detailed information about a single project version""" params = {"version_id": version} - resp = self.get("/v1/project/version/{}".format(project_path), params) - return json.load(resp) + params = {"page": version, "per_page": 1, "descending": False} + resp = self.get(f"/v1/project/versions/paginated/{project_path}", params) + j = json.load(resp) + return j["versions"] def project_file_history_info(self, project_path, file_path): """Returns JSON with full history of a single file within a project""" diff --git a/mergin/test/test_client.py b/mergin/test/test_client.py index bd7e5109..f6f1c329 100644 --- a/mergin/test/test_client.py +++ b/mergin/test/test_client.py @@ -4,7 +4,7 @@ import tempfile import subprocess import shutil -from datetime import datetime, timedelta +from datetime import datetime, timedelta, date import pytest import pytz import sqlite3 @@ -1860,3 +1860,33 @@ def test_changesets_download(mc): assert os.path.exists(diff_file) assert mp.geodiff.has_changes(diff_file) assert mp.geodiff.changes_count(diff_file) == 3 + + +def test_version_info(mc): + """Check retrieving detailed information about single project version.""" + test_project = "test_version_info" + project = API_USER + "/" + test_project + project_dir = os.path.join(TMP_DIR, test_project) # primary project dir + test_gpkg = "test.gpkg" + file_path = os.path.join(project_dir, "test.gpkg") + + cleanup(mc, project, [project_dir]) + + os.makedirs(project_dir, exist_ok=True) + shutil.copy(os.path.join(TEST_DATA_DIR, "base.gpkg"), file_path) + mc.create_project_and_push(test_project, project_dir) + + shutil.copy(os.path.join(TEST_DATA_DIR, "inserted_1_A.gpkg"), file_path) + mc.push_project(project_dir) + + shutil.copy(os.path.join(TEST_DATA_DIR, "inserted_1_A_mod.gpkg"), file_path) + mc.push_project(project_dir) + + info = mc.project_version_info(project, 2)[0] + assert info["namespace"] == API_USER + assert info["project_name"] == test_project + assert info["name"] == "v2" + assert info["author"] == API_USER + created = datetime.strptime(info["created"], "%Y-%m-%dT%H:%M:%SZ") + assert created.date() == date.today() + assert info["changes"]["updated"][0]["size"] == 98304