Skip to content

allow querying project information by project ID (fix #179) #181

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 2 commits into from
Oct 11, 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
12 changes: 8 additions & 4 deletions mergin/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,12 +623,12 @@ 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.

:param project_path: Project's full name (<namespace>/<name>)
:type project_path: String
:param project_path_or_id: Project's full name (<namespace>/<name>) or id
:type project_path_or_id: String
:param since: Version to track history of geodiff files from
:type since: String
:param version: Project version to get details for (particularly list of files)
Expand All @@ -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):
Expand Down
7 changes: 7 additions & 0 deletions mergin/test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down