Skip to content

Commit

Permalink
Merge 08f2eef into 1e6d69b
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego authored Jan 15, 2018
2 parents 1e6d69b + 08f2eef commit 7217e39
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 8 deletions.
8 changes: 7 additions & 1 deletion reana_workflow_controller/fsdb.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# This file is part of REANA.
# Copyright (C) 2017 CERN.
# Copyright (C) 2017, 2018 CERN.
#
# REANA is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
Expand Down Expand Up @@ -65,6 +65,12 @@ def create_workflow_workspace(org, user, workflow_uuid):
workflow_workspace = fs.path.join(analysis_workspace, 'workspace')
if not reana_fs.exists(workflow_workspace):
reana_fs.makedirs(workflow_workspace)
reana_fs.makedirs(
fs.path.join(workflow_workspace,
app.config['INPUTS_RELATIVE_PATH']))
reana_fs.makedirs(
fs.path.join(workflow_workspace,
app.config['OUTPUTS_RELATIVE_PATH']))

return workflow_workspace, analysis_workspace

Expand Down
8 changes: 5 additions & 3 deletions reana_workflow_controller/rest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# This file is part of REANA.
# Copyright (C) 2017 CERN.
# Copyright (C) 2017, 2018 CERN.
#
# REANA is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
Expand Down Expand Up @@ -355,8 +355,10 @@ def seed_workflow_workspace(workflow_id):
raise ValueError('The file transferred needs to have name.')

workflow = Workflow.query.filter(Workflow.id_ == workflow_id).first()
file_.save(os.path.join(os.getenv('SHARED_VOLUME_PATH'),
workflow.workspace_path, file_name))
file_.save(os.path.join(current_app.config['SHARED_VOLUME_PATH'],
workflow.workspace_path,
current_app.config['INPUTS_RELATIVE_PATH'],
file_name))
return jsonify({'message': 'File successfully transferred'}), 200
except KeyError as e:
return jsonify({"message": str(e)}), 400
Expand Down
61 changes: 57 additions & 4 deletions tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# This file is part of REANA.
# Copyright (C) 2017 CERN.
# Copyright (C) 2017, 2018 CERN.
#
# REANA is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
Expand All @@ -21,12 +21,14 @@
# submit itself to any jurisdiction.
"""REANA-Workflow-Controller fsdb module tests."""

import io
import json
import os
import uuid

import fs
from flask import url_for
from werkzeug.utils import secure_filename

from reana_workflow_controller.fsdb import get_user_analyses_dir
from reana_workflow_controller.models import Workflow, WorkflowStatus
Expand Down Expand Up @@ -210,7 +212,7 @@ def test_get_workflow_outputs_file(app, db_session, default_user,
workflow.workspace_path)
# write file in the workflow workspace under `outputs` directory
file_path = os.path.join(absolute_path_workflow_workspace,
'outputs',
app.config['OUTPUTS_RELATIVE_PATH'],
# we use `secure_filename` here because
# we use it in server side when adding
# files
Expand Down Expand Up @@ -304,7 +306,6 @@ def test_get_workflow_inputs_list(app, db_session, default_user,
fs_ = fs.open_fs(absolute_path_workflow_workspace)
# from config
inputs_relative_path = app.config['INPUTS_RELATIVE_PATH']
fs_.makedirs(inputs_relative_path)
test_files = []
for i in range(5):
file_name = '{0}.csv'.format(i)
Expand Down Expand Up @@ -353,7 +354,6 @@ def test_get_workflow_outputs_list(app, db_session, default_user,
fs_ = fs.open_fs(absolute_path_workflow_workspace)
# from config
outputs_realative_path = app.config['OUTPUTS_RELATIVE_PATH']
fs_.makedirs(outputs_realative_path)
test_files = []
for i in range(5):
file_name = '{0}.csv'.format(i)
Expand Down Expand Up @@ -576,3 +576,56 @@ def test_set_workflow_status_unknown_workflow(app, default_user):
content_type='application/json',
data=json.dumps(payload))
assert res.status_code == 404


def test_seed_workflow_workspace(app, db_session, default_user,
tmp_shared_volume_path):
"""Test download output file."""
with app.test_client() as client:
# create workflow
organization = 'default'
data = {'parameters': {'min_year': '1991',
'max_year': '2001'},
'specification': {'first': 'do this',
'second': 'do that'},
'type': 'cwl'}
res = client.post(url_for('api.create_workflow'),
query_string={
"user": default_user.id_,
"organization": organization},
content_type='application/json',
data=json.dumps(data))

response_data = json.loads(res.get_data(as_text=True))
workflow_uuid = response_data.get('workflow_id')
workflow = Workflow.query.filter(
Workflow.id_ == workflow_uuid).first()
# create file
file_name = 'dataset.csv'
file_binary_content = b'1,2,3,4\n5,6,7,8'
absolute_path_workflow_workspace = \
os.path.join(tmp_shared_volume_path,
workflow.workspace_path)

res = client.post(
url_for('api.seed_workflow_workspace', workflow_id=workflow_uuid),
query_string={"user": default_user.id_,
"organization": organization,
"file_name": file_name},
content_type='multipart/form-data',
data={'file_content': (io.BytesIO(file_binary_content),
file_name)})
assert res.status_code == 200
absolute_path_workflow_workspace = \
os.path.join(tmp_shared_volume_path,
workflow.workspace_path)

file_path = os.path.join(absolute_path_workflow_workspace,
app.config['INPUTS_RELATIVE_PATH'],
# we use `secure_filename` here because
# we use it in server side when adding
# files
secure_filename(file_name))

with open(file_path, 'rb') as f:
assert f.read() == file_binary_content

0 comments on commit 7217e39

Please sign in to comment.