@@ -1065,6 +1065,72 @@ def test_edit_subject_info(data_builder, as_admin, as_user):
10651065 assert r .json ()['info' ] == {}
10661066
10671067
1068+ def test_edit_analysis_info (data_builder , default_payload , file_form , as_admin , as_user ):
1069+ """
1070+ Abridged version since it uses same storage layer as container info
1071+ """
1072+
1073+ gear_doc = default_payload ['gear' ]['gear' ]
1074+ gear_doc ['inputs' ] = {'csv' : {'base' : 'file' }}
1075+ gear = data_builder .create_gear (gear = gear_doc )
1076+ project = data_builder .create_project ()
1077+
1078+ assert as_admin .post ('/projects/' + project + '/files' , files = file_form ('test.csv' )).ok
1079+ r = as_admin .post ('/projects/' + project + '/analyses' , params = {'job' : 'true' }, json = {
1080+ 'analysis' : {'label' : 'with-job' },
1081+ 'job' : {
1082+ 'gear_id' : gear ,
1083+ 'inputs' : {'csv' : {'type' : 'project' , 'id' : project , 'name' : 'test.csv' }}
1084+ }
1085+ })
1086+ assert r .ok
1087+ analysis = r .json ()['_id' ]
1088+
1089+
1090+ r = as_admin .get ('/analyses/' + analysis )
1091+ assert r .ok
1092+ assert not r .json ().get ('info' )
1093+
1094+ # Send improper payload
1095+ r = as_admin .post ('/analyses/' + analysis + '/info' , json = {
1096+ 'delete' : ['map' ],
1097+ 'replace' : {'not_going' : 'to_happen' }
1098+ })
1099+ assert r .status_code == 400
1100+
1101+ # Send improper payload
1102+ r = as_admin .post ('/analyses/' + analysis + '/info' , json = {
1103+ 'delete' : {'a' : 'map' },
1104+ })
1105+ assert r .status_code == 400
1106+
1107+ # Send improper payload
1108+ r = as_admin .post ('/analyses/' + analysis + '/info' , json = {
1109+ 'set' : 'cannot do this' ,
1110+ })
1111+ assert r .status_code == 400
1112+
1113+ # Attempt full replace of info
1114+ analysis_info = {
1115+ 'a' : 'b' ,
1116+ 'test' : 123 ,
1117+ 'map' : {
1118+ 'a' : 'b'
1119+ },
1120+ 'list' : [1 ,2 ,3 ]
1121+ }
1122+
1123+
1124+ r = as_admin .post ('/analyses/' + analysis + '/info' , json = {
1125+ 'replace' : analysis_info
1126+ })
1127+ assert r .ok
1128+
1129+ r = as_admin .get ('/analyses/' + analysis )
1130+ assert r .ok
1131+ assert r .json ()['info' ] == analysis_info
1132+
1133+
10681134def test_fields_list_requests (data_builder , file_form , as_admin ):
10691135 # Ensure sensitive keys are not returned on list endpoints
10701136 # Project: info and files.info
0 commit comments