Skip to content

Commit eb070d1

Browse files
committed
chore: cleanup for mirrored workflows
1 parent 0a391e6 commit eb070d1

File tree

4 files changed

+24
-46
lines changed

4 files changed

+24
-46
lines changed

tests/integration/otdfctl_to_python/test_cli_comparison.py

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
import pytest
99

1010
from tests.support_cli_args import run_cli_decrypt
11-
from tests.support_common import handle_subprocess_error
11+
from tests.support_common import (
12+
handle_subprocess_error,
13+
validate_plaintext_file_created,
14+
validate_tdf3_file,
15+
)
1216
from tests.support_otdfctl_args import (
1317
run_otdfctl_decrypt_command,
1418
run_otdfctl_encrypt_command,
@@ -88,15 +92,8 @@ def test_otdfctl_encrypt_python_decrypt(
8892
scenario_name="Python CLI decrypt",
8993
)
9094

91-
# Verify both decrypted files were created
92-
assert otdfctl_decrypt_output.exists(), "otdfctl did not create decrypted file"
93-
assert otdfctl_decrypt_output.stat().st_size > 0, (
94-
"otdfctl created empty decrypted file"
95-
)
96-
assert cli_decrypt_output.exists(), "Python CLI did not create decrypted file"
97-
assert cli_decrypt_output.stat().st_size > 0, (
98-
"Python CLI created empty decrypted file"
99-
)
95+
validate_plaintext_file_created(path=otdfctl_decrypt_output, scenario="otdfctl")
96+
validate_plaintext_file_created(path=cli_decrypt_output, scenario="Python CLI")
10097

10198
# Verify both tools produce the same decrypted content
10299
with open(otdfctl_decrypt_output) as f:
@@ -162,13 +159,7 @@ def test_otdfctl_encrypt_otdfctl_decrypt(collect_server_logs, temp_credentials_f
162159
)
163160

164161
# Verify the TDF file was created
165-
assert otdfctl_tdf_output.exists(), "otdfctl did not create TDF file"
166-
assert otdfctl_tdf_output.stat().st_size > 0, "otdfctl created empty TDF file"
167-
168-
# Verify TDF file has correct ZIP signature
169-
with open(otdfctl_tdf_output, "rb") as f:
170-
tdf_header = f.read(4)
171-
assert tdf_header == b"PK\x03\x04", "otdfctl output is not a valid ZIP file"
162+
validate_tdf3_file(tdf_path=otdfctl_tdf_output, tool_name="otdfctl")
172163

173164
# Run otdfctl decrypt
174165
otdfctl_decrypt_result = run_otdfctl_decrypt_command(
@@ -185,11 +176,7 @@ def test_otdfctl_encrypt_otdfctl_decrypt(collect_server_logs, temp_credentials_f
185176
scenario_name="otdfctl decrypt",
186177
)
187178

188-
# Verify the decrypted file was created
189-
assert otdfctl_decrypt_output.exists(), "otdfctl did not create decrypted file"
190-
assert otdfctl_decrypt_output.stat().st_size > 0, (
191-
"otdfctl created empty decrypted file"
192-
)
179+
validate_plaintext_file_created(path=otdfctl_decrypt_output, scenario="otdfctl")
193180

194181
# Verify the decrypted content matches the original
195182
with open(otdfctl_decrypt_output) as f:

tests/integration/test_cli_integration.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from tests.support_common import (
1212
compare_tdf3_file_size,
1313
handle_subprocess_error,
14+
validate_plaintext_file_created,
1415
validate_tdf3_file,
1516
)
1617
from tests.support_otdfctl_args import (
@@ -78,10 +79,8 @@ def test_cli_decrypt_otdfctl_tdf(
7879
scenario_name="Python CLI decrypt",
7980
)
8081

81-
# Verify the decrypted file was created
82-
assert cli_decrypt_output.exists(), "Python CLI did not create decrypted file"
83-
assert cli_decrypt_output.stat().st_size > 0, (
84-
"Python CLI created empty decrypted file"
82+
validate_plaintext_file_created(
83+
path=cli_decrypt_output, scenario="Python decrypt"
8584
)
8685

8786
# Verify the content matches the original
@@ -168,15 +167,8 @@ def test_otdfctl_decrypt_comparison(
168167
scenario_name="Python CLI decrypt",
169168
)
170169

171-
# Verify both decrypted files were created
172-
assert otdfctl_decrypt_output.exists(), "otdfctl did not create decrypted file"
173-
assert otdfctl_decrypt_output.stat().st_size > 0, (
174-
"otdfctl created empty decrypted file"
175-
)
176-
assert cli_decrypt_output.exists(), "Python CLI did not create decrypted file"
177-
assert cli_decrypt_output.stat().st_size > 0, (
178-
"Python CLI created empty decrypted file"
179-
)
170+
validate_plaintext_file_created(path=otdfctl_decrypt_output, scenario="otdfctl")
171+
validate_plaintext_file_created(path=cli_decrypt_output, scenario="Python CL")
180172

181173
# Verify both tools produce the same decrypted content
182174
with open(otdfctl_decrypt_output) as f:
@@ -261,11 +253,7 @@ def test_otdfctl_encrypt_decrypt_roundtrip(collect_server_logs, temp_credentials
261253
scenario_name="otdfctl decrypt",
262254
)
263255

264-
# Verify the decrypted file was created
265-
assert otdfctl_decrypt_output.exists(), "otdfctl did not create decrypted file"
266-
assert otdfctl_decrypt_output.stat().st_size > 0, (
267-
"otdfctl created empty decrypted file"
268-
)
256+
validate_plaintext_file_created(path=otdfctl_decrypt_output, scenario="otdfctl")
269257

270258
# Verify the decrypted content matches the original
271259
with open(otdfctl_decrypt_output) as f:

tests/integration/test_cli_tdf_validation.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
)
1717
from tests.support_common import (
1818
handle_subprocess_error,
19+
validate_plaintext_file_created,
1920
validate_tdf3_file,
2021
)
2122
from tests.support_otdfctl_args import (
@@ -249,9 +250,7 @@ def _run_otdfctl_decrypt(
249250
otdfctl_decrypt_result, collect_server_logs, "otdfctl decrypt"
250251
)
251252

252-
# Verify the decrypted file was created
253-
assert decrypt_output.exists(), "otdfctl did not create decrypted file"
254-
assert decrypt_output.stat().st_size > 0, "otdfctl created empty decrypted file"
253+
validate_plaintext_file_created(path=decrypt_output, scenario="otdfctl")
255254

256255
# Verify the decrypted content matches expected
257256
with open(decrypt_output) as f:
@@ -285,9 +284,7 @@ def _run_python_cli_decrypt(
285284
python_decrypt_result, collect_server_logs, "Python CLI decrypt"
286285
)
287286

288-
# Verify the decrypted file was created
289-
assert decrypt_output.exists(), "Python CLI did not create decrypted file"
290-
assert decrypt_output.stat().st_size > 0, "Python CLI created empty decrypted file"
287+
validate_plaintext_file_created(path=decrypt_output, scenario="Python CLI")
291288

292289
# Verify the decrypted content matches expected
293290
with open(decrypt_output) as f:

tests/support_common.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ def validate_tdf3_file(tdf_path: Path, tool_name: str) -> None:
6060
assert tdf_header == b"PK\x03\x04", f"{tool_name} output is not a valid ZIP file"
6161

6262

63+
def validate_plaintext_file_created(path: Path, scenario: str) -> None:
64+
"""Validate that a non-empty file was created"""
65+
assert path.exists(), f"{scenario=} did not create decrypted file"
66+
assert path.stat().st_size > 0, f"{scenario=} created empty decrypted file"
67+
68+
6369
def compare_tdf3_file_size(otdfctl_tdf_path: Path, py_cli_tdf_path: Path) -> None:
6470
"""Compare the file sizes of two TDF files (tdf_type="tdf3"), assert within 30% of each other."""
6571
size_otdfctl_tdf = otdfctl_tdf_path.stat().st_size

0 commit comments

Comments
 (0)