Fix test cases

Fix lint

Fix lint

Fix test messages

Remove unnecessary variable

Remove unused test helper functions

Fix lint

Fix error message in tests

Fix spaces
This commit is contained in:
guerler
2015-10-06 19:12:06 -04:00
parent 59885c3afd
commit ee1136d5bf
4 changed files with 53 additions and 256 deletions
@@ -118,7 +118,7 @@ define(['utils/utils', 'utils/deferred', 'mvc/ui/ui-misc', 'mvc/form/form-view',
console.debug(response);
// show error
var error_message = ( response && response.error) || (response && response.err_msg) || 'Uncaught error.';
var error_message = ( response && response.error ) || ( response && response.err_msg ) || 'Uncaught error.';
if ( self.$el.is(':empty') ) {
self.$el.prepend((new Ui.Message({
message : error_message,
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -219,7 +219,7 @@ class GalaxyInteractorApi( object ):
jobs=submit_response_object[ 'jobs' ],
)
except KeyError:
message = "Error creating a job for these tool inputs - %s" % submit_response_object[ 'message' ]
message = "Error creating a job for these tool inputs - %s" % submit_response_object[ 'err_msg' ]
raise RunToolException( message, inputs_tree )
def _create_collection( self, history_id, collection_def ):
+50 -253
View File
@@ -4,11 +4,8 @@
from unittest import TestCase
import galaxy.model
from galaxy.tools import DefaultToolState
from galaxy.tools.parameters import params_to_incoming
from galaxy.util.bunch import Bunch
from galaxy.util import string_to_object
from galaxy.util import object_to_string
from galaxy.util.odict import odict
import tools_support
@@ -49,118 +46,62 @@ class ToolExecutionTestCase( TestCase, tools_support.UsesApp, tools_support.Uses
def test_state_new( self ):
self._init_tool( tools_support.SIMPLE_TOOL_CONTENTS )
template, template_vars = self.__handle_with_incoming(
param1="moo",
# no runtool_btn, just rerenders the form mako with tool
# state populated.
)
state = self.__assert_rerenders_tool_without_errors( template, template_vars )
assert state.inputs[ "param1" ] == "moo"
vars = self.__handle_with_incoming( param1="moo" )
state = self.__assert_rerenders_tool_without_errors( vars )
assert state[ "param1" ] == "moo"
def test_execute( self ):
self._init_tool( tools_support.SIMPLE_TOOL_CONTENTS )
template, template_vars = self.__handle_with_incoming(
param1="moo",
runtool_btn="dummy",
)
self.__assert_exeuted( template, template_vars )
vars = self.__handle_with_incoming( param1="moo" )
self.__assert_executed( vars )
# 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( tools_support.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" ]
try:
self.__handle_with_incoming( param1="moo" )
except Exception, e:
assert 'Error executing tool' in str( e )
def test_execute_errors( self ):
self._init_tool( tools_support.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
try:
self.__handle_with_incoming( param1="moo" )
except Exception, e:
assert 'Test Error Message' in str( e )
def test_redirect( self ):
self._init_tool( tools_support.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",
)
self.__handle_with_incoming( param1="moo" )
except httpexceptions.HTTPFound:
redirect_raised = True
assert redirect_raised
def test_remap_job( self ):
self._init_tool( tools_support.SIMPLE_TOOL_CONTENTS )
template, template_vars = self.__handle_with_incoming(
param1="moo",
rerun_remap_job_id=self.app.security.encode_id(123),
runtool_btn="dummy",
)
self.__assert_exeuted( template, template_vars )
vars = self.__handle_with_incoming( param1="moo", rerun_remap_job_id=self.app.security.encode_id(123) )
self.__assert_executed( vars )
assert self.tool_action.execution_call_args[ 0 ][ "rerun_remap_job_id" ] == 123
def test_invalid_remap_job( self ):
self._init_tool( tools_support.SIMPLE_TOOL_CONTENTS )
template, template_vars = self.__handle_with_incoming(
param1="moo",
rerun_remap_job_id='123', # Not encoded
runtool_btn="dummy",
)
assert template == "message.mako"
assert template_vars[ "status" ] == "error"
assert "invalid job" in template_vars[ "message" ]
def test_repeat_state_updates( self ):
self._init_tool( REPEAT_TOOL_CONTENTS )
# Fresh state contains no repeat elements
template, template_vars = self.__handle_with_incoming()
state = self.__assert_rerenders_tool_without_errors( template, template_vars )
assert len( state.inputs[ "repeat1" ] ) == 0
# Hitting add button adds repeat element
template, template_vars = self.__handle_with_incoming(
repeat1_add="dummy",
)
state = self.__assert_rerenders_tool_without_errors( template, template_vars )
assert len( state.inputs[ "repeat1" ] ) == 1
# Hitting add button again adds another repeat element
template, template_vars = self.__handle_with_incoming( state, **{
"repeat1_add": "dummy",
"repeat1_0|param2": "moo2",
} )
state = self.__assert_rerenders_tool_without_errors( template, template_vars )
assert len( state.inputs[ "repeat1" ] ) == 2
assert state.inputs[ "repeat1" ][ 0 ][ "param2" ] == "moo2"
# Hitting remove drops a repeat element
template, template_vars = self.__handle_with_incoming( state, repeat1_1_remove="dummy" )
state = self.__assert_rerenders_tool_without_errors( template, template_vars )
assert len( state.inputs[ "repeat1" ] ) == 1
try:
self.__handle_with_incoming( param1="moo", rerun_remap_job_id='123' )
except Exception, e:
assert 'invalid job' in str( e )
def test_data_param_execute( self ):
self._init_tool( tools_support.SIMPLE_CAT_TOOL_CONTENTS )
hda = self.__add_dataset(1)
hda = self.__add_dataset( 1 )
# Execute tool action
template, template_vars = self.__handle_with_incoming(
param1=1,
runtool_btn="dummy",
)
self.__assert_exeuted( template, template_vars )
vars = self.__handle_with_incoming( param1=1 )
self.__assert_executed( vars )
# Tool 'executed' once, with hda as param1
assert len( self.tool_action.execution_call_args ) == 1
assert self.tool_action.execution_call_args[ 0 ][ "incoming" ][ "param1" ] == hda
@@ -169,113 +110,27 @@ class ToolExecutionTestCase( TestCase, tools_support.UsesApp, tools_support.Uses
self._init_tool( tools_support.SIMPLE_CAT_TOOL_CONTENTS )
hda = self.__add_dataset( 1 )
# Update state
template, template_vars = self.__handle_with_incoming(
param1=1,
)
state = self.__assert_rerenders_tool_without_errors( template, template_vars )
assert hda == state.inputs[ "param1" ]
vars = self.__handle_with_incoming( param1=1 )
state = self.__assert_rerenders_tool_without_errors( vars )
assert hda == state[ "param1" ]
def test_simple_multirun_state_update( self ):
hda1, hda2 = self.__setup_multirun_job()
template, template_vars = self.__handle_with_incoming( **{
"param1|__multirun__": [ 1, 2 ],
vars = self.__handle_with_incoming( **{
"param1|__multirun__": [ 1, 2 ]
} )
state = self.__assert_rerenders_tool_without_errors( template, template_vars )
self.__assert_state_serializable( state )
self.assertEquals( state.inputs[ "param1|__multirun__" ], [ 1, 2 ] )
def test_simple_collection_multirun_state_update( self ):
hdca = self.__setup_collection_multirun_job()
encoded_id = self.app.security.encode_id(hdca.id)
template, template_vars = self.__handle_with_incoming( **{
"param1|__collection_multirun__": encoded_id,
} )
state = self.__assert_rerenders_tool_without_errors( template, template_vars )
self.__assert_state_serializable( state )
self.assertEquals( state.inputs[ "param1|__collection_multirun__" ], encoded_id )
def test_repeat_multirun_state_updates( self ):
self._init_tool( REPEAT_TOOL_CONTENTS )
# Fresh state contains no repeat elements
self.__handle_with_incoming()
# Hitting add button adds repeat element
template, template_vars = self.__handle_with_incoming(**{
"param1|__multirun__": [ 1, 2 ],
"repeat1_add": "dummy",
})
state = self.__assert_rerenders_tool_without_errors( template, template_vars )
self.assertEquals( state.inputs[ "param1|__multirun__" ], [ 1, 2 ] )
assert len( state.inputs[ "repeat1" ] ) == 1
# Hitting add button again adds another repeat element
template, template_vars = self.__handle_with_incoming( state, **{
"repeat1_0|param2|__multirun__": [ 1, 2 ],
"repeat1_add": "dummy",
} )
state = self.__assert_rerenders_tool_without_errors( template, template_vars )
self.assertEquals( state.inputs[ "param1|__multirun__" ], [ 1, 2 ] )
self.assertEquals( state.inputs[ "repeat1" ][0][ "param2|__multirun__" ], [ 1, 2 ] )
def test_simple_multirun_execution( self ):
hda1, hda2 = self.__setup_multirun_job()
template, template_vars = self.__handle_with_incoming( **{
"param1|__multirun__": [ 1, 2 ],
"runtool_btn": "dummy",
} )
self.__assert_exeuted( template, template_vars )
# Tool 'executed' twice, with param1 as hda1 and hda2 respectively.
assert len( self.tool_action.execution_call_args ) == 2
self.assertEquals( self.tool_action.execution_call_args[ 0 ][ "incoming" ][ "param1" ], hda1 )
self.assertEquals( self.tool_action.execution_call_args[ 1 ][ "incoming" ][ "param1" ], hda2 )
self.assertEquals( len( template_vars[ "jobs" ] ), 2 )
self.__assert_rerenders_tool_without_errors( vars )
assert vars[ 'num_jobs' ] == 2
def test_cannot_multirun_and_remap( self ):
hda1, hda2 = self.__setup_multirun_job()
template, template_vars = self.__handle_with_incoming( **{
"param1|__multirun__": [ 1, 2 ],
"rerun_remap_job_id": self.app.security.encode_id(123), # Not encoded
"runtool_btn": "dummy",
} )
self.assertEquals( template, "message.mako" )
assert template_vars[ "status" ] == "error"
assert "multiple jobs" in template_vars[ "message" ]
def test_multirun_with_state_updates( self ):
hda1, hda2 = self.__setup_multirun_job()
# Fresh state contains no repeat elements
template, template_vars = self.__handle_with_incoming()
state = self.__assert_rerenders_tool_without_errors( template, template_vars )
assert len( state.inputs[ "repeat1" ] ) == 0
self.__assert_state_serializable( state )
# Hitting add button adds repeat element
template, template_vars = self.__handle_with_incoming( **{
"param1|__multirun__": [ 1, 2 ],
"repeat1_add": "dummy",
} )
state = self.__assert_rerenders_tool_without_errors( template, template_vars )
assert len( state.inputs[ "repeat1" ] ) == 1
self.assertEquals( state.inputs[ "param1|__multirun__" ], [ 1, 2 ] )
self.__assert_state_serializable( state )
# Hitting add button again adds another repeat element
template, template_vars = self.__handle_with_incoming( state, **{
"repeat1_add": "dummy",
"repeat1_0|param2": 1,
} )
state = self.__assert_rerenders_tool_without_errors( template, template_vars )
self.assertEquals( state.inputs[ "param1|__multirun__" ], [ 1, 2 ] )
assert len( state.inputs[ "repeat1" ] ) == 2
assert state.inputs[ "repeat1" ][ 0 ][ "param2" ] == hda1
self.__assert_state_serializable( state )
# Hitting remove drops a repeat element
template, template_vars = self.__handle_with_incoming( state, repeat1_1_remove="dummy" )
state = self.__assert_rerenders_tool_without_errors( template, template_vars )
assert len( state.inputs[ "repeat1" ] ) == 1
self.__assert_state_serializable( state )
try:
self.__handle_with_incoming( **{
"param1|__multirun__": [ 1, 2 ],
"rerun_remap_job_id": self.app.security.encode_id( 123 )
} )
except Exception, e:
assert 'multiple jobs' in str( e )
def test_collection_multirun_with_state_updates( self ):
hda1, hda2 = self.__setup_multirun_job()
@@ -284,31 +139,10 @@ class ToolExecutionTestCase( TestCase, tools_support.UsesApp, tools_support.Uses
self.app.dataset_collections_service = Bunch(
match_collections=lambda collections: None
)
template, template_vars = self.__handle_with_incoming( **{
"param1|__collection_multirun__": collection_id,
"runtool_btn": "dummy",
vars = self.__handle_with_incoming( **{
"param1|__collection_multirun__": collection_id
} )
self.__assert_exeuted( template, template_vars )
def test_subcollection_multirun_with_state_updates( self ):
self._init_tool( REPEAT_COLLECTION_PARAM_CONTENTS )
hda1, hda2 = self.__add_dataset( 1 ), self.__add_dataset( 2 )
collection = self.__history_dataset_collection_for( [ hda1, hda2 ], collection_type="list:paired" )
collection_id = self.app.security.encode_id( collection.id )
self.app.dataset_collections_service = Bunch(
match_collections=lambda collections: None
)
template, template_vars = self.__handle_with_incoming(
repeat1_add="dummy",
)
state = self.__assert_rerenders_tool_without_errors( template, template_vars )
assert len( state.inputs[ "repeat1" ] ) == 1
template, template_vars = self.__handle_with_incoming( state, **{
"repeat1_0|param2|__collection_multirun__": "%s|paired" % collection_id,
"repeat1_add": "dummy",
} )
state = self.__assert_rerenders_tool_without_errors( template, template_vars )
assert state.inputs[ "repeat1" ][ 0 ][ "param2|__collection_multirun__" ] == "%s|paired" % collection_id
self.__assert_executed( vars )
def __history_dataset_collection_for( self, hdas, collection_type="list", id=1234 ):
collection = galaxy.model.DatasetCollection(
@@ -340,19 +174,11 @@ class ToolExecutionTestCase( TestCase, tools_support.UsesApp, tools_support.Uses
hdcas[ id ] = history_dataset_collection_association
return history_dataset_collection_association
def __assert_state_serializable( self, state ):
self.__state_to_string( state ) # Will thrown exception if there is a problem...
def __setup_multirun_job( self ):
self._init_tool( tools_support.SIMPLE_CAT_TOOL_CONTENTS )
hda1, hda2 = self.__add_dataset( 1 ), self.__add_dataset( 2 )
return hda1, hda2
def __setup_collection_multirun_job( self ):
self._init_tool( tools_support.SIMPLE_CAT_TOOL_CONTENTS )
hdca = self.__add_collection_dataset( 1 )
return hdca
def __handle_with_incoming( self, previous_state=None, **kwds ):
""" Execute tool.handle_input with incoming specified by kwds
(optionally extending a previous state).
@@ -361,10 +187,7 @@ class ToolExecutionTestCase( TestCase, tools_support.UsesApp, tools_support.Uses
incoming = self.__to_incoming( previous_state, **kwds)
else:
incoming = kwds
return self.tool.handle_input(
trans=self.trans,
incoming=incoming,
)
return self.tool.handle_input( trans=self.trans, incoming=incoming )
def __to_incoming( self, state, **kwds ):
new_incoming = {}
@@ -398,43 +221,17 @@ class ToolExecutionTestCase( TestCase, tools_support.UsesApp, tools_support.Uses
self.history.dataset_collections.append( hdca )
return hdca
def __assert_rerenders_tool_without_errors( self, template, template_vars ):
assert template == ""
self.__assert_no_errors( template_vars )
state = template_vars[ "tool_state" ]
return state
def __assert_rerenders_tool_without_errors( self, vars ):
self.__assert_no_errors( vars )
return self.tool_action.execution_call_args[ 0 ][ "incoming" ]
def __assert_exeuted( self, template, template_vars ):
if template == "":
self.__assert_no_errors( template_vars )
self.assertEquals(
template,
"tool_executed.mako",
"Expected tools_execute template - got template %s with vars %s" % ( template, template_vars)
)
def __assert_executed( self, vars ):
self.__assert_no_errors( vars )
assert len( vars[ 'jobs' ] ) > 0
def __assert_no_errors( self, template_vars ):
assert "errors" in template_vars, "Tool form rendered without error definition."
errors = template_vars[ "errors" ]
assert not errors, "Template rendered unexpected errors - %s" % errors
def __string_to_state( self, state_string ):
encoded_state = string_to_object( state_string )
state = DefaultToolState()
state.decode( encoded_state, self.tool, self.app )
return state
def __inputs_to_state( self, inputs ):
tool_state = DefaultToolState()
tool_state.inputs = inputs
return tool_state
def __state_to_string( self, tool_state ):
return object_to_string( tool_state.encode( self.tool, self.app ) )
def __inputs_to_state_string( self, inputs ):
tool_state = self.__inputs_to_state( inputs )
return self.__state_to_string( tool_state )
def __assert_no_errors( self, vars ):
assert "job_errors" in vars
assert not vars[ "job_errors" ]
class MockAction( object ):