2 new commits in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/4f1f6bb5bf5e/ Changeset: 4f1f6bb5bf5e User: jmchilton Date: 2014-01-16 16:30:01 Summary: Add tool execution tests for various exceptional conditions. Tool action raising exception, redirecting, and returning an error message. Affected #: 1 file diff -r ff018b067bb21760335de776f7e97a987d86c7e6 -r 4f1f6bb5bf5e975f4d40a8feeeed77795a6d69aa test/unit/tools/test_execution.py --- a/test/unit/tools/test_execution.py +++ b/test/unit/tools/test_execution.py @@ -15,6 +15,10 @@ from galaxy.util.odict import odict from tools_support import UsesApp +from galaxy import eggs +eggs.require( "Paste" ) +from paste import httpexceptions + # Simple tool with just one text parameter and output. SIMPLE_TOOL_CONTENTS = '''<tool id="test_tool" name="Test Tool"><command>echo "$param1" < $out1</command> @@ -92,6 +96,41 @@ # Didn't specify a rerun_remap_id so this should be None assert self.tool_action.execution_call_args[ 0 ][ "rerun_remap_job_id" ] is None + def test_execute_exception( self ): + self.__init_tool( SIMPLE_TOOL_CONTENTS ) + self.tool_action.raise_exception( ) + template, template_vars = self.__handle_with_incoming( + param1="moo", + runtool_btn="dummy", + ) + assert template == "message.mako" + assert template_vars[ "status" ] == "error" + assert "Error executing tool" in template_vars[ "message" ] + + def test_execute_errors( self ): + self.__init_tool( SIMPLE_TOOL_CONTENTS ) + self.tool_action.return_error( ) + template, template_vars = self.__handle_with_incoming( + param1="moo", + runtool_btn="dummy", + ) + assert template == "message.mako" + assert template_vars[ "status" ] == "error" + assert "Test Error Message" in template_vars[ "message" ], template_vars + + def test_redirect( self ): + self.__init_tool( SIMPLE_TOOL_CONTENTS ) + self.tool_action.expect_redirect = True + redirect_raised = False + try: + template, template_vars = self.__handle_with_incoming( + param1="moo", + runtool_btn="dummy", + ) + except httpexceptions.HTTPFound: + redirect_raised = True + assert redirect_raised + def test_remap_job( self ): self.__init_tool( SIMPLE_TOOL_CONTENTS ) template, template_vars = self.__handle_with_incoming( @@ -237,12 +276,31 @@ def __init__( self, expected_trans ): self.expected_trans = expected_trans self.execution_call_args = [] + self.expect_redirect = False + self.exception_after_exection = None + self.error_message_after_excution = None def execute( self, tool, trans, **kwds ): assert self.expected_trans == trans self.execution_call_args.append( kwds ) + num_calls = len( self.execution_call_args ) + if self.expect_redirect: + raise httpexceptions.HTTPFound( "http://google.com" ) + if self.exception_after_exection is not None: + if num_calls > self.exception_after_exection: + raise Exception( "Test Exception" ) + if self.error_message_after_excution is not None: + if num_calls > self.error_message_after_excution: + return None, "Test Error Message" + return None, odict(dict(out1="1")) + def raise_exception( self, after_execution=0 ): + self.exception_after_exection = after_execution + + def return_error( self, after_execution=0 ): + self.error_message_after_excution = after_execution + class MockTrans( object ): https://bitbucket.org/galaxy/galaxy-central/commits/659a29d112f6/ Changeset: 659a29d112f6 User: jmchilton Date: 2014-01-16 16:30:01 Summary: Rearrange __handle_execute and handle_input in Tool... Slightly cleaner this way (fewer exit points) and will enable extensions I am making downstream. Affected #: 1 file diff -r 4f1f6bb5bf5e975f4d40a8feeeed77795a6d69aa -r 659a29d112f622db5dabb65e4105535b5aee3b30 lib/galaxy/tools/__init__.py --- a/lib/galaxy/tools/__init__.py +++ b/lib/galaxy/tools/__init__.py @@ -1871,7 +1871,7 @@ errors, params = self.__check_param_values( trans, incoming, state, old_errors, process_state, history=history, source=source ) if self.__should_refresh_state( incoming ): - return self.__handle_state_refresh( trans, state, errors ) + template, template_vars = self.__handle_state_refresh( trans, state, errors ) else: # User actually clicked next or execute. @@ -1879,18 +1879,30 @@ # error messages if errors: error_message = "One or more errors were found in the input you provided. The specific errors are marked below." - return "tool_form.mako", dict( errors=errors, tool_state=state, incoming=incoming, error_message=error_message ) + template = "tool_form.mako" + template_vars = dict( errors=errors, tool_state=state, incoming=incoming, error_message=error_message ) # If we've completed the last page we can execute the tool elif all_pages or state.page == self.last_page: - return self.__handle_tool_execute( trans, rerun_remap_job_id, params, history ) + tool_executed, result = self.__handle_tool_execute( trans, rerun_remap_job_id, params, history ) + if tool_executed: + template = 'tool_executed.mako' + template_vars = dict( out_data=result ) + else: + template = 'message.mako' + template_vars = dict( status='error', message=result, refresh_frames=[] ) # Otherwise move on to the next page else: - return self.__handle_page_advance( trans, state, errors ) + template, template_vars = self.__handle_page_advance( trans, state, errors ) + return template, template_vars def __should_refresh_state( self, incoming ): return not( 'runtool_btn' in incoming or 'URL' in incoming or 'ajax_upload' in incoming ) def __handle_tool_execute( self, trans, rerun_remap_job_id, params, history ): + """ + Return a pair with whether execution is successful as well as either + resulting output data or an error message indicating the problem. + """ try: _, out_data = self.execute( trans, incoming=params, history=history, rerun_remap_job_id=rerun_remap_job_id ) except httpexceptions.HTTPFound, e: @@ -1898,16 +1910,16 @@ raise e except Exception, e: log.exception('Exception caught while attempting tool execution:') - return 'message.mako', dict( status='error', message='Error executing tool: %s' % str(e), refresh_frames=[] ) - try: - assert isinstance( out_data, odict ) - return 'tool_executed.mako', dict( out_data=out_data ) - except: + message = 'Error executing tool: %s' % str(e) + return False, message + if isinstance( out_data, odict ): + return True, out_data + else: if isinstance( out_data, str ): message = out_data else: - message = 'Failure executing tool (odict not returned from tool execution)' - return 'message.mako', dict( status='error', message=message, refresh_frames=[] ) + message = 'Failure executing tool (invalid data returned from tool execution)' + return False, message def __handle_state_refresh( self, trans, state, errors ): try: Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.