Skip to content

Commit

Permalink
add limit and offset to show_folder
Browse files Browse the repository at this point in the history
  • Loading branch information
bernt-matthias committed Jan 29, 2025
1 parent eeb96c5 commit 5b889cf
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 10 deletions.
21 changes: 20 additions & 1 deletion bioblend/_tests/TestGalaxyFolders.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
List,
)

from . import GalaxyTestBase
from . import (
GalaxyTestBase,
test_util,
)

FOO_DATA = "foo\nbar\n"

Expand Down Expand Up @@ -36,6 +39,22 @@ def test_show_folder_contents(self):
assert "metadata" in f2
assert self.name == f2["metadata"]["folder_name"]

@test_util.skip_unless_galaxy("release_21.05")
def test_show_folder_contents_limit(self):
subfolders = []
for i in range(12):
subfolders.append(self.gi.folders.create_folder(self.folder["id"], f"{self.name} {i}"))

# check defaults for limit and offset
f2 = self.gi.folders.show_folder(self.folder["id"], contents=True)
assert len(f2["folder_contents"]) == 10
assert f2["folder_contents"][0]["name"] == f"{self.name} 0"

# check non defaults
f2 = self.gi.folders.show_folder(self.folder["id"], contents=True, limit=1, offset=1)
assert len(f2["folder_contents"]) == 1
assert f2["folder_contents"][0]["name"] == f"{self.name} 1"

def test_delete_folder(self):
self.sub_folder = self.gi.folders.create_folder(self.folder["id"], self.name)
self.gi.folders.delete_folder(self.sub_folder["id"])
Expand Down
3 changes: 1 addition & 2 deletions bioblend/_tests/TestGalaxyHistories.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""
"""
""" """

import os
import shutil
Expand Down
3 changes: 1 addition & 2 deletions bioblend/_tests/TestGalaxyTools.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""
"""
""" """

import os
from typing import (
Expand Down
3 changes: 1 addition & 2 deletions bioblend/_tests/test_util.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
""" General support infrastructure not tied to any particular test.
"""
"""General support infrastructure not tied to any particular test."""

import os
import random
Expand Down
18 changes: 15 additions & 3 deletions bioblend/galaxy/folders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ def create_folder(self, parent_folder_id: str, name: str, description: Optional[
payload["description"] = description
return self._post(payload=payload, id=parent_folder_id)

def show_folder(self, folder_id: str, contents: bool = False) -> Dict[str, Any]:
def show_folder(
self, folder_id: str, contents: bool = False, limit: Optional[int] = 10, offset: Optional[int] = 0
) -> Dict[str, Any]:
"""
Display information about a folder.
Expand All @@ -56,11 +58,21 @@ def show_folder(self, folder_id: str, contents: bool = False) -> Dict[str, Any]:
:param contents: True to get the contents of the folder, rather
than just the folder details.
:type limit: int
:param limit: Maximum number of contents to return (default: 10).
:type offset: int
:param contents: Return contents from this specified position (default: 0).
:rtype: dict
:return: dictionary including details of the folder
"""

return self._get(id=folder_id, contents=contents)
params = {}
if limit:
params["limit"] = limit
if offset:
params["offset"] = offset
return self._get(id=folder_id, contents=contents, params=params)

def delete_folder(self, folder_id: str, undelete: bool = False) -> Dict[str, Any]:
"""
Expand Down

0 comments on commit 5b889cf

Please sign in to comment.