Commit 3a0eaead authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Added local path to Upload and api.

parent 254f0404
......@@ -180,6 +180,9 @@ class UploadsRes(Resource):
}
:jsonparam string name: An optional name for the upload.
:jsonparem string local_path: An optional path the a file that is already on the server.
In this case, uploading a file won't be possible, the local file is processed
immediatly as if it was uploaded.
:reqheader Content-Type: application/json
:resheader Content-Type: application/json
:status 200: upload successfully created
......@@ -189,7 +192,11 @@ class UploadsRes(Resource):
if json_data is None:
json_data = {}
upload = Upload.create(user=g.user, name=json_data.get('name'))
upload = Upload.create(
user=g.user,
name=json_data.get('name'),
local_path=json_data.get('local_path'))
return upload.json_dict, 200
......
......@@ -232,6 +232,7 @@ class Upload(Chord):
Attributes:
name: optional user provided upload name
local_path: optional local path, e.g. for files that are already somewhere on the server
additional_metadata: optional user provided additional meta data
upload_id: the upload id generated by the database
in_staging: true if the upload is still in staging and can be edited by the uploader
......@@ -245,6 +246,7 @@ class Upload(Chord):
upload_id = StringField(primary_key=True)
name = StringField(default=None)
local_path = StringField(default=None)
additional_metadata = DictField(default=None)
in_staging = BooleanField(default=True)
......@@ -291,7 +293,7 @@ class Upload(Chord):
with lnr(logger, 'delete upload file'):
try:
UploadFile(self.upload_id).delete()
UploadFile(self.upload_id, local_path=self.local_path).delete()
except KeyError:
if self.current_task == 'uploading':
logger.debug(
......@@ -365,6 +367,7 @@ class Upload(Chord):
""" A json serializable dictionary representation. """
data = {
'name': self.name,
'local_path': self.local_path,
'additional_metadata': self.additional_metadata,
'upload_id': self.upload_id,
'upload_url': self.upload_url,
......@@ -388,7 +391,7 @@ class Upload(Chord):
def extracting(self):
logger = self.get_logger()
try:
self._upload = UploadFile(self.upload_id)
self._upload = UploadFile(self.upload_id, local_path=self.local_path)
self._upload.extract()
logger.debug('opened upload')
except KeyError as e:
......@@ -436,7 +439,7 @@ class Upload(Chord):
@task
def cleanup(self):
try:
upload = UploadFile(self.upload_id)
upload = UploadFile(self.upload_id, local_path=self.local_path)
except KeyError as e:
self.fail('Upload does not exist', exc_info=e)
return
......
......@@ -125,12 +125,25 @@ def test_create_upload(client, test_user_auth, no_warn):
def test_create_upload_with_name(client, test_user_auth, no_warn):
rv = client.post(
'/uploads', headers=test_user_auth,
data=json.dumps(dict(name='test_name')), content_type='application/json')
data=json.dumps(dict(name='test_name')),
content_type='application/json')
assert rv.status_code == 200
upload = assert_upload(rv.data)
assert upload['name'] == 'test_name'
def test_create_upload_with_local_path(client, test_user_auth, no_warn):
rv = client.post(
'/uploads', headers=test_user_auth,
data=json.dumps(dict(local_path='test_local_path')),
content_type='application/json')
assert rv.status_code == 200
upload = assert_upload(rv.data)
assert upload['local_path'] == 'test_local_path'
def test_delete_empty_upload(client, test_user_auth, no_warn):
rv = client.post('/uploads', headers=test_user_auth)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment