Skip to content

Commit fad03b8

Browse files
committed
WIP: Fix files verification with spaces
1 parent d28b576 commit fad03b8

6 files changed

Lines changed: 40 additions & 36 deletions

File tree

dapi/files.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,13 +316,15 @@ def get_ds_path_uri(t: Tapis, path: str, verify_exists: bool = False) -> str:
316316
print(f"Verifying existence of translated path: {input_uri}")
317317
try:
318318
system_id, remote_path = _parse_tapis_uri(input_uri)
319+
# The Tapis API expects URL-encoded paths when they contain spaces or special characters
320+
encoded_remote_path = urllib.parse.quote(remote_path)
319321
print(f"Checking system '{system_id}' for path '{remote_path}'...")
320322
# Use limit=1 for efficiency, we only care if it *exists*
321323
# Note: listFiles might return successfully for the *parent* directory
322324
# if the final component doesn't exist. A more robust check might
323325
# involve checking the result count or specific item name, but this
324326
# basic check catches non-existent parent directories.
325-
t.files.listFiles(systemId=system_id, path=remote_path, limit=1)
327+
t.files.listFiles(systemId=system_id, path=encoded_remote_path, limit=1)
326328
print(f"Verification successful: Path exists.")
327329
except BaseTapyException as e:
328330
# Specifically check for 404 on the listFiles call

examples/mpm/uniaxial_stress/test_benchmark.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

tests/auth/test_auth.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import unittest
22
from unittest.mock import patch, MagicMock
3-
from dapi.auth.auth import init
3+
from dapi.auth import init
44

55

66
class TestAuthInit(unittest.TestCase):
7-
@patch("dapi.auth.auth.Tapis")
8-
@patch("dapi.auth.auth.os.environ")
7+
@patch("dapi.auth.Tapis")
8+
@patch("dapi.auth.os.environ")
99
def test_init_with_env_variables(self, mock_environ, mock_tapis):
1010
# Setup
1111
mock_environ.get.side_effect = {
@@ -27,10 +27,10 @@ def test_init_with_env_variables(self, mock_environ, mock_tapis):
2727
mock_tapis_obj.get_tokens.assert_called_once()
2828
self.assertEqual(result, mock_tapis_obj)
2929

30-
@patch("dapi.auth.auth.Tapis")
31-
@patch("dapi.auth.auth.os.environ")
32-
@patch("dapi.auth.auth.input")
33-
@patch("dapi.auth.auth.getpass")
30+
@patch("dapi.auth.Tapis")
31+
@patch("dapi.auth.os.environ")
32+
@patch("dapi.auth.input")
33+
@patch("dapi.auth.getpass")
3434
def test_init_with_user_input(
3535
self, mock_getpass, mock_input, mock_environ, mock_tapis
3636
):
@@ -53,8 +53,8 @@ def test_init_with_user_input(
5353
mock_tapis_obj.get_tokens.assert_called_once()
5454
self.assertEqual(result, mock_tapis_obj)
5555

56-
@patch("dapi.auth.auth.Tapis")
57-
@patch("dapi.auth.auth.os.environ")
56+
@patch("dapi.auth.Tapis")
57+
@patch("dapi.auth.os.environ")
5858
def test_init_authentication_failure(self, mock_environ, mock_tapis):
5959
# Setup
6060
mock_environ.get.side_effect = {

tests/files/test_uri_translation.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,27 @@ def test_empty_path(self):
6161
result = tapis_uri_to_local_path(input_uri)
6262
self.assertEqual(result, expected)
6363

64+
def test_path_with_spaces(self):
65+
"""Test handling of paths with spaces (URL encoded)"""
66+
input_uri = "tapis://designsafe.storage.default/kks32/DS%20input/file.txt"
67+
expected = "/home/jupyter/MyData/DS input/file.txt"
68+
result = tapis_uri_to_local_path(input_uri)
69+
self.assertEqual(result, expected)
70+
71+
def test_community_path_with_spaces(self):
72+
"""Test handling of community paths with spaces"""
73+
input_uri = "tapis://designsafe.storage.community/My%20Dataset/data.csv"
74+
expected = "/home/jupyter/CommunityData/My Dataset/data.csv"
75+
result = tapis_uri_to_local_path(input_uri)
76+
self.assertEqual(result, expected)
77+
78+
def test_project_path_with_spaces(self):
79+
"""Test handling of project paths with spaces"""
80+
input_uri = "tapis://project-1234-abcd/simulation%20results/output.txt"
81+
expected = "/home/jupyter/MyProjects/simulation results/output.txt"
82+
result = tapis_uri_to_local_path(input_uri)
83+
self.assertEqual(result, expected)
84+
6485

6586
# This allows running the test from the command line
6687
if __name__ == "__main__":

tests/jobs/test_dir_uri.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import unittest
22
from unittest.mock import MagicMock, patch
3-
from dapi.jobs import get_ds_path_uri
3+
from dapi.files import get_ds_path_uri
44
from tapipy.tapis import Tapis
55

66

tests/jobs/test_job_gen_jobinfo.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import unittest
22
from unittest.mock import Mock, patch
3-
from dapi.jobs import jobs
3+
from dapi.jobs import generate_job_request
44
from datetime import datetime
55

66

@@ -20,10 +20,10 @@ def setUp(self):
2020
self.app_info_mock.jobAttributes.execSystemLogicalQueue = "normal"
2121
self.t_mock.apps.getAppLatestVersion.return_value = self.app_info_mock
2222

23-
@patch("dapi.jobs.jobs.datetime")
23+
@patch("dapi.jobs.datetime")
2424
def test_generate_job_info_default(self, mock_datetime):
2525
mock_datetime.now.return_value = datetime(2023, 5, 1, 12, 0, 0)
26-
result = jobs.generate_job_info(
26+
result = generate_job_request(
2727
self.t_mock, self.app_name, self.input_uri, self.input_file
2828
)
2929
self.assertEqual(result["name"], f"{self.app_name}_20230501_120000")
@@ -52,11 +52,10 @@ def test_generate_job_info_custom(self):
5252
custom_cores_per_node = 4
5353
custom_queue = "high-priority"
5454
custom_allocation = "project123"
55-
result = jobs.generate_job_info(
55+
result = generate_job_request(
5656
self.t_mock,
5757
self.app_name,
5858
self.input_uri,
59-
self.input_file,
6059
job_name=custom_job_name,
6160
max_minutes=custom_max_minutes,
6261
node_count=custom_node_count,
@@ -77,15 +76,11 @@ def test_generate_job_info_custom(self):
7776
def test_generate_job_info_invalid_app(self):
7877
self.t_mock.apps.getAppLatestVersion.side_effect = Exception("Invalid app")
7978
with self.assertRaises(Exception):
80-
jobs.generate_job_info(
81-
self.t_mock, "invalid-app", self.input_uri, self.input_file
82-
)
79+
generate_job_request(self.t_mock, "invalid-app", self.input_uri)
8380

8481
def test_generate_job_info_opensees(self):
8582
opensees_app_name = "opensees-express"
86-
result = jobs.generate_job_info(
87-
self.t_mock, opensees_app_name, self.input_uri, self.input_file
88-
)
83+
result = generate_job_request(self.t_mock, opensees_app_name, self.input_uri)
8984
self.assertIn("parameterSet", result)
9085
self.assertIn("envVariables", result["parameterSet"])
9186
self.assertEqual(

0 commit comments

Comments
 (0)