Skip to content

Commit 6fa6ca8

Browse files
committed
fix: add the tests with settings
1 parent 6aab2e6 commit 6fa6ca8

File tree

1 file changed

+97
-13
lines changed

1 file changed

+97
-13
lines changed

tests/test_unit_tests.py

Lines changed: 97 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ def setUp(self):
749749
"version": "0.0.1",
750750
}],
751751
# claim version 2 is the default
752-
# "claim_version": 2,
752+
"claim_version": 2,
753753
"format": "image/jpeg",
754754
"title": "Python Test Image V2",
755755
"ingredients": [],
@@ -2324,32 +2324,48 @@ def test_builder_state_with_invalid_native_pointer(self):
23242324
with self.assertRaises(Error):
23252325
builder.set_no_embed()
23262326

2327-
def test_builder_minimal_manifest_add_actions_and_sign(self):
2327+
def test_builder_add_action_to_manifest_no_auto_add(self):
23282328
# For testing, remove auto-added actions
2329-
load_settings('{"builder":{"actions":{"auto_placed_action":{"enabled": false}}}}')
2330-
load_settings('{"builder":{"actions":{"auto_opened_action":{"enabled": false}}}}')
2331-
load_settings('{"builder":{"actions":{"auto_created_action":{"enabled": false}}}}')
2329+
load_settings('{"builder":{"actions":{"auto_placed_action":{"enabled":false}}}}')
2330+
load_settings('{"builder":{"actions":{"auto_opened_action":{"enabled":false}}}}')
2331+
load_settings('{"builder":{"actions":{"auto_created_action":{"enabled":false}}}}')
23322332

23332333
initial_manifest_definition = {
23342334
"claim_generator": "python_test",
23352335
"claim_generator_info": [{
23362336
"name": "python_test",
23372337
"version": "0.0.1",
23382338
}],
2339+
# claim version 2 is the default
2340+
"claim_version": 2,
23392341
"format": "image/jpeg",
23402342
"title": "Python Test Image V2",
2343+
"ingredients": [],
2344+
"assertions": [
2345+
{
2346+
"label": "c2pa.actions",
2347+
"data": {
2348+
"actions": [
2349+
{
2350+
"action": "c2pa.created",
2351+
"digitalSourceType": "http://cv.iptc.org/newscodes/digitalsourcetype/digitalCreation"
2352+
}
2353+
]
2354+
}
2355+
}
2356+
]
23412357
}
2342-
builder = Builder.from_json(self.manifestDefinition)
2358+
builder = Builder.from_json(initial_manifest_definition)
23432359

2344-
builder.add_action('{ "action": "c2pa.created", "digitalSourceType": "http://cv.iptc.org/newscodes/digitalsourcetype/digitalCreation"}')
2360+
action_json = '{"action": "c2pa.color_adjustments", "parameters": {"name": "brightnesscontrast"}}'
2361+
builder.add_action(action_json)
23452362

23462363
with open(self.testPath2, "rb") as file:
23472364
output = io.BytesIO(bytearray())
23482365
builder.sign(self.signer, "image/jpeg", file, output)
23492366
output.seek(0)
23502367
reader = Reader("image/jpeg", output)
23512368
json_data = reader.json()
2352-
print(json_data)
23532369
manifest_data = json.loads(json_data)
23542370

23552371
# Verify active manifest exists
@@ -2365,16 +2381,84 @@ def test_builder_minimal_manifest_add_actions_and_sign(self):
23652381
self.assertIn("assertions", active_manifest)
23662382
assertions = active_manifest["assertions"]
23672383

2368-
# Find the c2pa.actions.v2 assertion
2384+
# Find the c2pa.actions.v2 assertion to check what we added
23692385
actions_assertion = None
23702386
for assertion in assertions:
23712387
if assertion.get("label") == "c2pa.actions.v2":
23722388
actions_assertion = assertion
23732389
break
23742390

23752391
self.assertIsNotNone(actions_assertion)
2392+
self.assertIn("data", actions_assertion)
2393+
assertion_data = actions_assertion["data"]
2394+
# Verify the manifest now contains actions
2395+
self.assertIn("actions", assertion_data)
2396+
actions = assertion_data["actions"]
2397+
# Verify "c2pa.color_adjustments" action exists anywhere in the actions array
2398+
created_action_found = False
2399+
for action in actions:
2400+
if action.get("action") == "c2pa.color_adjustments":
2401+
created_action_found = True
2402+
break
23762403

2377-
# Check what we added is there
2404+
self.assertTrue(created_action_found)
2405+
2406+
builder.close()
2407+
2408+
# Reset settings
2409+
load_settings('{"builder":{"actions":{"auto_placed_action":{"enabled":true}}}}')
2410+
load_settings('{"builder":{"actions":{"auto_opened_action":{"enabled":true}}}}')
2411+
load_settings('{"builder":{"actions":{"auto_created_action":{"enabled":true}}}}')
2412+
2413+
2414+
def test_builder_minimal_manifest_add_actions_and_sign_no_auto_add(self):
2415+
# For testing, remove auto-added actions
2416+
load_settings('{"builder":{"actions":{"auto_placed_action":{"enabled":false}}}}')
2417+
load_settings('{"builder":{"actions":{"auto_opened_action":{"enabled":false}}}}')
2418+
load_settings('{"builder":{"actions":{"auto_created_action":{"enabled":false}}}}')
2419+
2420+
initial_manifest_definition = {
2421+
"claim_generator": "python_test",
2422+
"claim_generator_info": [{
2423+
"name": "python_test",
2424+
"version": "0.0.1",
2425+
}],
2426+
"format": "image/jpeg",
2427+
"title": "Python Test Image V2",
2428+
}
2429+
2430+
builder = Builder.from_json(initial_manifest_definition)
2431+
builder.add_action('{ "action": "c2pa.created", "digitalSourceType": "http://cv.iptc.org/newscodes/digitalsourcetype/digitalCreation"}')
2432+
2433+
with open(self.testPath2, "rb") as file:
2434+
output = io.BytesIO(bytearray())
2435+
builder.sign(self.signer, "image/jpeg", file, output)
2436+
output.seek(0)
2437+
reader = Reader("image/jpeg", output)
2438+
json_data = reader.json()
2439+
manifest_data = json.loads(json_data)
2440+
2441+
# Verify active manifest exists
2442+
self.assertIn("active_manifest", manifest_data)
2443+
active_manifest_id = manifest_data["active_manifest"]
2444+
2445+
# Verify active manifest object exists
2446+
self.assertIn("manifests", manifest_data)
2447+
self.assertIn(active_manifest_id, manifest_data["manifests"])
2448+
active_manifest = manifest_data["manifests"][active_manifest_id]
2449+
2450+
# Verify assertions object exists in active manifest
2451+
self.assertIn("assertions", active_manifest)
2452+
assertions = active_manifest["assertions"]
2453+
2454+
# Find the c2pa.actions.v2 assertion to look for what we added
2455+
actions_assertion = None
2456+
for assertion in assertions:
2457+
if assertion.get("label") == "c2pa.actions.v2":
2458+
actions_assertion = assertion
2459+
break
2460+
2461+
self.assertIsNotNone(actions_assertion)
23782462
self.assertIn("data", actions_assertion)
23792463
assertion_data = actions_assertion["data"]
23802464
# Verify the manifest now contains actions
@@ -2392,9 +2476,9 @@ def test_builder_minimal_manifest_add_actions_and_sign(self):
23922476
builder.close()
23932477

23942478
# Reset settings
2395-
load_settings('{"builder":{"actions":{"auto_placed_action":{"enabled": true}}}}')
2396-
load_settings('{"builder":{"actions":{"auto_opened_action":{"enabled": true}}}}')
2397-
load_settings('{"builder":{"actions":{"auto_created_action":{"enabled": true}}}}')
2479+
load_settings('{"builder":{"actions":{"auto_placed_action":{"enabled":true}}}}')
2480+
load_settings('{"builder":{"actions":{"auto_opened_action":{"enabled":true}}}}')
2481+
load_settings('{"builder":{"actions":{"auto_created_action":{"enabled":true}}}}')
23982482

23992483

24002484
class TestStream(unittest.TestCase):

0 commit comments

Comments
 (0)