Skip to content

Commit e900f97

Browse files
committed
fix(searcher): respect get-file-locations --server parameter (#155)
Fixes issue where `get-file-locations --server https://example.org` would ignore the custom server and revert to the default HTTPS server. Closes #153
1 parent 625eb9d commit e900f97

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

cernopendata_client/searcher.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,8 @@ def get_files_list(
198198
files_list = []
199199

200200
new_server = SERVER_ROOT_URI
201-
if searcher_protocol == "http":
201+
if searcher_protocol in ("http", "https"):
202202
new_server = server
203-
elif searcher_protocol == "https":
204-
new_server = SERVER_HTTPS_URI
205203

206204
for file_ in record_json["metadata"].get("files", []):
207205
files_list.append(
@@ -262,7 +260,7 @@ def get_file_info_remote(server, recid, protocol=None, filtered_files=None):
262260
if searcher_protocol == "http":
263261
file_uri = file_info["uri"].replace(SERVER_ROOT_URI, server)
264262
elif searcher_protocol == "https":
265-
file_uri = file_info["uri"].replace(SERVER_ROOT_URI, SERVER_HTTPS_URI)
263+
file_uri = file_info["uri"].replace(SERVER_ROOT_URI, server)
266264
if not filtered_files or file_uri in filtered_files:
267265
file_info_remote.append(
268266
{

tests/test_cli_get_file_locations.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# This file is part of cernopendata-client.
44
#
5-
# Copyright (C) 2020 CERN.
5+
# Copyright (C) 2020, 2025 CERN.
66
#
77
# cernopendata-client is free software; you can redistribute it and/or modify
88
# it under the terms of the GPLv3 license; see LICENSE file for more details.
@@ -130,3 +130,15 @@ def test_get_file_locations_no_expand_with_http_protocol():
130130
assert test_result.exit_code == 0
131131
assert "http://opendata.cern.ch" in test_result.output
132132
assert "file_index" in test_result.output
133+
134+
135+
def test_get_file_locations_with_custom_https_server():
136+
"""Test `get-file-locations --server` command for custom https server."""
137+
test_get_file_locations = CliRunner()
138+
test_result = test_get_file_locations.invoke(
139+
get_file_locations, ["--recid", 3005, "--server", "https://opendata-qa.cern.ch"]
140+
)
141+
assert test_result.exit_code == 0
142+
assert "https://opendata-qa.cern.ch" in test_result.output
143+
assert "https://opendata.cern.ch" not in test_result.output
144+
assert "configFile.py" in test_result.output

0 commit comments

Comments
 (0)