|
| 1 | +import builtins |
| 2 | +import os |
| 3 | +import random |
| 4 | +import string |
| 5 | + |
| 6 | +import test_utils |
| 7 | +from base import BaseTest |
| 8 | + |
| 9 | +from datashuttle.configs.canonical_configs import get_broad_datatypes |
| 10 | +from datashuttle.utils import rclone |
| 11 | + |
| 12 | + |
| 13 | +# @pytest.mark.skipif(os.getenv("CI") is None, reason="Only runs in CI") |
| 14 | +class TestGoogleDriveGithubCI(BaseTest): |
| 15 | + |
| 16 | + def test_google_drive_connection(self, no_cfg_project, tmp_path): |
| 17 | + |
| 18 | + central_path = f"test-datashuttle/test-id-{''.join(random.choices(string.digits, k=15))}" |
| 19 | + |
| 20 | + aws_access_key_id = os.environ["AWS_ACCESS_KEY_ID"] |
| 21 | + aws_access_key_id_secret = os.environ["AWS_ACCESS_KEY_ID_SECRET"] |
| 22 | + aws_region = os.environ["AWS_REGION"] |
| 23 | + |
| 24 | + no_cfg_project.make_config_file( |
| 25 | + local_path=str(tmp_path), # any temp location TODO UPDATE |
| 26 | + connection_method="aws", |
| 27 | + central_path=central_path, |
| 28 | + aws_access_key_id=aws_access_key_id, |
| 29 | + aws_region=aws_region, |
| 30 | + ) |
| 31 | + |
| 32 | + state = {"first": True} |
| 33 | + |
| 34 | + def mock_input(_: str) -> str: |
| 35 | + if state["first"]: |
| 36 | + state["first"] = False |
| 37 | + return "y" |
| 38 | + return aws_access_key_id_secret |
| 39 | + |
| 40 | + original_input = builtins.input |
| 41 | + builtins.input = mock_input |
| 42 | + |
| 43 | + no_cfg_project.setup_aws_connection() # TODO: check that the connection method is correct for these funcs |
| 44 | + |
| 45 | + builtins.input = original_input |
| 46 | + |
| 47 | + subs, sessions = test_utils.get_default_sub_sessions_to_test() |
| 48 | + |
| 49 | + test_utils.make_and_check_local_project_folders( |
| 50 | + no_cfg_project, "rawdata", subs, sessions, get_broad_datatypes() |
| 51 | + ) |
| 52 | + |
| 53 | + no_cfg_project.upload_entire_project() |
| 54 | + |
| 55 | + # get a list of files on gdrive and check they are as expected |
| 56 | + # assert the test id if its failed |
| 57 | + |
| 58 | + # only tidy up if as expected, otherwise we can leave the folder there to have a look |
| 59 | + # and delete manually later |
| 60 | + |
| 61 | + rclone.call_rclone( |
| 62 | + f"purge central_{no_cfg_project.project_name}_aws:{central_path}" |
| 63 | + ) |
0 commit comments