@@ -1034,3 +1034,81 @@ def test_config_from_dryccfile(self, mock_requests):
10341034 self .assertEqual (release .failed , False )
10351035 self .assertEqual (release .config .envs ("web" ), {})
10361036 self .assertEqual (release .config .values_refs , {})
1037+
1038+ # test config modification creates new build with merged dryccfile
1039+ # First, create a build with dryccfile
1040+ build_body_with_dryccfile = copy .deepcopy (build_body )
1041+ build_body_with_dryccfile ['dryccfile' ]['config' ] = {
1042+ "mygroup1" : {
1043+ "GROUP" : "g1" ,
1044+ "DEBUG" : "tr" ,
1045+ }
1046+ }
1047+ build_body_with_dryccfile ['dryccfile' ]['pipeline' ]['web.yaml' ]['env' ] = {
1048+ "PENV1" : "web"
1049+ }
1050+ build_body_with_dryccfile ['dryccfile' ]['pipeline' ]['web.yaml' ]['config' ] = [
1051+ "mygroup1"
1052+ ]
1053+ with mock .patch ('scheduler.resources.pod.Pod.watch' ) as mock_kube :
1054+ mock_kube .return_value = ['up' , 'down' ]
1055+ url = f"/v2/apps/{ app_id } /build"
1056+ response = self .client .post (url , build_body_with_dryccfile )
1057+ self .assertEqual (response .status_code , 201 , response .data )
1058+
1059+ # Get the latest release and build
1060+ release = app .release_set .latest ()
1061+ initial_build = release .build
1062+ self .assertIsNotNone (initial_build .dryccfile )
1063+
1064+ # Now modify config - this should trigger build.merge() and create a new build
1065+ config_values = [
1066+ {"name" : "NEW_CONFIG" , "value" : "new_value" , "group" : "mygroup1" },
1067+ {"name" : "PENV2" , "value" : "web2" , "ptype" : "web" }
1068+ ]
1069+ body = {'values' : config_values }
1070+ url = f"/v2/apps/{ app_id } /config"
1071+ response = self .client .post (url , body )
1072+ self .assertEqual (response .status_code , 201 , response .data )
1073+
1074+ # Check that a new release was created
1075+ new_release = app .release_set .latest ()
1076+ self .assertNotEqual (release .uuid , new_release .uuid )
1077+
1078+ # Check that a new build was created with merged dryccfile
1079+ new_build = new_release .build
1080+ self .assertIsNotNone (new_build )
1081+ self .assertNotEqual (initial_build .uuid , new_build .uuid )
1082+
1083+ # Verify dryccfile was merged with config values
1084+ self .assertIn ('dryccfile' , new_build .__dict__ )
1085+ dryccfile = new_build .dryccfile
1086+
1087+ # Check config groups were merged
1088+ self .assertIn ('config' , dryccfile )
1089+ self .assertIn ('mygroup1' , dryccfile ['config' ])
1090+ self .assertEqual (dryccfile ['config' ]['mygroup1' ]['GROUP' ], 'g1' )
1091+ self .assertEqual (dryccfile ['config' ]['mygroup1' ]['DEBUG' ], 'tr' )
1092+ self .assertEqual (dryccfile ['config' ]['mygroup1' ]['NEW_CONFIG' ], 'new_value' )
1093+
1094+ # Check ptype envs were merged
1095+ self .assertIn ('pipeline' , dryccfile )
1096+ self .assertIn ('web.yaml' , dryccfile ['pipeline' ])
1097+ self .assertIn ('env' , dryccfile ['pipeline' ]['web.yaml' ])
1098+ self .assertEqual (dryccfile ['pipeline' ]['web.yaml' ]['env' ]['PENV1' ], 'web' )
1099+ self .assertEqual (dryccfile ['pipeline' ]['web.yaml' ]['env' ]['PENV2' ], 'web2' )
1100+
1101+ # Check config refs
1102+ self .assertIn ('config' , dryccfile ['pipeline' ]['web.yaml' ])
1103+ self .assertEqual (dryccfile ['pipeline' ]['web.yaml' ]['config' ], ['mygroup1' ])
1104+
1105+ # Verify config values are correct
1106+ config = new_release .config
1107+ expected_envs = {
1108+ 'GROUP' : 'g1' ,
1109+ 'DEBUG' : 'tr' ,
1110+ 'NEW_CONFIG' : 'new_value' ,
1111+ 'PENV1' : 'web' ,
1112+ 'PENV2' : 'web2'
1113+ }
1114+ self .assertEqual (config .envs ("web" ), expected_envs )
0 commit comments