From 30ab43cb7f87a541d0cda1c08ad179d6470004b5 Mon Sep 17 00:00:00 2001 From: Alexander Bruy Date: Tue, 10 Oct 2023 16:04:23 +0300 Subject: [PATCH] allow querying project information by project ID (fix #179) --- mergin/client.py | 8 ++++++-- mergin/test/test_client.py | 7 +++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/mergin/client.py b/mergin/client.py index 3070008..c6e5126 100644 --- a/mergin/client.py +++ b/mergin/client.py @@ -623,7 +623,7 @@ def projects_list( break return projects - def project_info(self, project_path, since=None, version=None): + def project_info(self, project_path_or_id, since=None, version=None): """ Fetch info about project. @@ -639,7 +639,11 @@ def project_info(self, project_path, since=None, version=None): # since and version are mutually exclusive if version: params = {"version": version} - resp = self.get("/v1/project/{}".format(project_path), params) + + if re.match("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}", project_path_or_id): + resp = self.get("/v1/project/by_uuid/{}".format(project_path_or_id), params) + else: + resp = self.get("/v1/project/{}".format(project_path_or_id), params) return json.load(resp) def project_versions(self, project_path, since=None, to=None): diff --git a/mergin/test/test_client.py b/mergin/test/test_client.py index 8f3d485..891ab17 100644 --- a/mergin/test/test_client.py +++ b/mergin/test/test_client.py @@ -150,6 +150,13 @@ def test_create_remote_project_from_local(mc): assert project_info["namespace"] == API_USER assert project_info["id"] == source_mp.project_id() + # check project metadata retrieval by id + project_info = mc.project_info(source_mp.project_id()) + assert project_info["version"] == "v1" + assert project_info["name"] == test_project + assert project_info["namespace"] == API_USER + assert project_info["id"] == source_mp.project_id() + versions = mc.project_versions(project) assert len(versions) == 1 assert versions[0]["name"] == "v1"