Skip to content

Commit 1e258e4

Browse files
committed
chore: cleanup for mirrored workflows
1 parent 86c0fc3 commit 1e258e4

File tree

8 files changed

+125
-108
lines changed

8 files changed

+125
-108
lines changed

conftest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,18 @@
55
loaded by pytest when running tests.
66
"""
77

8+
from pathlib import Path
9+
810
import pytest
911

1012
from tests.server_logs import log_server_logs_on_failure
1113

1214

15+
@pytest.fixture(scope="session")
16+
def project_root(request) -> Path:
17+
return request.config.rootpath # Project root
18+
19+
1320
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
1421
def pytest_runtest_makereport(item, call):
1522
"""

tests/integration/otdfctl_to_python/test_cli_comparison.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@
88

99
import pytest
1010

11-
from tests.support_cli_args import build_cli_decrypt_command
11+
from tests.support_cli_args import run_cli_decrypt
1212
from tests.support_otdfctl_args import (
1313
build_otdfctl_decrypt_command,
1414
build_otdfctl_encrypt_command,
1515
)
1616

1717

1818
@pytest.mark.integration
19-
def test_otdfctl_encrypt_python_decrypt(collect_server_logs, temp_credentials_file):
19+
def test_otdfctl_encrypt_python_decrypt(
20+
collect_server_logs, temp_credentials_file, project_root
21+
):
2022
"""Integration test that uses otdfctl for encryption and the Python CLI for decryption"""
2123

2224
# Create temporary directory for work
@@ -88,17 +90,11 @@ def test_otdfctl_encrypt_python_decrypt(collect_server_logs, temp_credentials_fi
8890
)
8991

9092
# Run our Python CLI decrypt on the same TDF
91-
cli_decrypt_cmd = build_cli_decrypt_command(
93+
cli_decrypt_result = run_cli_decrypt(
9294
creds_file=temp_credentials_file,
9395
input_file=otdfctl_tdf_output,
9496
output_file=cli_decrypt_output,
95-
)
96-
97-
cli_decrypt_result = subprocess.run(
98-
cli_decrypt_cmd,
99-
capture_output=True,
100-
text=True,
101-
cwd=Path(__file__).parent.parent,
97+
cwd=project_root,
10298
)
10399

104100
# Check that our CLI succeeded

tests/integration/otdfctl_to_python/test_cli_decrypt.py

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@
1010
import pytest
1111

1212
from tests.support_cli_args import (
13-
build_cli_decrypt_command,
13+
run_cli_decrypt,
1414
)
15+
from tests.support_common import handle_subprocess_error
1516

1617
logger = logging.getLogger(__name__)
1718

1819

1920
@pytest.mark.integration
20-
def test_cli_decrypt_v4_2_2_vs_v4_3_1(all_target_mode_tdf_files, temp_credentials_file):
21+
def test_cli_decrypt_v4_2_2_vs_v4_3_1(
22+
all_target_mode_tdf_files, temp_credentials_file, collect_server_logs, project_root
23+
):
2124
"""
2225
Test Python CLI decrypt with various TDF versions created by otdfctl.
2326
"""
@@ -31,10 +34,14 @@ def test_cli_decrypt_v4_2_2_vs_v4_3_1(all_target_mode_tdf_files, temp_credential
3134
v4_3_1_tdf = v4_3_1_files[file_type]
3235

3336
# Decrypt v4.2.2 TDF
34-
v4_2_2_output = _run_cli_decrypt(v4_2_2_tdf, temp_credentials_file)
37+
v4_2_2_output = _run_cli_decrypt(
38+
v4_2_2_tdf, temp_credentials_file, project_root, collect_server_logs
39+
)
3540

3641
# Decrypt v4.3.1 TDF
37-
v4_3_1_output = _run_cli_decrypt(v4_3_1_tdf, temp_credentials_file)
42+
v4_3_1_output = _run_cli_decrypt(
43+
v4_3_1_tdf, temp_credentials_file, project_root, collect_server_logs
44+
)
3845

3946
# Both should succeed and produce output files
4047
assert v4_2_2_output is not None, f"Failed to decrypt v4.2.2 {file_type} TDF"
@@ -75,7 +82,7 @@ def test_cli_decrypt_v4_2_2_vs_v4_3_1(all_target_mode_tdf_files, temp_credential
7582

7683
@pytest.mark.integration
7784
def test_cli_decrypt_different_file_types(
78-
all_target_mode_tdf_files, temp_credentials_file
85+
all_target_mode_tdf_files, temp_credentials_file, collect_server_logs, project_root
7986
):
8087
"""
8188
Test CLI decrypt with different file types.
@@ -98,7 +105,9 @@ def test_cli_decrypt_different_file_types(
98105
tdf_path = tdf_files[file_type]
99106

100107
# Decrypt the TDF
101-
output_file = _run_cli_decrypt(tdf_path, temp_credentials_file)
108+
output_file = _run_cli_decrypt(
109+
tdf_path, temp_credentials_file, project_root, collect_server_logs
110+
)
102111

103112
assert output_file is not None, f"Failed to decrypt {file_type} TDF"
104113
assert output_file.exists(), (
@@ -136,7 +145,9 @@ def test_cli_decrypt_different_file_types(
136145
output_file.unlink()
137146

138147

139-
def _run_cli_decrypt(tdf_path: Path, creds_file: Path) -> Path | None:
148+
def _run_cli_decrypt(
149+
tdf_path: Path, creds_file: Path, cwd: Path, collect_server_logs
150+
) -> Path | None:
140151
"""
141152
Helper function to run Python CLI decrypt command and return the output file path.
142153
@@ -148,25 +159,20 @@ def _run_cli_decrypt(tdf_path: Path, creds_file: Path) -> Path | None:
148159

149160
try:
150161
# Build CLI command
151-
cmd = build_cli_decrypt_command(
162+
cli_decrypt_result = run_cli_decrypt(
152163
creds_file=creds_file,
153164
input_file=tdf_path,
154165
output_file=output_path,
166+
cwd=cwd,
155167
)
156168

157-
# Run the CLI command
158-
result = subprocess.run(
159-
cmd,
160-
capture_output=True,
161-
text=True,
162-
check=True,
163-
cwd=Path(__file__).parent.parent.parent, # Project root
169+
# Fail fast on errors
170+
handle_subprocess_error(
171+
result=cli_decrypt_result,
172+
collect_server_logs=collect_server_logs,
173+
scenario_name="Python CLI decrypt",
164174
)
165175

166-
logger.debug(f"CLI decrypt succeeded for {tdf_path}")
167-
if result.stdout:
168-
logger.debug(f"CLI stdout: {result.stdout}")
169-
170176
return output_path
171177

172178
except subprocess.CalledProcessError as e:

tests/integration/otdfctl_to_python/test_cli_inspect.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212

1313

1414
@pytest.mark.integration
15-
def test_cli_inspect_v4_2_2_vs_v4_3_1(all_target_mode_tdf_files, temp_credentials_file):
15+
def test_cli_inspect_v4_2_2_vs_v4_3_1(
16+
all_target_mode_tdf_files, temp_credentials_file, project_root
17+
):
1618
"""
1719
Test Python CLI inspect with various TDF versions created by otdfctl.
1820
"""
@@ -26,10 +28,10 @@ def test_cli_inspect_v4_2_2_vs_v4_3_1(all_target_mode_tdf_files, temp_credential
2628
v4_3_1_tdf = v4_3_1_files[file_type]
2729

2830
# Inspect v4.2.2 TDF
29-
v4_2_2_result = run_cli_inspect(v4_2_2_tdf, temp_credentials_file)
31+
v4_2_2_result = run_cli_inspect(v4_2_2_tdf, temp_credentials_file, project_root)
3032

3133
# Inspect v4.3.1 TDF
32-
v4_3_1_result = run_cli_inspect(v4_3_1_tdf, temp_credentials_file)
34+
v4_3_1_result = run_cli_inspect(v4_3_1_tdf, temp_credentials_file, project_root)
3335

3436
# Both should succeed
3537
assert v4_2_2_result is not None, f"Failed to inspect v4.2.2 {file_type} TDF"
@@ -79,8 +81,7 @@ def test_cli_inspect_v4_2_2_vs_v4_3_1(all_target_mode_tdf_files, temp_credential
7981

8082
@pytest.mark.integration
8183
def test_cli_inspect_different_file_types(
82-
all_target_mode_tdf_files,
83-
temp_credentials_file,
84+
all_target_mode_tdf_files, temp_credentials_file, project_root
8485
):
8586
"""
8687
Test CLI inspect with different file types.
@@ -102,7 +103,7 @@ def test_cli_inspect_different_file_types(
102103
tdf_path = tdf_files[file_type]
103104

104105
# Inspect the TDF
105-
result = run_cli_inspect(tdf_path, temp_credentials_file)
106+
result = run_cli_inspect(tdf_path, temp_credentials_file, project_root)
106107

107108
assert result is not None, (
108109
f"Failed to inspect {file_type} TDF, TDF version {version}"

tests/integration/test_cli_integration.py

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88

99
import pytest
1010

11-
from tests.support_cli_args import build_cli_decrypt_command, build_cli_encrypt_command
11+
from tests.support_cli_args import (
12+
build_cli_encrypt_command,
13+
run_cli_decrypt,
14+
)
1215
from tests.support_common import (
1316
get_testing_environ,
1417
handle_subprocess_error,
@@ -20,7 +23,9 @@
2023

2124

2225
@pytest.mark.integration
23-
def test_cli_decrypt_otdfctl_tdf(collect_server_logs, temp_credentials_file):
26+
def test_cli_decrypt_otdfctl_tdf(
27+
collect_server_logs, temp_credentials_file, project_root
28+
):
2429
"""
2530
Test that the Python CLI can successfully decrypt TDF files created by otdfctl.
2631
"""
@@ -68,19 +73,12 @@ def test_cli_decrypt_otdfctl_tdf(collect_server_logs, temp_credentials_file):
6873
assert otdfctl_tdf_output.exists(), "otdfctl did not create TDF file"
6974
assert otdfctl_tdf_output.stat().st_size > 0, "otdfctl created empty TDF file"
7075

71-
cli_decrypt_cmd = build_cli_decrypt_command(
76+
# Run our Python CLI decrypt on the otdfctl-created TDF
77+
cli_decrypt_result = run_cli_decrypt(
7278
creds_file=temp_credentials_file,
7379
input_file=otdfctl_tdf_output,
7480
output_file=cli_decrypt_output,
75-
)
76-
77-
# Run our Python CLI decrypt on the otdfctl-created TDF
78-
cli_decrypt_result = subprocess.run(
79-
cli_decrypt_cmd,
80-
capture_output=True,
81-
text=True,
82-
cwd=Path(__file__).parent.parent,
83-
env=get_testing_environ(),
81+
cwd=project_root,
8482
)
8583

8684
# Fail fast on errors
@@ -107,7 +105,9 @@ def test_cli_decrypt_otdfctl_tdf(collect_server_logs, temp_credentials_file):
107105

108106

109107
@pytest.mark.integration
110-
def test_otdfctl_decrypt_comparison(collect_server_logs, temp_credentials_file):
108+
def test_otdfctl_decrypt_comparison(
109+
collect_server_logs, temp_credentials_file, project_root
110+
):
111111
"""
112112
Test comparative decryption between otdfctl and Python CLI on the same TDF.
113113
"""
@@ -178,19 +178,11 @@ def test_otdfctl_decrypt_comparison(collect_server_logs, temp_credentials_file):
178178
scenario_name="otdfctl decrypt",
179179
)
180180

181-
cli_decrypt_cmd = build_cli_decrypt_command(
181+
cli_decrypt_result = run_cli_decrypt(
182182
creds_file=temp_credentials_file,
183183
input_file=otdfctl_tdf_output,
184184
output_file=cli_decrypt_output,
185-
)
186-
187-
# Run our Python CLI decrypt on the same TDF
188-
cli_decrypt_result = subprocess.run(
189-
cli_decrypt_cmd,
190-
capture_output=True,
191-
text=True,
192-
cwd=Path(__file__).parent.parent,
193-
env=get_testing_environ(),
185+
cwd=project_root,
194186
)
195187

196188
# Fail fast on errors
@@ -344,7 +336,9 @@ def test_otdfctl_encrypt_decrypt_roundtrip(collect_server_logs, temp_credentials
344336

345337

346338
@pytest.mark.integration
347-
def test_cli_encrypt_integration(collect_server_logs, temp_credentials_file):
339+
def test_cli_encrypt_integration(
340+
collect_server_logs, temp_credentials_file, project_root
341+
):
348342
"""Integration test comparing our CLI with otdfctl"""
349343

350344
# Create temporary directory for work
@@ -390,7 +384,7 @@ def test_cli_encrypt_integration(collect_server_logs, temp_credentials_file):
390384

391385
# Run our Python CLI encrypt
392386
cli_result = subprocess.run(
393-
cli_cmd, capture_output=True, text=True, cwd=Path(__file__).parent.parent
387+
cli_cmd, capture_output=True, text=True, cwd=project_root
394388
)
395389

396390
# Fail fast on errors

0 commit comments

Comments
 (0)