Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_get_retry(self):
# We set the client to try twice, with a delay of 5 seconds between
# attempts. So, we expect the call to take at least 5 seconds before
# failing.
self.gi.max_get_attempts = 2
self.gi.get_retry_delay = 5
start = time.time()
try:
self.gi.libraries.get_libraries()
self.fail("Call to show_libraries should have raised a ConnectionError")
except ConnectionError:
end = time.time()
duration = end - start
self.assertGreater(duration, self.gi.get_retry_delay, "Didn't seem to retry long enough")
def test_get_workflows_with_connection_error(self):
with mock.patch.object(
bioblend.galaxy.workflows.WorkflowClient,
"get_workflows",
side_effect=bioblend.ConnectionError("Bad Connection")
):
with self.assertRaises(RuntimeError) as context:
get_workflows()
self.assertIn(
"Unable to retrieve workflows from '{}'".format(
self.workflow_engine.instance.base_url
),
str(context.exception)
)
side_effect=bioblend.ConnectionError("Bad connection"))
def test_galaxy_cleanup_methods_are_called_on_bioblend_exception(
self, invoke_workflow_mock):
settings.REFINERY_GALAXY_ANALYSIS_CLEANUP = "always"
self.create_tool(
ToolDefinition.WORKFLOW,
annotation_file_name="LIST:PAIR.json"
)
self.tool.update_galaxy_data(
self.tool.GALAXY_IMPORT_HISTORY_DICT,
{"id": self.GALAXY_ID_MOCK}
)
self.tool.update_galaxy_data(
self.tool.COLLECTION_INFO,
{"id": "coffee"}
)
else:
if wait:
maxwait = sys.maxsize
else:
maxwait = 0
params = {
'gzip': gzip,
'include_hidden': include_hidden,
'include_deleted': include_deleted,
}
url = '%s/exports' % self._make_url(history_id)
time_left = maxwait
while True:
try:
r = self._put(payload={}, url=url, params=params)
except ConnectionError as e:
if e.status_code == 202: # export is not ready
if time_left > 0:
log.warning("Waiting for the export of history %s to complete. Will wait %i more s", history_id, time_left)
time.sleep(1)
time_left -= 1
else:
return ''
else:
raise
else:
break
jeha_id = r['download_url'].rsplit('/', 1)[-1]
return jeha_id
def _delete(self, payload=None, id=None, deleted=False, contents=None, url=None, params=None):
"""
Do a generic DELETE request, composing the url from the contents of the
arguments. Alternatively, an explicit ``url`` can be provided to use
for the request. ``payload`` must be a dict that contains additional
request arguments which will be sent along with the request body.
:return: The decoded response.
"""
if not url:
url = self._make_url(module_id=id, deleted=deleted, contents=contents)
r = self.gi.make_delete_request(url, payload=payload, params=params)
if r.status_code == 200:
return r.json()
# @see self.body for HTTP response body
raise ConnectionError("Unexpected HTTP status code: %s" % r.status_code,
body=r.text, status_code=r.status_code)
params['key'] = self.key
else:
params = self.default_params
payload = json.dumps(payload)
headers = self.json_headers
r = requests.put(url, data=payload, params=params, headers=headers,
verify=self.verify, timeout=self.timeout)
if r.status_code == 200:
try:
return r.json()
except Exception as e:
raise ConnectionError("Request was successful, but cannot decode the response content: %s" %
e, body=r.content, status_code=r.status_code)
# @see self.body for HTTP response body
raise ConnectionError("Unexpected HTTP status code: %s" % r.status_code,
body=r.text, status_code=r.status_code)
def func_wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except bioblend.ConnectionError as e:
error_message = (
"Error while interacting with bioblend: {}".format(e)
)
logger.error(error_message)
args[0].analysis.cancel()
return
return func_wrapper
else:
payload = json.dumps(payload)
headers = self.json_headers
post_params = params
r = requests.post(url, data=payload, headers=headers,
verify=self.verify, params=post_params,
timeout=self.timeout)
if r.status_code == 200:
try:
return r.json()
except Exception as e:
raise ConnectionError("Request was successful, but cannot decode the response content: %s" %
e, body=r.content, status_code=r.status_code)
# @see self.body for HTTP response body
raise ConnectionError("Unexpected HTTP status code: %s" % r.status_code,
body=r.text, status_code=r.status_code)
def _install(tool_client, tool_id):
try:
tool_client.install_dependencies(tool_id)
except ConnErr as e:
if e.status_code in timeout_codes:
log.warning(e.body)
else:
raise