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

Manage empty searches in transfer_complete_datasets #204

Merged
merged 11 commits into from
Sep 21, 2022
5 changes: 4 additions & 1 deletion dkist/net/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ def transfer_complete_datasets(datasets: Union[str, QueryResponseRow, DKISTQuery
from dkist.net import conf

if isinstance(datasets, str):
datasets = _get_dataset_inventory(datasets)[0]
try:
datasets = _get_dataset_inventory(datasets)[0]
except IndexError as e:
raise IndexError(f"No results available for dataset {datasets}") from e
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do this inside _get_dataset_inventory we could avoid the try block which is always my slight preference?


# If we have a UnifiedResponse object, it could contain one or more dkist tables.
# Stack them and then treat them like we were passed a single table with many rows.
Expand Down
11 changes: 11 additions & 0 deletions dkist/net/tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ def test_download_default_keywords(orchestrate_transfer_mock, keywords):
)


def test_transfer_unavailable_data(mocker):
get_inv_mock = mocker.patch(
"dkist.net.helpers._get_dataset_inventory",
autospec=True,
return_value=[],
)

with pytest.raises(IndexError):
transfer_complete_datasets("null")


def test_transfer_from_dataset_id(mocker, orchestrate_transfer_mock):
get_inv_mock = mocker.patch(
"dkist.net.helpers._get_dataset_inventory",
Expand Down