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
6 changes: 5 additions & 1 deletion dkist/net/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ def _get_dataset_inventory(dataset_id: str): # pragma: no cover
"""
Do a search for a single dataset id
"""
return DKISTClient().search(Dataset(dataset_id))
results = DKISTClient().search(Dataset(dataset_id))
if len(results) == 1:
raise IndexError(f"No results available for dataset {dataset_id}")

return results


def transfer_complete_datasets(datasets: Union[str, QueryResponseRow, DKISTQueryResponseTable, UnifiedResponse],
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.client.DKISTClient.search",
Copy link
Member

Choose a reason for hiding this comment

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

Is this mocker actually being hit? I would have thought this should be

Suggested change
"dkist.net.client.DKISTClient.search",
"dkist.net.helpers.DKISTClient.search",

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If it wasn't, surely the test would hit the "An attempt was made to connect to the internet" error (which is what happens if I take the mocker out entirely).

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