Skip to content

Fix project version info #168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 28, 2023
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
2 changes: 1 addition & 1 deletion mergin/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down
8 changes: 5 additions & 3 deletions mergin/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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"""
Expand Down
32 changes: 31 additions & 1 deletion mergin/test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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