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

Provide feedback if trying to upload zero files #355

Merged
merged 1 commit into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cumulus_library/actions/uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ def upload_files(args: dict):
filtered_paths.append(path)
file_paths = filtered_paths

if len(file_paths) == 0:
sys.exit("No files found for upload. Is your data path/target specified correctly?")
if not args["user"] or not args["id"]:
sys.exit("user/id not provided, please pass --user and --id")
try:
Expand Down
53 changes: 32 additions & 21 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,11 +646,19 @@ def test_cli_upload_studies(mock_glob, args, status, login_error, raises):


@pytest.mark.parametrize(
"args,calls",
"args,calls,raises",
[
(["upload", "--user", "user", "--id", "id", "./foo"], 2),
(["upload", "--user", "user", "--id", "id", "./foo", "-t", "test_data"], 1),
(["upload", "--user", "user", "--id", "id", "./foo", "-t", "not_found"], 0),
(["upload", "--user", "user", "--id", "id", "./foo"], 2, does_not_raise()),
(
["upload", "--user", "user", "--id", "id", "./foo", "-t", "test_data"],
1,
does_not_raise(),
),
(
["upload", "--user", "user", "--id", "id", "./foo", "-t", "not_found"],
0,
pytest.raises(SystemExit),
),
],
)
@mock.patch.dict(
Expand All @@ -659,23 +667,26 @@ def test_cli_upload_studies(mock_glob, args, status, login_error, raises):
)
@mock.patch("pathlib.Path.glob")
@mock.patch("cumulus_library.actions.uploader.upload_data")
def test_cli_upload_filter(mock_upload_data, mock_glob, args, calls):
mock_glob.side_effect = [
[
Path(
str(Path(__file__).parent) + "/test_data/test_data__count_synthea_patient.parquet"
),
Path(
str(Path(__file__).parent) + "/other_data/other_data__count_synthea_patient.parquet"
),
],
]
cli.main(cli_args=args)
if len(mock_upload_data.call_args_list) == 1:
target = args[args.index("-t") + 1]
# filepath is in the third argument position in the upload data arg list
assert target in str(mock_upload_data.call_args[0][2])
assert mock_upload_data.call_count == calls
def test_cli_upload_filter(mock_upload_data, mock_glob, args, calls, raises):
with raises:
mock_glob.side_effect = [
[
Path(
str(Path(__file__).parent)
+ "/test_data/test_data__count_synthea_patient.parquet"
),
Path(
str(Path(__file__).parent)
+ "/other_data/other_data__count_synthea_patient.parquet"
),
],
]
cli.main(cli_args=args)
if len(mock_upload_data.call_args_list) == 1:
target = args[args.index("-t") + 1]
# filepath is in the third argument position in the upload data arg list
assert target in str(mock_upload_data.call_args[0][2])
assert mock_upload_data.call_count == calls


@pytest.mark.parametrize("mode", ["cli", "env"])
Expand Down