Skip to content

Commit

Permalink
Archive path
Browse files Browse the repository at this point in the history
  • Loading branch information
kks32 committed Oct 27, 2023
1 parent a219444 commit f9b206a
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dsjobs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .dir import get_ds_path_uri
from .jobs import get_status, runtime_summary, generate_job_info
from .jobs import get_status, runtime_summary, generate_job_info, get_archive_path
31 changes: 31 additions & 0 deletions dsjobs/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,34 @@ def generate_job_info(
}

return job_info


def get_archive_path(ag, job_id):
"""
Get the archive path for a given job ID and modifies the user directory
to '/home/jupyter/MyData'.
Args:
ag (object): The Agave object to interact with the platform.
job_id (str): The job ID to retrieve the archive path for.
Returns:
str: The modified archive path.
Raises:
ValueError: If the archivePath format is unexpected.
"""

# Fetch the job info.
job_info = ag.jobs.get(jobId=job_id)

# Try to split the archive path to extract the user.
try:
user, _ = job_info.archivePath.split("/", 1)
except ValueError:
raise ValueError(f"Unexpected archivePath format for jobId={job_id}")

# Construct the new path.
new_path = job_info.archivePath.replace(user, "/home/jupyter/MyData")

return new_path
34 changes: 34 additions & 0 deletions tests/test_job_get_archive_path.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import unittest
from unittest.mock import patch, Mock
from dsjobs import get_archive_path


class TestGetArchivePath(unittest.TestCase):
def test_get_archive_path(self):
# Create a mock Agave object and its method return value
mock_ag = Mock()
mock_job_info = Mock()
mock_job_info.archivePath = "user123/jobdata/somefile"
mock_ag.jobs.get.return_value = mock_job_info

# Call the function
result = get_archive_path(mock_ag, "dummy_job_id")

# Check the result
expected_path = "/home/jupyter/MyData/jobdata/somefile"
self.assertEqual(result, expected_path)

def test_get_archive_path_invalid_format(self):
# Create a mock Agave object with an unexpected format return
mock_ag = Mock()
mock_job_info = Mock()
mock_job_info.archivePath = "invalid_format_path"
mock_ag.jobs.get.return_value = mock_job_info

# Check if the function raises a ValueError as expected
with self.assertRaises(ValueError):
get_archive_path(mock_ag, "dummy_job_id")


if __name__ == "__main__":
unittest.main()

0 comments on commit f9b206a

Please sign in to comment.