Skip to content

Commit b316947

Browse files
committed
Fixing tests.
1 parent 8f3e444 commit b316947

File tree

10 files changed

+37
-24
lines changed

10 files changed

+37
-24
lines changed

datashuttle/tui/tabs/create_folders.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
require_double_click,
4343
)
4444
from datashuttle.tui.utils.tui_validators import NeuroBlueprintValidator
45+
from datashuttle.utils import rclone_encryption
4546

4647

4748
class CreateFoldersTab(TreeAndInputTab):
@@ -338,9 +339,12 @@ def suggest_next_sub_ses(
338339
in canonical_configs.get_connection_methods_list()
339340
)
340341

341-
if include_central and self.interface.project.cfg[
342-
"connection_method"
343-
] in ["aws", "gdrive", "ssh"]:
342+
if (
343+
include_central
344+
and rclone_encryption.connection_method_requires_encryption(
345+
self.interface.project.cfg["connection_method"]
346+
)
347+
):
344348
self.searching_central_popup_widget = (
345349
SearchingCentralForNextSubSesPopup(prefix)
346350
)

datashuttle/utils/rclone.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,9 @@ def get_config_arg(cfg: Configs) -> str:
504504
cfg.rclone.get_rclone_central_connection_config_filepath()
505505
)
506506

507-
if cfg["connection_method"] in ["aws", "gdrive", "ssh"]:
507+
if rclone_encryption.connection_method_requires_encryption(
508+
cfg["connection_method"]
509+
):
508510
return f'--config "{rclone_config_path}"'
509511
else:
510512
return ""

datashuttle/utils/rclone_encryption.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,13 +304,15 @@ def remove_credentials_as_password_command():
304304
os.environ.pop("RCLONE_PASSWORD_COMMAND")
305305

306306

307+
def connection_method_requires_encryption(connection_method: str):
308+
return connection_method in ["aws", "gdrive", "ssh"]
309+
310+
307311
def get_windows_password_filepath(
308312
cfg: Configs,
309313
) -> Path:
310314
"""Get the canonical location where datashuttle stores the windows credentials."""
311-
assert cfg["connection_method"] in ["aws", "gdrive", "ssh"], (
312-
"password should only be set for ssh, aws, gdrive."
313-
)
315+
assert connection_method_requires_encryption(cfg["connection_method"])
314316

315317
base_path = canonical_folders.get_datashuttle_path() / "credentials"
316318

tests/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from . import test_utils
66

7-
TEST_PROJECT_NAME = "test_project"
7+
TEST_PROJECT_NAME = "ds-unique-test-project-d375gd234vds2f"
88

99

1010
class BaseTest:

tests/tests_integration/test_local_only_mode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from .. import test_utils
1010
from ..base import BaseTest
1111

12-
TEST_PROJECT_NAME = "test_project"
12+
TEST_PROJECT_NAME = "ds-unique-test-project-d375gd234vds2f"
1313

1414

1515
class TestLocalOnlyProject(BaseTest):

tests/tests_integration/test_logging.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def clean_project_name(self):
8686
Switch on datashuttle logging as required for
8787
these tests, then turn back off during tear-down.
8888
"""
89-
project_name = "test_project"
89+
project_name = "ds-unique-test-project-d375gd234vds2f"
9090
test_utils.delete_project_if_it_exists(project_name)
9191
test_utils.set_datashuttle_loggers(disable=False)
9292

@@ -290,7 +290,7 @@ def test_logs_upload_and_download(
290290
assert "Using config file from" in log
291291
assert "--include" in log
292292
assert "sub-11/ses-123/anat/**" in log
293-
assert "/central/test_project/rawdata" in log
293+
assert "/central/ds-unique-test-project-d375gd234vds2f/rawdata" in log
294294

295295
@pytest.mark.parametrize("upload_or_download", ["upload", "download"])
296296
def test_logs_upload_and_download_folder_or_file(

tests/tests_integration/test_search_methods.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
class TestSubSesSearches(BaseTest):
2020
@pytest.mark.parametrize("return_full_path", [True, False])
2121
def test_local_vs_central_search_methods(
22-
self, project, monkeypatch, return_full_path
22+
self, project, monkeypatch, return_full_path, tmp_path
2323
):
2424
"""
2525
Test the `search_local_filesystem` and `search_central_via_connection`
@@ -55,18 +55,23 @@ def test_local_vs_central_search_methods(
5555
test_utils.write_file(central_path / path_.parent.parent.parent / f"{path_.parent.parent.name}.md", contents="hello_world",)
5656
# fmt: on
5757

58-
# Monkeycatch `get_rclone_config_name` to return `local` and set `local`
59-
# as a rclone config entry associated with the local filesystem. By this
60-
# method we can hijack `search_central_via_connection` to run locally
61-
# (though it is set up in practice to run via ssh, gdrive or aws).
58+
# search_central_via_connection will run the transfer
59+
# function but with additional checks for rclone password
60+
# through `run_function_that_requires_encrypted_rclone_config_access`.
61+
# Here we monkeypatch that to skip all of those checks.
62+
call_rclone(r"config create local local nounc true")
63+
64+
from datashuttle.utils import rclone
65+
66+
def mock_rclone_caller(_, func, optional=None):
67+
return func()
68+
6269
monkeypatch.setattr(
63-
project.cfg,
64-
"get_rclone_config_name",
65-
lambda connection_method: "local",
70+
rclone,
71+
"run_function_that_requires_encrypted_rclone_config_access",
72+
mock_rclone_caller,
6673
)
6774

68-
call_rclone("config create local local nounc true")
69-
7075
# Perform a range of checks across folders and files
7176
# and check the outputs of both approaches match.
7277
# fmt: off

tests/tests_regression/test_backwards_compatibility.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from .. import test_utils
88

9-
TEST_PROJECT_NAME = "test_project"
9+
TEST_PROJECT_NAME = "ds-unique-test-project-d375gd234vds2f"
1010

1111

1212
class TestBackwardsCompatibility:

tests/tests_transfers/base_transfer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def pathtable_and_project(self, tmpdir_factory):
3232
tmp_path = tmpdir_factory.mktemp("test")
3333

3434
base_path = tmp_path / "test with space"
35-
test_project_name = "test_file_conflicts"
35+
test_project_name = "ds-unique-test-project-d375gd234vds2f"
3636

3737
project = test_utils.setup_project_fixture(
3838
base_path, test_project_name

tests/tests_tui/tui_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ async def empty_project_paths(self, tmp_path_factory, monkeypatch):
4343
2) It fails for testing CLI, because CLI spawns a new process in
4444
which `get_datashuttle_path()` is not monkeypatched.
4545
"""
46-
project_name = "my-test-project"
46+
project_name = "ds-unique-test-project-d375gd234vds2f"
4747
tmp_path = tmp_path_factory.mktemp("test")
4848
tmp_config_path = tmp_path / "config"
4949

0 commit comments

Comments
 (0)