Unverified Commit d014469f authored by Martin Cech's avatar Martin Cech Committed by GitHub
Browse files

Merge pull request #6742 from mvdbeek/fix_error_reporting

[18.05] Fix and test anonymous error reports
parents 84004174 f5dcf605
......@@ -320,7 +320,7 @@ class JobController(BaseAPIController, UsesLibraryMixinItems):
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 )
......@@ -343,10 +343,17 @@ class JobController(BaseAPIController, UsesLibraryMixinItems):
# 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}
......@@ -4,13 +4,14 @@ import os
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
from base.populators import ( # noqa: I100
DatasetCollectionPopulator,
DatasetPopulator,
skip_without_tool,
wait_on,
wait_on_state,
)
......@@ -131,6 +132,35 @@ class JobsApiTestCase(api.ApiTestCase):
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
def test_deleting_output_keep_running_until_all_deleted(self):
history_id, job_state, outputs = self._setup_running_two_output_job(120)
......@@ -263,7 +293,7 @@ class JobsApiTestCase(api.ApiTestCase):
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
......
Markdown is supported
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