|
| 1 | +import builtins |
1 | 2 | import os |
2 | 3 | from pathlib import Path |
3 | 4 |
|
4 | 5 | import pytest |
5 | 6 | import test_utils |
6 | 7 | from base import BaseTest |
7 | 8 |
|
| 9 | +from datashuttle import DataShuttle |
8 | 10 | from datashuttle.configs.canonical_configs import get_broad_datatypes |
9 | 11 |
|
10 | 12 |
|
11 | | -@pytest.mark.skipif(os.getenv("CI") is None, reason="Only runs in CI") |
| 13 | +# @pytest.mark.skipif(os.getenv("CI") is None, reason="Only runs in CI") |
12 | 14 | class TestGoogleDriveGithubCI(BaseTest): |
13 | 15 |
|
14 | | - def test_google_drive_connection(self, project): |
15 | | - # ── 1 pull the secrets from env ─────────────────────────────── |
| 16 | + @pytest.fixture(scope="function") |
| 17 | + def transfer_project_info(self, tmp_path): |
| 18 | + """ """ |
| 19 | + project = DataShuttle("transfer_project") |
| 20 | + central_path = Path(*tmp_path.parts[-2:]).as_posix() |
| 21 | + |
| 22 | + return (project, central_path) |
| 23 | + |
| 24 | + def test_google_drive_connection(self, transfer_project_info): |
| 25 | + |
| 26 | + project, central_path = transfer_project_info |
| 27 | + |
16 | 28 | root_id = os.environ["GDRIVE_ROOT_FOLDER_ID"] |
17 | 29 | sa_path = os.environ["GDRIVE_SERVICE_ACCOUNT_FILE"] |
18 | 30 |
|
19 | | - # ── 2 configure the project (no hard-coded ids/paths) ───────── |
20 | 31 | project.update_config_file( |
21 | 32 | local_path=str( |
22 | 33 | Path.home() / "data" |
23 | 34 | ), # any temp location TODO UPDATE |
24 | 35 | connection_method="gdrive", |
25 | | - central_path="testGDrive", |
| 36 | + central_path=central_path, |
26 | 37 | gdrive_root_folder_id=root_id, |
27 | 38 | gdrive_client_id=None, # keep None |
28 | 39 | ) |
29 | 40 |
|
30 | | - # ── 3 feed the SA-file path to the interactive prompt ───────── |
31 | 41 | state = {"first": True} |
32 | 42 |
|
33 | 43 | def mock_input(_: str) -> str: |
34 | 44 | if state["first"]: |
35 | 45 | state["first"] = False |
36 | | - return "n" # ← tells setup to use file, not auth-browser |
37 | | - return sa_path # ← absolute path written in the workflow |
38 | | - |
39 | | - import builtins |
| 46 | + return "n" |
| 47 | + return sa_path |
40 | 48 |
|
41 | 49 | original_input = builtins.input |
42 | 50 | builtins.input = mock_input |
43 | 51 |
|
44 | | - try: |
45 | | - project.setup_google_drive_connection() |
46 | | - finally: |
47 | | - builtins.input = original_input # always restore |
| 52 | + project.setup_google_drive_connection() |
| 53 | + |
| 54 | + builtins.input = original_input |
48 | 55 |
|
49 | | - # ── 4 run the usual checks ──────────────────────────────────── |
50 | 56 | subs, sessions = test_utils.get_default_sub_sessions_to_test() |
| 57 | + |
51 | 58 | test_utils.make_and_check_local_project_folders( |
52 | 59 | project, "rawdata", subs, sessions, get_broad_datatypes() |
53 | 60 | ) |
|
0 commit comments