@@ -1132,6 +1132,66 @@ def test_packfile_upload(data_builder, file_form, as_admin, as_root, api_db):
11321132 assert acquisition .get ('label' ) == 'test-packfile-timestamp'
11331133
11341134
1135+ # Test that acquisition timestamp is used to differenciate acquisitions and session code for sessions
1136+
1137+ # Make sure there is only one session and one acquisition with the above label to start
1138+ sessions = list (api_db .sessions .find ({'label' :'test-packfile-timestamp' }))
1139+ acquisitions = list (api_db .acquisitions .find ({'label' :'test-packfile-timestamp' }))
1140+ assert len (sessions ) == 1
1141+ assert len (acquisitions ) == 1
1142+
1143+
1144+ r = as_admin .post ('/projects/' + project + '/packfile-start' )
1145+ assert r .ok
1146+ token = r .json ()['token' ]
1147+ r = as_admin .post ('/projects/' + project + '/packfile' ,
1148+ params = {'token' : token }, files = file_form ('one.csv' ))
1149+ assert r .ok
1150+
1151+ metadata_json = json .dumps ({
1152+ 'project' : {'_id' : project },
1153+ 'session' : {
1154+ 'label' : 'test-packfile-timestamp' ,
1155+ 'subject' : {
1156+ 'code' : 'new-subject'
1157+ }
1158+ },
1159+ 'acquisition' : {
1160+ 'label' : 'test-packfile-timestamp' ,
1161+ 'timestamp' : '1999-01-01T00:00:00+00:00'
1162+ },
1163+ 'packfile' : {'type' : 'test' }
1164+ })
1165+
1166+ r = as_admin .post ('/projects/' + project + '/packfile-end' ,
1167+ params = {'token' : token , 'metadata' : metadata_json })
1168+ assert r .ok
1169+
1170+ sessions = list (api_db .sessions .find ({'label' :'test-packfile-timestamp' }))
1171+ acquisitions = list (api_db .acquisitions .find ({'label' :'test-packfile-timestamp' }))
1172+
1173+ # Ensure a new session was created
1174+ assert len (sessions ) == 2
1175+
1176+ # Ensure a new acquisition was created
1177+ assert len (acquisitions ) == 2
1178+
1179+ # Ensure subject code exists on a session
1180+ for s in sessions :
1181+ if s .get ('subject' , {}).get ('code' ) == 'new-subject' :
1182+ break
1183+ else :
1184+ # We didn't fine one
1185+ assert False
1186+
1187+ # Ensure second acquisition timestamp exists on an acquisition
1188+ for a in acquisitions :
1189+ if str (a .get ('timestamp' )) == '1999-01-01 00:00:00' :
1190+ break
1191+ else :
1192+ # We didn't fine one
1193+ assert False
1194+
11351195 # get another token (start packfile-upload)
11361196 r = as_admin .post ('/projects/' + project + '/packfile-start' )
11371197 assert r .ok
0 commit comments