Skip to content

Commit 12f04d4

Browse files
committed
fix: Refactor 2
1 parent 2ca2298 commit 12f04d4

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

tests/test_unit_tests.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -774,16 +774,16 @@ def test_sign_file(self):
774774

775775
def test_sign_file_callback_signer(self):
776776
"""Test signing a file using the sign_file method."""
777-
# Create a temporary directory for the test
777+
778778
temp_dir = tempfile.mkdtemp()
779+
779780
try:
780-
# Create a temporary output file path
781781
output_path = os.path.join(temp_dir, "signed_output.jpg")
782782

783783
# Use the sign_file method
784784
builder = Builder(self.manifestDefinition)
785785

786-
# Create signer with callback
786+
# Create signer with callback using create_signer function
787787
signer = create_signer(
788788
callback=self.callback_signer_es256,
789789
alg=SigningAlg.ES256,
@@ -800,7 +800,7 @@ def test_sign_file_callback_signer(self):
800800
# Verify the output file was created
801801
self.assertTrue(os.path.exists(output_path))
802802

803-
# Verify we got both result and manifest bytes
803+
# Verify results
804804
self.assertIsInstance(result, int)
805805
self.assertIsInstance(manifest_bytes, bytes)
806806
self.assertGreater(len(manifest_bytes), 0)
@@ -813,18 +813,17 @@ def test_sign_file_callback_signer(self):
813813
self.assertNotIn("validation_status", json_data)
814814

815815
finally:
816-
# Clean up the temporary directory
817816
shutil.rmtree(temp_dir)
818817

819-
def test_sign_file_callback_signer_from_callback(self):
818+
def test_builder_sign_file_callback_signer_from_callback(self):
820819
"""Test signing a file using the sign_file method with Signer.from_callback."""
821-
# Create a temporary directory for the test
820+
822821
temp_dir = tempfile.mkdtemp()
823822
try:
824-
# Create a temporary output file path
823+
825824
output_path = os.path.join(temp_dir, "signed_output_from_callback.jpg")
826825

827-
# Use the sign_file method
826+
# Will use the sign_file method
828827
builder = Builder(self.manifestDefinition)
829828

830829
# Create signer with callback using Signer.from_callback
@@ -844,7 +843,7 @@ def test_sign_file_callback_signer_from_callback(self):
844843
# Verify the output file was created
845844
self.assertTrue(os.path.exists(output_path))
846845

847-
# Verify we got both result and manifest bytes
846+
# Verify results
848847
self.assertIsInstance(result, int)
849848
self.assertIsInstance(manifest_bytes, bytes)
850849
self.assertGreater(len(manifest_bytes), 0)
@@ -857,13 +856,13 @@ def test_sign_file_callback_signer_from_callback(self):
857856
self.assertNotIn("validation_status", json_data)
858857

859858
finally:
860-
# Clean up the temporary directory
861859
shutil.rmtree(temp_dir)
862860

863-
def test_sign_file_using_callback_signer(self):
861+
def test_sign_file_using_callback_signer_overloads(self):
864862
"""Test signing a file using the sign_file function with a Signer object."""
865863
# Create a temporary directory for the test
866864
temp_dir = tempfile.mkdtemp()
865+
867866
try:
868867
# Create a temporary output file path
869868
output_path = os.path.join(temp_dir, "signed_output_callback.jpg")
@@ -876,7 +875,7 @@ def test_sign_file_using_callback_signer(self):
876875
tsa_url="http://timestamp.digicert.com"
877876
)
878877

879-
# Test with return_manifest_as_bytes=False (default) - should return JSON string
878+
# Overload that returns a JSON string
880879
result_json = sign_file(
881880
self.testPath,
882881
output_path,
@@ -888,17 +887,16 @@ def test_sign_file_using_callback_signer(self):
888887
# Verify the output file was created
889888
self.assertTrue(os.path.exists(output_path))
890889

891-
# Verify the result is a JSON string (not binary data)
890+
# Verify the result is JSON
892891
self.assertIsInstance(result_json, str)
893892
self.assertGreater(len(result_json), 0)
894893

895-
# Parse the JSON and verify it contains expected content
896894
manifest_data = json.loads(result_json)
897895
self.assertIn("manifests", manifest_data)
898896
self.assertIn("active_manifest", manifest_data)
899897

900-
# Test with return_manifest_as_bytes=True - should return bytes
901898
output_path_bytes = os.path.join(temp_dir, "signed_output_callback_bytes.jpg")
899+
# Overload that returns bytes
902900
result_bytes = sign_file(
903901
self.testPath,
904902
output_path_bytes,
@@ -910,7 +908,7 @@ def test_sign_file_using_callback_signer(self):
910908
# Verify the output file was created
911909
self.assertTrue(os.path.exists(output_path_bytes))
912910

913-
# Verify the result is bytes (not JSON string)
911+
# Verify the result is bytes
914912
self.assertIsInstance(result_bytes, bytes)
915913
self.assertGreater(len(result_bytes), 0)
916914

@@ -922,7 +920,6 @@ def test_sign_file_using_callback_signer(self):
922920
self.assertNotIn("validation_status", file_manifest_json)
923921

924922
finally:
925-
# Clean up the temporary directory
926923
shutil.rmtree(temp_dir)
927924

928925
def test_sign_file_overloads(self):

0 commit comments

Comments
 (0)