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

Added upload check for targets #125

Merged
merged 2 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions cumulus_library/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ def upload_files(args: dict):
"study export folder."
)
file_paths = list(args["data_path"].glob("**/*.parquet"))
if args["target"] is not None:
dogversioning marked this conversation as resolved.
Show resolved Hide resolved
filtered_paths = []
for path in file_paths:
if any(study in str(path) for study in args["target"]):
filtered_paths.append(path)
file_paths = filtered_paths

if not args["user"] or not args["id"]:
sys.exit("user/id not provided, please pass --user and --id")
try:
Expand Down
32 changes: 31 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import requests_mock

from cumulus_library import cli
from cumulus_library import upload


@mock.patch("pyathena.connect")
Expand Down Expand Up @@ -204,7 +205,7 @@ def test_cli_creates_studies(
def test_cli_upload_studies(mock_glob, args, status, login_error, raises):
mock_glob.side_effect = [
[Path(__file__)],
[Path(str(Path(__file__)) + "/test_data/count_synthea_patient.parquet")],
[Path(str(Path(__file__).parent) + "/test_data/count_synthea_patient.parquet")],
]
with raises:
with requests_mock.Mocker() as r:
Expand All @@ -217,3 +218,32 @@ def test_cli_upload_studies(mock_glob, args, status, login_error, raises):
)
r.post("https://presigned.url.org", status_code=status)
cli.main(cli_args=args)


@pytest.mark.parametrize(
"args,calls",
[
(["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),
],
)
@mock.patch.dict(
os.environ,
clear=True,
)
@mock.patch("pathlib.Path.glob")
@mock.patch("cumulus_library.upload.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/count_synthea_patient.parquet"
),
Path(
str(Path(__file__).parent) + "/other_data/count_synthea_patient.parquet"
),
],
]
cli.main(cli_args=args)
assert mock_upload_data.call_count == calls
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I might prefer to also see a comparison of the actual paths, to confirm the filtering got the right ones.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, this is lightly contrived, but there is a check now making sure the right path was selected.