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

test: add integ tests to test download func #422

Merged
merged 1 commit into from
Jul 29, 2024
Merged
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
88 changes: 88 additions & 0 deletions test/integ/deadline_job_attachments/test_job_attachments.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from dataclasses import dataclass
from pathlib import Path
from unittest.mock import MagicMock
import sys

from deadline.job_attachments.models import JobAttachmentS3Settings

Expand Down Expand Up @@ -1533,3 +1534,90 @@ def test_download_outputs_windows_max_file_path_length_exception(
),
):
job_output_downloader.download_job_output()


@pytest.mark.integ
def test_download_outputs_no_outputs_dir(
job_attachment_test: JobAttachmentTest,
sync_outputs: SyncOutputsOutput,
):
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: We should add typing for this return

"""
Test that if trying to download outputs but not specify a file path
Download will be saved to the current directory.
"""

download_path = Path(
os.path.normpath(Path("").absolute()) / sync_outputs.step0_task0_output_file
)

job_attachment_settings = get_queue(
farm_id=job_attachment_test.farm_id,
queue_id=job_attachment_test.queue_id,
deadline_endpoint_url=job_attachment_test.deadline_endpoint,
).jobAttachmentSettings

if job_attachment_settings is None:
raise Exception("Job attachment settings must be set for this test.")

job_output_downloader = download.OutputDownloader(
s3_settings=job_attachment_settings,
farm_id=job_attachment_test.farm_id,
queue_id=job_attachment_test.queue_id,
job_id=sync_outputs.job_id,
step_id=sync_outputs.step0_id,
task_id=sync_outputs.step0_task0_id,
)
job_output_downloader.set_root_path(str(job_attachment_test.ASSET_ROOT), "")

# WHEN
try:
job_output_downloader.download_job_output()
# THEN
# The output file should be downloaded to the current directory
assert download_path.exists()
finally:
shutil.rmtree(download_path.parent)


@pytest.mark.integ
@pytest.mark.skipif(
sys.platform != "win32",
reason="This test is for Windows file path length UNC, skipping this if os not Windows",
)
def test_download_outputs_windows_file_path_UNC(
job_attachment_test: JobAttachmentTest,
sync_outputs: SyncOutputsOutput,
):
"""
Test that if trying to download outputs to a file path that
longer than 260 chars in Windows but have UNC, the download is success.
"""
long_root_path = Path("\\\\?\\" + __file__).parent / str("A" * 135)

job_attachment_settings = get_queue(
farm_id=job_attachment_test.farm_id,
queue_id=job_attachment_test.queue_id,
deadline_endpoint_url=job_attachment_test.deadline_endpoint,
).jobAttachmentSettings

if job_attachment_settings is None:
raise Exception("Job attachment settings must be set for this test.")

job_output_downloader = download.OutputDownloader(
s3_settings=job_attachment_settings,
farm_id=job_attachment_test.farm_id,
queue_id=job_attachment_test.queue_id,
job_id=sync_outputs.job_id,
step_id=sync_outputs.step0_id,
task_id=sync_outputs.step0_task0_id,
)
job_output_downloader.set_root_path(str(job_attachment_test.ASSET_ROOT), str(long_root_path))

# WHEN
try:
job_output_downloader.download_job_output()
# THEN
# The output file should be downloaded to the current directory
assert Path(long_root_path / sync_outputs.step0_task0_output_file).exists()
finally:
shutil.rmtree(long_root_path)
Loading