Skip to content

Commit 38a54a6

Browse files
committed
Change gdrive headless method and add prototype test.
1 parent b49d27b commit 38a54a6

File tree

5 files changed

+50
-49
lines changed

5 files changed

+50
-49
lines changed

.github/workflows/code_test_and_deploy.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,16 @@ jobs:
5555
conda uninstall datashuttle --force
5656
python -m pip install --upgrade pip
5757
pip install .[dev]
58-
- name: Test
59-
run: pytest
58+
# - name: Test
59+
# run: pytest
60+
- name: Set up Google Drive secrets
61+
run: |
62+
printf '%s' '${{ secrets.GDRIVE_SERVICE_ACCOUNT_JSON }}' > "$HOME/gdrive.json"
63+
echo "GDRIVE_SERVICE_ACCOUNT_FILE=$HOME/gdrive.json" >> $GITHUB_ENV
64+
echo "GDRIVE_ROOT_FOLDER_ID=${{ secrets.GDRIVE_ROOT_FOLDER_ID }}" >> $GITHUB_ENV
65+
66+
- name: Run Google Drive tests
67+
run: pytest -q -k test_gdrive_connection
6068

6169
build_sdist_wheels:
6270
name: Build source distribution

.github/workflows/test_connections.yml

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

datashuttle/configs/canonical_configs.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
import typeguard
2929

30-
from datashuttle.configs.aws_regions import get_aws_regions_list
3130
from datashuttle.utils import folders, utils
3231
from datashuttle.utils.custom_exceptions import ConfigError
3332

@@ -48,7 +47,7 @@ def get_canonical_configs() -> dict:
4847
"gdrive_client_id": Optional[str],
4948
"gdrive_root_folder_id": Optional[str],
5049
"aws_access_key_id": Optional[str],
51-
"aws_region": Optional[Literal[*get_aws_regions_list()]],
50+
"aws_region": Optional[str],
5251
}
5352

5453
return canonical_configs

datashuttle/utils/gdrive.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1+
from __future__ import annotations
2+
3+
from typing import (
4+
TYPE_CHECKING,
5+
)
6+
7+
if TYPE_CHECKING:
8+
from datashuttle.configs.config_class import Configs
9+
110
import json
211

3-
from datashuttle.configs.config_class import Configs
412
from datashuttle.utils import rclone, utils
513

614
# -----------------------------------------------------------------------------
Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,64 @@
1+
import builtins
12
import os
2-
from pathlib import Path
3+
import random
4+
import string
35

46
import pytest
57
import test_utils
68
from base import BaseTest
79

810
from datashuttle.configs.canonical_configs import get_broad_datatypes
11+
from datashuttle.utils import rclone
912

1013

1114
@pytest.mark.skipif(os.getenv("CI") is None, reason="Only runs in CI")
1215
class TestGoogleDriveGithubCI(BaseTest):
1316

14-
def test_google_drive_connection(self, project):
15-
# ── 1 pull the secrets from env ───────────────────────────────
17+
def test_google_drive_connection(self, no_cfg_project, tmp_path):
18+
19+
central_path = (
20+
f"test-id-{''.join(random.choices(string.digits, k=15))}"
21+
)
22+
1623
root_id = os.environ["GDRIVE_ROOT_FOLDER_ID"]
1724
sa_path = os.environ["GDRIVE_SERVICE_ACCOUNT_FILE"]
1825

19-
# ── 2 configure the project (no hard-coded ids/paths) ─────────
20-
project.update_config_file(
21-
local_path=str(Path.home() / "data"), # any temp location
26+
no_cfg_project.make_config_file(
27+
local_path=str(tmp_path), # any temp location TODO UPDATE
2228
connection_method="gdrive",
23-
central_path="testGDrive",
29+
central_path=central_path,
2430
gdrive_root_folder_id=root_id,
2531
gdrive_client_id=None, # keep None
2632
)
2733

28-
# ── 3 feed the SA-file path to the interactive prompt ─────────
2934
state = {"first": True}
3035

3136
def mock_input(_: str) -> str:
3237
if state["first"]:
3338
state["first"] = False
34-
return "n" # ← tells setup to use file, not auth-browser
35-
return sa_path # ← absolute path written in the workflow
36-
37-
import builtins
39+
return "n"
40+
return sa_path
3841

3942
original_input = builtins.input
4043
builtins.input = mock_input
4144

42-
try:
43-
project.setup_google_drive_connection()
44-
finally:
45-
builtins.input = original_input # always restore
45+
no_cfg_project.setup_google_drive_connection()
46+
47+
builtins.input = original_input
4648

47-
# ── 4 run the usual checks ────────────────────────────────────
4849
subs, sessions = test_utils.get_default_sub_sessions_to_test()
50+
4951
test_utils.make_and_check_local_project_folders(
50-
project, "rawdata", subs, sessions, get_broad_datatypes()
52+
no_cfg_project, "rawdata", subs, sessions, get_broad_datatypes()
5153
)
5254

53-
project.upload_entire_project()
55+
no_cfg_project.upload_entire_project()
56+
57+
# get a list of files on gdrive and check they are as expected
58+
# assert the test id if its failed
59+
60+
# only tidy up if as expected, otherwise we can leave the folder there to have a look
61+
# and delete manually later
62+
rclone.call_rclone(
63+
f"purge central_{no_cfg_project.project_name}_gdrive:{central_path}"
64+
)

0 commit comments

Comments
 (0)