Skip to content

Commit 1921f6f

Browse files
committed
Add prototype AWS test.
1 parent 38a54a6 commit 1921f6f

File tree

2 files changed

+78
-6
lines changed

2 files changed

+78
-6
lines changed

.github/workflows/code_test_and_deploy.yml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,23 @@ jobs:
5757
pip install .[dev]
5858
# - name: Test
5959
# run: pytest
60-
- name: Set up Google Drive secrets
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
68+
69+
- name: Set up AWS secrets
6170
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
71+
echo "AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }}" >> $GITHUB_ENV
72+
echo "AWS_ACCESS_KEY_ID_SECRET=${{ secrets.AWS_ACCESS_KEY_ID_SECRET }}" >> $GITHUB_ENV
73+
echo "AWS_REGION=${{ secrets.AWS_REGION }}" >> $GITHUB_ENV
6574
66-
- name: Run Google Drive tests
67-
run: pytest -q -k test_gdrive_connection
75+
- name: Run AWS tests
76+
run: pytest -q -k test_aws_connection
6877

6978
build_sdist_wheels:
7079
name: Build source distribution
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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

Comments
 (0)