Skip to content

Commit e414eba

Browse files
committed
fix: Move tests
1 parent e5d6d5b commit e414eba

File tree

1 file changed

+97
-55
lines changed

1 file changed

+97
-55
lines changed

tests/test_unit_tests.py

Lines changed: 97 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,61 +1346,6 @@ def test_signing_manifest_v2(self):
13461346

13471347
output.close()
13481348

1349-
def test_builder_add_ingredient_from_file_path(self):
1350-
"""Test Builder class add_ingredient_from_file_path method."""
1351-
1352-
# Suppress the specific deprecation warning for this test, as this is a legacy method
1353-
with warnings.catch_warnings():
1354-
warnings.simplefilter("ignore", DeprecationWarning)
1355-
1356-
builder = Builder.from_json(self.manifestDefinition)
1357-
1358-
# Test adding ingredient from file path
1359-
ingredient_json = '{"test": "ingredient_from_file_path"}'
1360-
builder.add_ingredient_from_file_path(ingredient_json, "image/jpeg", self.testPath)
1361-
1362-
builder.close()
1363-
1364-
def test_builder_sign_with_ingredient_from_file(self):
1365-
"""Test Builder class operations with an ingredient added from file path."""
1366-
1367-
builder = Builder.from_json(self.manifestDefinition)
1368-
1369-
# Test adding ingredient from file path
1370-
ingredient_json = '{"title": "Test Ingredient From File"}'
1371-
# Suppress the specific deprecation warning for this test, as this is a legacy method
1372-
with warnings.catch_warnings():
1373-
warnings.simplefilter("ignore", DeprecationWarning)
1374-
builder.add_ingredient_from_file_path(ingredient_json, "image/jpeg", self.testPath3)
1375-
1376-
with open(self.testPath2, "rb") as file:
1377-
output = io.BytesIO(bytearray())
1378-
builder.sign(self.signer, "image/jpeg", file, output)
1379-
output.seek(0)
1380-
reader = Reader("image/jpeg", output)
1381-
json_data = reader.json()
1382-
manifest_data = json.loads(json_data)
1383-
1384-
# Verify active manifest exists
1385-
self.assertIn("active_manifest", manifest_data)
1386-
active_manifest_id = manifest_data["active_manifest"]
1387-
1388-
# Verify active manifest object exists
1389-
self.assertIn("manifests", manifest_data)
1390-
self.assertIn(active_manifest_id, manifest_data["manifests"])
1391-
active_manifest = manifest_data["manifests"][active_manifest_id]
1392-
1393-
# Verify ingredients array exists in active manifest
1394-
self.assertIn("ingredients", active_manifest)
1395-
self.assertIsInstance(active_manifest["ingredients"], list)
1396-
self.assertTrue(len(active_manifest["ingredients"]) > 0)
1397-
1398-
# Verify the first ingredient's title matches what we set
1399-
first_ingredient = active_manifest["ingredients"][0]
1400-
self.assertEqual(first_ingredient["title"], "Test Ingredient From File")
1401-
1402-
builder.close()
1403-
14041349

14051350
class TestStream(unittest.TestCase):
14061351
def setUp(self):
@@ -1549,6 +1494,48 @@ def setUp(self):
15491494

15501495
self.data_dir = FIXTURES_DIR
15511496
self.testPath = DEFAULT_TEST_FILE
1497+
self.testPath2 = INGREDIENT_TEST_FILE
1498+
self.testPath3 = os.path.join(self.data_dir, "A_thumbnail.jpg")
1499+
1500+
# Load test certificates and key
1501+
with open(os.path.join(self.data_dir, "es256_certs.pem"), "rb") as cert_file:
1502+
self.certs = cert_file.read()
1503+
with open(os.path.join(self.data_dir, "es256_private.key"), "rb") as key_file:
1504+
self.key = key_file.read()
1505+
1506+
# Create a local ES256 signer with certs and a timestamp server
1507+
self.signer_info = C2paSignerInfo(
1508+
alg=b"es256",
1509+
sign_cert=self.certs,
1510+
private_key=self.key,
1511+
ta_url=b"http://timestamp.digicert.com"
1512+
)
1513+
self.signer = Signer.from_info(self.signer_info)
1514+
1515+
# Define a manifest as a dictionary
1516+
self.manifestDefinition = {
1517+
"claim_generator": "python_internals_test",
1518+
"claim_generator_info": [{
1519+
"name": "python_internals_test",
1520+
"version": "0.0.1",
1521+
}],
1522+
"claim_version": 1,
1523+
"format": "image/jpeg",
1524+
"title": "Python Test Image",
1525+
"ingredients": [],
1526+
"assertions": [
1527+
{
1528+
"label": "c2pa.actions",
1529+
"data": {
1530+
"actions": [
1531+
{
1532+
"action": "c2pa.opened"
1533+
}
1534+
]
1535+
}
1536+
}
1537+
]
1538+
}
15521539

15531540
# Create temp directory for tests
15541541
self.temp_data_dir = os.path.join(self.data_dir, "temp_data")
@@ -1659,6 +1646,61 @@ def test_sign_file(self):
16591646
if os.path.exists(output_path):
16601647
os.remove(output_path)
16611648

1649+
def test_builder_sign_with_ingredient_from_file(self):
1650+
"""Test Builder class operations with an ingredient added from file path."""
1651+
1652+
builder = Builder.from_json(self.manifestDefinition)
1653+
1654+
# Test adding ingredient from file path
1655+
ingredient_json = '{"title": "Test Ingredient From File"}'
1656+
# Suppress the specific deprecation warning for this test, as this is a legacy method
1657+
with warnings.catch_warnings():
1658+
warnings.simplefilter("ignore", DeprecationWarning)
1659+
builder.add_ingredient_from_file_path(ingredient_json, "image/jpeg", self.testPath3)
1660+
1661+
with open(self.testPath2, "rb") as file:
1662+
output = io.BytesIO(bytearray())
1663+
builder.sign(self.signer, "image/jpeg", file, output)
1664+
output.seek(0)
1665+
reader = Reader("image/jpeg", output)
1666+
json_data = reader.json()
1667+
manifest_data = json.loads(json_data)
1668+
1669+
# Verify active manifest exists
1670+
self.assertIn("active_manifest", manifest_data)
1671+
active_manifest_id = manifest_data["active_manifest"]
1672+
1673+
# Verify active manifest object exists
1674+
self.assertIn("manifests", manifest_data)
1675+
self.assertIn(active_manifest_id, manifest_data["manifests"])
1676+
active_manifest = manifest_data["manifests"][active_manifest_id]
1677+
1678+
# Verify ingredients array exists in active manifest
1679+
self.assertIn("ingredients", active_manifest)
1680+
self.assertIsInstance(active_manifest["ingredients"], list)
1681+
self.assertTrue(len(active_manifest["ingredients"]) > 0)
1682+
1683+
# Verify the first ingredient's title matches what we set
1684+
first_ingredient = active_manifest["ingredients"][0]
1685+
self.assertEqual(first_ingredient["title"], "Test Ingredient From File")
1686+
1687+
builder.close()
1688+
1689+
def test_builder_add_ingredient_from_file_path(self):
1690+
"""Test Builder class add_ingredient_from_file_path method."""
1691+
1692+
# Suppress the specific deprecation warning for this test, as this is a legacy method
1693+
with warnings.catch_warnings():
1694+
warnings.simplefilter("ignore", DeprecationWarning)
1695+
1696+
builder = Builder.from_json(self.manifestDefinition)
1697+
1698+
# Test adding ingredient from file path
1699+
ingredient_json = '{"test": "ingredient_from_file_path"}'
1700+
builder.add_ingredient_from_file_path(ingredient_json, "image/jpeg", self.testPath)
1701+
1702+
builder.close()
1703+
16621704

16631705
if __name__ == '__main__':
16641706
unittest.main()

0 commit comments

Comments
 (0)