Skip to content

Commit c9addfc

Browse files
committed
Add tests
1 parent c9099cd commit c9addfc

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

api/placer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,7 @@ def finalize(self):
567567

568568
# Extra properties on insert
569569
insert_map = copy.deepcopy(query)
570+
insert_map.pop('subject.code', None) # Remove query term that should not become part of the payload
570571
insert_map['created'] = self.timestamp
571572
insert_map.update(self.metadata['session'])
572573
insert_map['subject'] = containerutil.add_id_to_subject(insert_map.get('subject'), bson.ObjectId(self.p_id))

tests/integration_tests/python/test_uploads.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)