Skip to content

Commit de756a2

Browse files
committed
Continue refactoring.
1 parent 33e20de commit de756a2

3 files changed

Lines changed: 62 additions & 71 deletions

File tree

tests/base.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import subprocess
21
import warnings
32

43
import pytest
5-
import ssh_test_utils
64
import test_utils
75

86
from datashuttle import DataShuttle
@@ -73,17 +71,3 @@ def clean_project_name(self):
7371
test_utils.delete_project_if_it_exists(project_name)
7472
yield project_name
7573
test_utils.delete_project_if_it_exists(project_name)
76-
77-
@pytest.fixture(
78-
scope="class",
79-
)
80-
def setup_ssh_container(self):
81-
"""
82-
Set up the Dockerfile container for SSH tests and
83-
delete it on teardown.
84-
"""
85-
container_name = "datashuttle_ssh_tests"
86-
ssh_test_utils.setup_ssh_container(container_name)
87-
yield
88-
89-
subprocess.run(f"docker rm -f {container_name}", shell=True)

tests/tests_transfers/base_transfer.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,83 @@
11
""" """
22

33
import copy
4+
import os
5+
import platform
6+
import subprocess
47
from pathlib import Path
58

69
import pandas as pd
710
import pytest
11+
import ssh_test_utils
812
import test_utils
913
from base import BaseTest
1014
from file_conflicts_pathtable import get_pathtable
1115

16+
# Choose port 3306 for running on GH actions
17+
# suggested in https://github.com/orgs/community/discussions/25550
18+
PORT = 3306
19+
os.environ["DS_SSH_PORT"] = str(PORT)
20+
1221

1322
class BaseTransfer(BaseTest):
1423
"""
1524
Class holding fixtures and methods for testing the
1625
custom transfers with keys (e.g. all_non_sub).
1726
"""
1827

28+
@pytest.fixture(
29+
scope="class",
30+
)
31+
def setup_ssh_container(self):
32+
"""
33+
Set up the Dockerfile container for SSH tests and
34+
delete it on teardown.
35+
"""
36+
container_name = "datashuttle_ssh_tests"
37+
38+
assert ssh_test_utils.docker_is_running(), (
39+
"docker is not running, "
40+
"this should be checked at the top of test script"
41+
)
42+
43+
image_path = Path(__file__).parent / "ssh_test_images"
44+
os.chdir(image_path)
45+
46+
if platform.system() != "Windows":
47+
build_command = "sudo docker build -t ssh_server ."
48+
run_command = (
49+
f"sudo docker run -d -p {PORT}:22 "
50+
f"--name {container_name} ssh_server"
51+
)
52+
else:
53+
build_command = "docker build -t ssh_server ."
54+
run_command = f"docker run -d -p {PORT}:22 --name {container_name} ssh_server"
55+
56+
build_output = subprocess.run(
57+
build_command,
58+
shell=True,
59+
capture_output=True,
60+
)
61+
assert build_output.returncode == 0, (
62+
f"docker build failed with: STDOUT-{build_output.stdout} "
63+
f"STDERR-{build_output.stderr}"
64+
)
65+
66+
run_output = subprocess.run(
67+
run_command,
68+
shell=True,
69+
capture_output=True,
70+
)
71+
72+
assert run_output.returncode == 0, (
73+
f"docker run failed with: STDOUT-{run_output.stdout} "
74+
f"STDERR-{run_output.stderr}"
75+
)
76+
77+
yield
78+
79+
subprocess.run(f"docker rm -f {container_name}", shell=True)
80+
1981
@pytest.fixture(
2082
scope="class",
2183
)
Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
11
import builtins
22
import copy
3-
import os
4-
import platform
53
import stat
64
import subprocess
75
import sys
86
import warnings
9-
from pathlib import Path
107

118
import paramiko
129

1310
from datashuttle.utils import rclone, ssh
1411

15-
# Choose port 3306 for running on GH actions
16-
# suggested in https://github.com/orgs/community/discussions/25550
17-
PORT = 3306
18-
os.environ["DS_SSH_PORT"] = str(PORT)
19-
2012

2113
def setup_project_for_ssh(
2214
project,
@@ -79,53 +71,6 @@ def setup_ssh_connection(project, setup_ssh_key_pair=True):
7971
return verified
8072

8173

82-
def setup_ssh_container(container_name):
83-
"""
84-
Build and run the docker container used for
85-
ssh tests.
86-
"""
87-
assert docker_is_running(), (
88-
"docker is not running, "
89-
"this should be checked at the top of test script"
90-
)
91-
92-
image_path = Path(__file__).parent / "ssh_test_images"
93-
os.chdir(image_path)
94-
95-
if platform.system() != "Windows":
96-
build_command = "sudo docker build -t ssh_server ."
97-
run_command = (
98-
f"sudo docker run -d -p {PORT}:22 "
99-
f"--name {container_name} ssh_server"
100-
)
101-
else:
102-
build_command = "docker build -t ssh_server ."
103-
run_command = (
104-
f"docker run -d -p {PORT}:22 --name {container_name} ssh_server"
105-
)
106-
107-
build_output = subprocess.run(
108-
build_command,
109-
shell=True,
110-
capture_output=True,
111-
)
112-
assert build_output.returncode == 0, (
113-
f"docker build failed with: STDOUT-{build_output.stdout} "
114-
f"STDERR-{build_output.stderr}"
115-
)
116-
117-
run_output = subprocess.run(
118-
run_command,
119-
shell=True,
120-
capture_output=True,
121-
)
122-
123-
assert run_output.returncode == 0, (
124-
f"docker run failed with: STDOUT-{run_output.stdout} "
125-
f"STDERR-{run_output.stderr}"
126-
)
127-
128-
12974
def recursive_search_central(project):
13075
"""
13176
A convenience function to recursively search a

0 commit comments

Comments
 (0)