Skip to content

Commit

Permalink
Adressed last comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentinBuira committed Dec 3, 2024
1 parent 32a8514 commit f018a50
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions mergin/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,8 @@ def workspace_usage(self, workspace_id):
try:
response = self.get(f"/v1/workspace/{workspace_id}/usage")
except ClientError as e:
self.log.debug(f"Unable to query for /workspace/{workspace_id}/usage endpoint")
return
e.extra = f"Unable to query for /workspace/{workspace_id}/usage endpoint"
raise e

response = json.loads(response.read())

Expand Down Expand Up @@ -718,7 +718,7 @@ def project_info(self, project_path_or_id, since=None, version=None):
resp = self.get("/v1/project/{}".format(project_path_or_id), params)
return json.load(resp)

def project_versions_page(self, project_path, page, per_page=100, descending=False):
def paginated_project_versions(self, project_path, page, per_page=100, descending=False):
"""
Get records of project's versions (history) using calculated pagination.
wrapper around the /v1/project/versions/paginated/{} API end point
Expand Down Expand Up @@ -786,15 +786,15 @@ def project_versions(self, project_path, since=1, to=None):
start_page = math.ceil(num_since / per_page)
if not num_to:
# let's get first page and count
versions, num_to = self.project_versions_page(project_path, start_page, per_page)
versions, num_to = self.paginated_project_versions(project_path, start_page, per_page)

latest_version = int_version(versions[-1]["name"])
if latest_version < num_to:
versions += self.project_versions(project_path, f"v{latest_version+1}", f"v{num_to}")
else:
end_page = math.ceil(num_to / per_page)
for page in range(start_page, end_page + 1):
page_versions, _ = self.project_versions_page(project_path, page, per_page)
page_versions, _ = self.paginated_project_versions(project_path, page, per_page)
versions += page_versions

# filter out versions not within range
Expand Down
2 changes: 1 addition & 1 deletion mergin/test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2016,7 +2016,7 @@ def test_project_versions_list(mc):
versions_count = mc.project_versions_count(project)
assert versions_count == 5

versions, _ = mc.project_versions_page(project, page=1, descending=True)
versions, _ = mc.paginated_project_versions(project, page=1, descending=True)
assert len(versions) == 5
assert versions[0]["name"] == "v5"
assert versions[-1]["name"] == "v1"
Expand Down

0 comments on commit f018a50

Please sign in to comment.