@@ -2499,12 +2499,11 @@ def test_builder_add_action_to_manifest_with_auto_add(self):
24992499
25002500 builder .close ()
25012501
2502- # Reset settings
2502+ # Reset settings to default
25032503 load_settings ('{"builder":{"actions":{"auto_placed_action":{"enabled":true}}}}' )
25042504 load_settings ('{"builder":{"actions":{"auto_opened_action":{"enabled":true}}}}' )
25052505 load_settings ('{"builder":{"actions":{"auto_created_action":{"enabled":true}}}}' )
25062506
2507-
25082507 def test_builder_minimal_manifest_add_actions_and_sign_no_auto_add (self ):
25092508 # For testing, remove auto-added actions
25102509 load_settings ('{"builder":{"actions":{"auto_placed_action":{"enabled":false}}}}' )
@@ -2574,6 +2573,85 @@ def test_builder_minimal_manifest_add_actions_and_sign_no_auto_add(self):
25742573 load_settings ('{"builder":{"actions":{"auto_opened_action":{"enabled":true}}}}' )
25752574 load_settings ('{"builder":{"actions":{"auto_created_action":{"enabled":true}}}}' )
25762575
2576+ def test_builder_minimal_manifest_add_actions_and_sign_with_auto_add (self ):
2577+ # For testing, remove auto-added actions
2578+ load_settings ('{"builder":{"actions":{"auto_placed_action":{"enabled":true}}}}' )
2579+ load_settings ('{"builder":{"actions":{"auto_opened_action":{"enabled":true}}}}' )
2580+ load_settings ('{"builder":{"actions":{"auto_created_action":{"enabled":true}}}}' )
2581+
2582+ initial_manifest_definition = {
2583+ "claim_generator" : "python_test" ,
2584+ "claim_generator_info" : [{
2585+ "name" : "python_test" ,
2586+ "version" : "0.0.1" ,
2587+ }],
2588+ "format" : "image/jpeg" ,
2589+ "title" : "Python Test Image V2" ,
2590+ }
2591+
2592+ builder = Builder .from_json (initial_manifest_definition )
2593+ action_json = '{"action": "c2pa.color_adjustments", "parameters": {"name": "brightnesscontrast"}}'
2594+ builder .add_action (action_json )
2595+
2596+ with open (self .testPath2 , "rb" ) as file :
2597+ output = io .BytesIO (bytearray ())
2598+ builder .sign (self .signer , "image/jpeg" , file , output )
2599+ output .seek (0 )
2600+ reader = Reader ("image/jpeg" , output )
2601+ json_data = reader .json ()
2602+ manifest_data = json .loads (json_data )
2603+
2604+ # Verify active manifest exists
2605+ self .assertIn ("active_manifest" , manifest_data )
2606+ active_manifest_id = manifest_data ["active_manifest" ]
2607+
2608+ # Verify active manifest object exists
2609+ self .assertIn ("manifests" , manifest_data )
2610+ self .assertIn (active_manifest_id , manifest_data ["manifests" ])
2611+ active_manifest = manifest_data ["manifests" ][active_manifest_id ]
2612+
2613+ # Verify assertions object exists in active manifest
2614+ self .assertIn ("assertions" , active_manifest )
2615+ assertions = active_manifest ["assertions" ]
2616+
2617+ # Find the c2pa.actions.v2 assertion to look for what we added
2618+ actions_assertion = None
2619+ for assertion in assertions :
2620+ if assertion .get ("label" ) == "c2pa.actions.v2" :
2621+ actions_assertion = assertion
2622+ break
2623+
2624+ self .assertIsNotNone (actions_assertion )
2625+ self .assertIn ("data" , actions_assertion )
2626+ assertion_data = actions_assertion ["data" ]
2627+ # Verify the manifest now contains actions
2628+ self .assertIn ("actions" , assertion_data )
2629+ actions = assertion_data ["actions" ]
2630+ # Verify "c2pa.created" action exists anywhere in the actions array
2631+ created_action_found = False
2632+ for action in actions :
2633+ if action .get ("action" ) == "c2pa.created" :
2634+ created_action_found = True
2635+ break
2636+
2637+ self .assertTrue (created_action_found )
2638+
2639+ # Verify "c2pa.color_adjustments" action also exists in the same actions array
2640+ color_adjustments_found = False
2641+ for action in actions :
2642+ if action .get ("action" ) == "c2pa.color_adjustments" :
2643+ color_adjustments_found = True
2644+ break
2645+
2646+ self .assertTrue (color_adjustments_found )
2647+
2648+ builder .close ()
2649+
2650+ # Reset settings
2651+ load_settings ('{"builder":{"actions":{"auto_placed_action":{"enabled":true}}}}' )
2652+ load_settings ('{"builder":{"actions":{"auto_opened_action":{"enabled":true}}}}' )
2653+ load_settings ('{"builder":{"actions":{"auto_created_action":{"enabled":true}}}}' )
2654+
25772655
25782656class TestStream (unittest .TestCase ):
25792657 def setUp (self ):
0 commit comments