Skip to content

Commit

Permalink
Merge branch 'release_18.09' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
nsoranzo committed Sep 20, 2018
2 parents 101f200 + d312c48 commit bae08f3
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 17 deletions.
15 changes: 11 additions & 4 deletions lib/galaxy/webapps/galaxy/api/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def search(self, trans, payload, **kwd):
jobs.append(job)
return [self.encode_all_ids(trans, single_job.to_dict('element'), True) for single_job in jobs]

@expose_api
@expose_api_anonymous
def error(self, trans, id, **kwd):
"""
error( trans, id )
Expand All @@ -364,10 +364,17 @@ def error(self, trans, id, **kwd):
# Get job
job = self.__get_job(trans, id)
tool = trans.app.toolbox.get_tool(job.tool_id, tool_version=job.tool_version) or None
email = kwd.get('email')
if not email and not trans.anonymous:
email = trans.user.email
messages = trans.app.error_reports.default_error_plugin.submit_report(
dataset, job, tool, user_submission=True, user=trans.user,
email=kwd.get('email', trans.user.email),
message=kwd.get('message', None)
dataset=dataset,
job=job,
tool=tool,
user_submission=True,
user=trans.user,
email=email,
message=kwd.get('message')
)

return {'messages': messages}
33 changes: 31 additions & 2 deletions test/api/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import time
from operator import itemgetter

from requests import put
import requests

from base import api # noqa: I100,I202
from base.api_asserts import assert_status_code_is_ok # noqa: I100
Expand Down Expand Up @@ -141,6 +141,35 @@ def test_show_security(self, history_id):
show_jobs_response = self._get("jobs/%s" % job_id, admin=True)
self._assert_has_keys(show_jobs_response.json(), "command_line", "external_id")

@skip_without_tool('detect_errors_aggressive')
def test_report_error(self):
with self.dataset_populator.test_history() as history_id:
payload = self.dataset_populator.run_tool_payload(
tool_id='detect_errors_aggressive',
inputs={'error_bool': 'true'},
history_id=history_id,
)
run_response = self._post("tools", data=payload).json()
job_id = run_response['jobs'][0]["id"]
dataset_id = run_response['outputs'][0]['id']
response = self._post('jobs/%s/error' % job_id,
data={'dataset_id': dataset_id})
assert response.status_code == 200

@skip_without_tool('detect_errors_aggressive')
def test_report_error_anon(self):
# Need to get a cookie and use that for anonymous tool runs
cookies = requests.get(self.galaxy_interactor.api_url.rsplit('/api', 1)[0]).cookies
payload = json.dumps({"tool_id": "detect_errors_aggressive",
"inputs": {"error_bool": "true"}})
run_response = requests.post("%s/tools" % self.galaxy_interactor.api_url, data=payload, cookies=cookies).json()
job_id = run_response['jobs'][0]["id"]
dataset_id = run_response['outputs'][0]['id']
response = requests.post('%s/jobs/%s/error' % (self.galaxy_interactor.api_url, job_id),
params={'email': 'someone@domain.com', 'dataset_id': dataset_id},
cookies=cookies)
assert response.status_code == 200

@uses_test_history(require_new=True)
def test_deleting_output_keep_running_until_all_deleted(self, history_id):
job_state, outputs = self._setup_running_two_output_job(history_id, 120)
Expand Down Expand Up @@ -275,7 +304,7 @@ def job_state():

def _raw_update_history_item(self, history_id, item_id, data):
update_url = self._api_url("histories/%s/contents/%s" % (history_id, item_id), use_key=True)
update_response = put(update_url, json=data)
update_response = requests.put(update_url, json=data)
assert_status_code_is_ok(update_response)
return update_response

Expand Down
41 changes: 30 additions & 11 deletions test/unit/tools/test_toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,19 +212,38 @@ def test_tool_reload_for_broken_tool(self):
tool_path = tool.config_file
with open(tool.config_file, 'w') as out:
out.write('certainly not a valid tool')
time.sleep(1.5)
tool = self.app.toolbox.get_tool("test_tool")
assert tool is not None
assert tool.version == "1.0"
assert tool.tool_errors == 'Current on-disk tool is not valid'

def check_tool_errors():
tool = self.app.toolbox.get_tool("test_tool")
assert tool is not None
assert tool.version == "1.0"
assert tool.tool_errors == 'Current on-disk tool is not valid'

self._try_until_no_errors(check_tool_errors)

# Tool is still loaded, lets restore it with a new version
self._init_tool(filename="simple_tool.xml", version="2.0")
time.sleep(1.5)
tool = self.app.toolbox.get_tool("test_tool")
assert tool is not None
assert tool.version == "2.0"
assert tool.tool_errors is None
assert tool_path == tool.config_file

def check_no_tool_errors():
tool = self.app.toolbox.get_tool("test_tool")
assert tool is not None
assert tool.version == "2.0"
assert tool.tool_errors is None
assert tool_path == tool.config_file, "config file"

self._try_until_no_errors(check_no_tool_errors)

def _try_until_no_errors(self, f):
e = None
for i in range(30):
try:
f()
return
except AssertionError as error:
e = error
time.sleep(.25)

raise e

def test_enforce_tool_profile(self):
self._init_tool(filename="old_tool.xml", version="1.0", profile="17.01", tool_id="test_old_tool_profile")
Expand Down

0 comments on commit bae08f3

Please sign in to comment.