Skip to content
Snippets Groups Projects
Commit d73d430b authored by Megan Henning's avatar Megan Henning
Browse files

Add db update and tests

parent 0ceb33a8
No related branches found
No related tags found
No related merge requests found
......@@ -14,6 +14,7 @@ import sys
import time
from api import config
from api import util
from api.dao import containerutil
from api.dao.containerstorage import ProjectStorage
from api.jobs.jobs import Job
......@@ -21,7 +22,7 @@ from api.jobs import gears
from api.types import Origin
from api.jobs import batch
CURRENT_DATABASE_VERSION = 35 # An int that is bumped when a new schema change is made
CURRENT_DATABASE_VERSION = 36 # An int that is bumped when a new schema change is made
def get_db_version():
......@@ -1189,6 +1190,27 @@ def upgrade_to_35():
process_cursor(cursor, upgrade_to_35_closure)
def upgrade_to_36_closure(acquisition):
for f in acquisition['files']:
if not f.get('mimetype'):
logging.debug('file with name {} did not have mimetype'.format(f['name']))
f['mimetype'] = util.guess_mimetype(f['name'])
result = config.db.acquisitions.update_one({'_id': acquisition['_id']}, {'$set': {'files': acquisition['files']}})
if result.modified_count != 1:
raise Exception('Acquisition file not updated')
return True
def upgrade_to_36():
"""
scitran/core issue #931 - mimetype not set on packfile uploads
"""
cursor = config.db.acquisitions.find({'files.mimetype': None})
process_cursor(cursor, upgrade_to_36_closure)
###
......
......@@ -932,6 +932,12 @@ def test_packfile_upload(data_builder, file_form, as_admin, as_root, api_db):
params={'token': token, 'metadata': metadata_json})
assert r.ok
# make sure file was uploaded and mimetype and type are properly set
packfile = as_admin.get('/acquisitions').json()[0]['files'][0]
assert packfile['mimetype'] == 'application/zip'
assert packfile['type'] == 'test'
# get another token (start packfile-upload)
r = as_admin.post('/projects/' + project + '/packfile-start')
assert r.ok
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment