Skip to content

Commit 790a7f7

Browse files
add limit and offset to show_folder
1 parent eeb96c5 commit 790a7f7

File tree

5 files changed

+38
-10
lines changed

5 files changed

+38
-10
lines changed

bioblend/_tests/TestGalaxyFolders.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
List,
44
)
55

6-
from . import GalaxyTestBase
6+
from . import (
7+
GalaxyTestBase,
8+
test_util,
9+
)
710

811
FOO_DATA = "foo\nbar\n"
912

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

42+
@test_util.skip_unless_galaxy("release_21.01")
43+
def test_show_folder_contents_limit(self):
44+
subfolders = []
45+
for i in range(12):
46+
subfolders.append(self.gi.folders.create_folder(self.folder["id"], f"{self.name} {i}"))
47+
48+
# check defaults for limit and offset
49+
f2 = self.gi.folders.show_folder(self.folder["id"], contents=True)
50+
assert len(f2["folder_contents"]) == 10
51+
assert f2["folder_contents"][0]["name"] == f"{self.name} 0"
52+
53+
# check non defaults
54+
f2 = self.gi.folders.show_folder(self.folder["id"], contents=True, limit=1, offset=1)
55+
assert len(f2["folder_contents"]) == 1
56+
assert f2["folder_contents"][0]["name"] == f"{self.name} 1"
57+
3958
def test_delete_folder(self):
4059
self.sub_folder = self.gi.folders.create_folder(self.folder["id"], self.name)
4160
self.gi.folders.delete_folder(self.sub_folder["id"])

bioblend/_tests/TestGalaxyHistories.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""
2-
"""
1+
""" """
32

43
import os
54
import shutil

bioblend/_tests/TestGalaxyTools.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""
2-
"""
1+
""" """
32

43
import os
54
from typing import (

bioblend/_tests/test_util.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
""" General support infrastructure not tied to any particular test.
2-
"""
1+
"""General support infrastructure not tied to any particular test."""
32

43
import os
54
import random

bioblend/galaxy/folders/__init__.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ def create_folder(self, parent_folder_id: str, name: str, description: Optional[
4545
payload["description"] = description
4646
return self._post(payload=payload, id=parent_folder_id)
4747

48-
def show_folder(self, folder_id: str, contents: bool = False) -> Dict[str, Any]:
48+
def show_folder(
49+
self, folder_id: str, contents: bool = False, limit: Optional[int] = 10, offset: Optional[int] = 0
50+
) -> Dict[str, Any]:
4951
"""
5052
Display information about a folder.
5153
@@ -56,11 +58,21 @@ def show_folder(self, folder_id: str, contents: bool = False) -> Dict[str, Any]:
5658
:param contents: True to get the contents of the folder, rather
5759
than just the folder details.
5860
61+
:type limit: int
62+
:param limit: Maximum number of contents to return (default: 10).
63+
64+
:type offset: int
65+
:param contents: Return contents from this specified position (default: 0).
66+
5967
:rtype: dict
6068
:return: dictionary including details of the folder
6169
"""
62-
63-
return self._get(id=folder_id, contents=contents)
70+
params = {}
71+
if limit:
72+
params["limit"] = limit
73+
if offset:
74+
params["offset"] = offset
75+
return self._get(id=folder_id, contents=contents, params=params)
6476

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

0 commit comments

Comments
 (0)