Skip to content
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

Add limit, offset and include_deleted to show_folder #494

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
51 changes: 50 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,52 @@ 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):
for i in range(12):
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_show_folder_contents_include_deleted(self):
history = self.gi.histories.create_history(name="Test History")
self._test_dataset(history["id"])
contents = self.gi.histories.show_history(history["id"], contents=True, types=["dataset"])
hda = contents[0]
bernt-matthias marked this conversation as resolved.
Show resolved Hide resolved

# create 2 library data sets within a new folder in the library
subfolder = self.gi.folders.create_folder(self.folder["id"], f"{self.name}")
ldda1 = self.gi.libraries.copy_from_dataset(
library_id=self.library["id"], dataset_id=hda["id"], folder_id=subfolder["id"], message="Added HDA"
)
ldda2 = self.gi.libraries.copy_from_dataset(
library_id=self.library["id"], dataset_id=hda["id"], folder_id=subfolder["id"], message="Added HDA"
)
subfolder_info = self.gi.folders.show_folder(subfolder["id"], contents=True)
assert len(subfolder_info["folder_contents"]) == 2
assert subfolder_info["folder_contents"][0]["type"] == "file"

# delete the library datasets and check if include_deleted works
self.gi.libraries.delete_library_dataset(self.library["id"], ldda1["id"])
self.gi.libraries.delete_library_dataset(self.library["id"], ldda2["id"], purged=True)
subfolder_info = self.gi.folders.show_folder(subfolder["id"], contents=True, include_deleted=True)
assert len(subfolder_info["folder_contents"]) == 2
subfolder_info = self.gi.folders.show_folder(subfolder["id"], contents=True)
assert len(subfolder_info["folder_contents"]) == 0
bernt-matthias marked this conversation as resolved.
Show resolved Hide resolved

# delete the library folder
self.gi.folders.delete_folder(subfolder["id"])
self.gi.histories.delete_dataset(history["id"], hda["id"])
bernt-matthias marked this conversation as resolved.
Show resolved Hide resolved
self.gi.histories.delete_history(history["id"])

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
26 changes: 23 additions & 3 deletions bioblend/galaxy/folders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,14 @@ 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: int = 10,
offset: int = 0,
include_deleted: bool = False,
) -> Dict[str, Any]:
"""
Display information about a folder.

Expand All @@ -56,11 +63,24 @@ 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).

:type include_deleted: bool
:param include_deleted: Returns also deleted contents.

:rtype: dict
:return: dictionary including details of the folder
"""

return self._get(id=folder_id, contents=contents)
params = {
"limit": limit,
"offset": offset,
"include_deleted": include_deleted,
}
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