Skip to content

Commit 625eb9d

Browse files
committed
fix(searcher): respect get-file-locations --protocol parameter (#154)
Fixes issue where `get-file-locations --no-expand --protocol xrootd` would return HTTPS URLs instead of XRootD URLs. Closes #152
1 parent ff4bd39 commit 625eb9d

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

cernopendata_client/searcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def get_files_list(
225225
else:
226226
files_list.append(
227227
(
228-
f"{SERVER_HTTPS_URI}/record/{record_json['metadata']['recid']}/file_index/{file_['key']}",
228+
f"{new_server}/record/{record_json['metadata']['recid']}/file_index/{file_['key']}",
229229
file_["size"],
230230
"",
231231
)

tests/test_cli_get_file_locations.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from click.testing import CliRunner
1313
from cernopendata_client.cli import get_file_locations
14-
from cernopendata_client.config import SERVER_HTTPS_URI
14+
from cernopendata_client.config import SERVER_HTTPS_URI, SERVER_ROOT_URI
1515

1616

1717
def test_get_file_locations_from_recid():
@@ -106,3 +106,27 @@ def test_get_file_locations_with_https_server_xrootd_protocol():
106106
)
107107
assert test_result.exit_code == 0
108108
assert "root://eospublic.cern.ch//eos/" in test_result.output
109+
110+
111+
def test_get_file_locations_no_expand_with_xrootd_protocol():
112+
"""Test `get-file-locations --no-expand --protocol xrootd` command."""
113+
test_get_file_locations = CliRunner()
114+
test_result = test_get_file_locations.invoke(
115+
get_file_locations,
116+
["--recid", 1, "--no-expand", "--protocol", "xrootd"],
117+
)
118+
assert test_result.exit_code == 0
119+
assert SERVER_ROOT_URI in test_result.output
120+
assert "file_index" in test_result.output
121+
122+
123+
def test_get_file_locations_no_expand_with_http_protocol():
124+
"""Test `get-file-locations --no-expand --protocol http` command."""
125+
test_get_file_locations = CliRunner()
126+
test_result = test_get_file_locations.invoke(
127+
get_file_locations,
128+
["--recid", 1, "--no-expand", "--protocol", "http"],
129+
)
130+
assert test_result.exit_code == 0
131+
assert "http://opendata.cern.ch" in test_result.output
132+
assert "file_index" in test_result.output

0 commit comments

Comments
 (0)