Skip to content

Commit

Permalink
Merge 3dc9b77 into d071e04
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego committed Jan 12, 2018
2 parents d071e04 + 3dc9b77 commit 0419b8e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
4 changes: 2 additions & 2 deletions docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -652,10 +652,10 @@
"description": "Request failed. The incoming data specification seems malformed."
},
"404": {
"description": "Request failed. User doesn't exist.",
"description": "Request failed. `file_name` does not exist.",
"examples": {
"application/json": {
"message": "User 00000000-0000-0000-0000-000000000000 doesn't exist"
"message": "input.csv does not exist"
}
}
},
Expand Down
11 changes: 7 additions & 4 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 All @@ -28,6 +28,7 @@

from flask import (Blueprint, abort, current_app, jsonify, request,
send_from_directory)
from werkzeug.exceptions import NotFound
from werkzeug.utils import secure_filename

from .factory import db
Expand Down Expand Up @@ -413,12 +414,11 @@ def get_workflow_outputs_file(workflow_id, file_name): # noqa
Request failed. The incoming data specification seems malformed.
404:
description: >-
Request failed. User doesn't exist.
Request failed. `file_name` does not exist.
examples:
application/json:
{
"message": "User 00000000-0000-0000-0000-000000000000 doesn't
exist"
"message": "input.csv does not exist"
}
500:
description: >-
Expand Down Expand Up @@ -451,6 +451,9 @@ def get_workflow_outputs_file(workflow_id, file_name): # noqa

except KeyError:
return jsonify({"message": "Malformed request."}), 400
except NotFound as e:
return jsonify(
{"message": "{0} does not exist.".format(file_name)}), 404
except Exception as e:
return jsonify({"message": str(e)}), 500

Expand Down
37 changes: 36 additions & 1 deletion 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 Down Expand Up @@ -180,6 +180,41 @@ def test_create_workflow_wrong_user(app, db_session, tmp_shared_volume_path):
assert not os.path.exists(workflow_workspace)


def test_get_workflow_outputs_absent_file(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))

assert res.status_code == 201
response_data = json.loads(res.get_data(as_text=True))
workflow_uuid = response_data.get('workflow_id')
file_name = 'input.csv'
res = client.get(
url_for('api.get_workflow_outputs_file', workflow_id=workflow_uuid,
file_name=file_name),
query_string={"user": default_user.id_,
"organization": organization},
content_type='application/json',
data=json.dumps(data))

assert res.status_code == 404
response_data = json.loads(res.get_data(as_text=True))
assert response_data == {'message': 'input.csv does not exist.'}


def test_get_workflow_outputs_file(app, db_session, default_user,
tmp_shared_volume_path):
"""Test download output file."""
Expand Down

0 comments on commit 0419b8e

Please sign in to comment.