Large cleanup of unused methods from twilltestcase.

In addition to deleting unused methods, this also moves ones only used by test_library_templates into that file.
This commit is contained in:
John Chilton
2016-11-17 08:41:52 -05:00
parent 2f08dd72c3
commit a209523639
2 changed files with 354 additions and 1727 deletions
File diff suppressed because it is too large Load Diff
+352
View File
@@ -1,3 +1,9 @@
import time
import pyparsing # noqa: F401
import twill.commands as tc
from markupsafe import escape
import galaxy.model
from base.test_db_util import (
get_folder,
@@ -30,6 +36,352 @@ regular_user1 = regular_user2 = regular_user3 = None
class TestLibraryFeatures( TwillTestCase ):
def add_folder( self, cntrller, library_id, folder_id, name='Folder One', description='This is Folder One' ):
"""Create a new folder"""
url = "%s/library_common/create_folder?cntrller=%s&library_id=%s&parent_id=%s" % ( self.url, cntrller, library_id, folder_id )
self.visit_url( url )
self.check_page_for_string( 'Create a new folder' )
tc.fv( "1", "name", name )
tc.fv( "1", "description", description )
tc.submit( "new_folder_button" )
check_str = escape( "The new folder named '%s' has been added to the data library." % name )
self.check_page_for_string( check_str )
def add_template( self, cntrller, item_type, form_type, form_id, form_name,
library_id=None, folder_id=None, ldda_id=None, request_type_id=None, sample_id=None ):
"""
Add a new template to an item - for library items, the template will ALWAYS BE SET TO INHERITABLE here. If you want to
dis-inherit your template, call the manage_library_template_inheritance() below immediately after you call this
method in your test code. Templates added to Requesttype objects are always inherited to samples.
"""
params = dict( cntrller=cntrller, item_type=item_type, form_type=form_type, library_id=library_id )
url = "/library_common/add_template"
if item_type == 'folder':
params[ 'folder_id' ] = folder_id
elif item_type == 'ldda':
params[ 'ldda_id' ] = ldda_id
self.visit_url( url, params )
self.check_page_for_string( "Select a template for the" )
self.refresh_form( "form_id", form_id )
# For some unknown reason, twill barfs if the form number ( 1 ) is used in the following
# rather than the form anme ( select_template ), so we have to use the form name.
tc.fv( "select_template", "inheritable", '1' )
tc.submit( "add_template_button" )
self.check_page_for_string = 'A template based on the form "%s" has been added to this' % form_name
def browse_library( self, cntrller, library_id, show_deleted=False, strings_displayed=[], strings_not_displayed=[] ):
self.visit_url( '%s/library_common/browse_library?cntrller=%s&id=%s&show_deleted=%s' % ( self.url, cntrller, library_id, str( show_deleted ) ) )
for check_str in strings_displayed:
self.check_page_for_string( check_str )
for check_str in strings_not_displayed:
try:
self.check_page_for_string( check_str )
raise AssertionError( "String (%s) incorrectly displayed when browsing library." % check_str )
except:
pass
def create_library( self, name='Library One', description='This is Library One', synopsis='Synopsis for Library One' ):
"""Create a new library"""
self.visit_url( "%s/library_admin/create_library" % self.url )
self.check_page_for_string( 'Create a new data library' )
tc.fv( "1", "name", name )
tc.fv( "1", "description", description )
tc.fv( "1", "synopsis", synopsis )
tc.submit( "create_library_button" )
check_str = escape( "The new library named '%s' has been created" % name )
self.check_page_for_string( check_str )
def create_form( self, name, description, form_type, field_type='TextField', form_layout_name='',
num_fields=1, num_options=0, field_name='1_field_name', strings_displayed=[],
strings_displayed_after_submit=[] ):
"""Create a new form definition."""
self.visit_url( "%s/forms/create_form_definition" % self.url )
for check_str in strings_displayed:
self.check_page_for_string( check_str )
tc.fv( "create_form_definition", "name", name )
tc.fv( "create_form_definition", "description", description )
tc.fv( "create_form_definition", "form_type_select_field", form_type )
tc.submit( "create_form_button" )
if form_type == "Sequencing Sample Form":
tc.submit( "add_layout_grid" )
tc.fv( "edit_form_definition", "grid_layout0", form_layout_name )
# if not adding any fields at this time, remove the default empty field
if num_fields == 0:
tc.submit( "remove_button" )
# Add fields to the new form definition
for index1 in range( num_fields ):
field_label = 'field_label_%i' % index1
field_contents = field_type
field_help_name = 'field_helptext_%i' % index1
field_help_contents = 'Field %i help' % index1
field_default = 'field_default_0'
field_default_contents = '%s default contents' % form_type
tc.fv( "edit_form_definition", field_label, field_contents )
tc.fv( "edit_form_definition", field_help_name, field_help_contents )
if field_type == 'SelectField':
# SelectField field_type requires a refresh_on_change
self.refresh_form( 'field_type_0', field_type )
# Add options so our select list is functional
if num_options == 0:
# Default to 2 options
num_options = 2
for index2 in range( 1, num_options + 1 ):
tc.submit( "addoption_0" )
# Add contents to the new options fields
for index2 in range( num_options ):
option_field_name = 'field_0_option_%i' % index2
option_field_value = 'Option%i' % index2
tc.fv( "edit_form_definition", option_field_name, option_field_value )
else:
tc.fv( "edit_form_definition", "field_type_0", field_type )
tc.fv( "edit_form_definition", 'field_name_0', field_name )
tc.fv( "edit_form_definition", field_default, field_default_contents )
# All done... now save
tc.submit( "save_changes_button" )
for check_str in strings_displayed_after_submit:
self.check_page_for_string( check_str )
def delete_library_item( self, cntrller, library_id, item_id, item_name, item_type='library_dataset' ):
"""Mark a library item as deleted"""
params = dict( cntrller=cntrller, library_id=library_id, item_id=item_id, item_type=item_type )
self.visit_url( "/library_common/delete_library_item", params )
if item_type == 'library_dataset':
item_desc = 'Dataset'
else:
item_desc = item_type.capitalize()
check_str = "marked deleted"
self.check_for_strings( strings_displayed=[ item_desc, check_str ] )
def edit_template( self, cntrller, item_type, form_type, library_id, field_type, field_label_1, field_helptext_1, field_default_1,
folder_id='', ldda_id='', action='add_field' ):
"""Edit the form fields defining a library template"""
params = dict( cntrller=cntrller, item_type=item_type, form_type=form_type, library_id=library_id )
self.visit_url( "/library_common/edit_template", params=params )
self.check_page_for_string( "Edit form definition" )
if action == 'add_field':
tc.submit( "add_field_button" )
tc.fv( "edit_form", "field_label_1", field_label_1 )
tc.fv( "edit_form", "field_helptext_1", field_helptext_1 )
if field_type == 'SelectField':
# Performs a refresh_on_change in this case
self.refresh_form( "field_type_1", field_type )
else:
tc.fv( "edit_form", "field_type_1", field_type )
tc.fv( "edit_form", "field_default_1", field_default_1 )
tc.submit( 'save_changes_button' )
self.check_page_for_string( "The template for this data library has been updated with your changes." )
def folder_info( self, cntrller, folder_id, library_id, name='', new_name='', description='', template_refresh_field_name='1_field_name',
template_refresh_field_contents='', template_fields=[], strings_displayed=[], strings_not_displayed=[],
strings_displayed_after_submit=[], strings_not_displayed_after_submit=[] ):
"""Add information to a library using an existing template with 2 elements"""
self.visit_url( "%s/library_common/folder_info?cntrller=%s&id=%s&library_id=%s" %
( self.url, cntrller, folder_id, library_id ) )
if name and new_name and description:
tc.fv( '1', "name", new_name )
tc.fv( '1', "description", description )
tc.submit( 'rename_folder_button' )
for check_str in strings_displayed:
self.check_page_for_string( check_str )
for check_str in strings_not_displayed:
try:
self.check_page_for_string( check_str )
raise AssertionError( "String (%s) incorrectly displayed." % check_str )
except:
pass
if template_refresh_field_contents:
# A template containing an AddressField is displayed on the form, so we need to refresh the form
# with the received template_refresh_field_contents. There are 2 forms on the folder_info page
# when in edit mode, and the 2nd one is the one we want.
self.refresh_form( template_refresh_field_name, template_refresh_field_contents, form_no=2 )
if template_fields:
# We have an information template associated with the folder, so
# there are 2 forms on this page and the template is the 2nd form
for field_name, field_value in template_fields:
tc.fv( "edit_info", field_name, field_value )
tc.submit( 'edit_info_button' )
for check_str in strings_displayed_after_submit:
self.check_page_for_string( check_str )
for check_str in strings_not_displayed_after_submit:
try:
self.check_page_for_string( check_str )
raise AssertionError( "String (%s) incorrectly displayed." % check_str )
except:
pass
def ldda_edit_info( self, cntrller, library_id, folder_id, ldda_id, ldda_name, new_ldda_name='', template_refresh_field_name='1_field_name',
template_refresh_field_contents='', template_fields=[], strings_displayed=[], strings_not_displayed=[] ):
"""Edit library_dataset_dataset_association information, optionally template element information"""
self.visit_url( "%s/library_common/ldda_edit_info?cntrller=%s&library_id=%s&folder_id=%s&id=%s" %
( self.url, cntrller, library_id, folder_id, ldda_id ) )
check_str = 'Edit attributes of %s' % ldda_name
self.check_page_for_string( check_str )
if new_ldda_name:
tc.fv( '1', 'name', new_ldda_name )
tc.submit( 'save' )
check_str = escape( "Attributes updated for library dataset '%s'." % new_ldda_name )
self.check_page_for_string( check_str )
if template_refresh_field_contents:
# A template containing an AddressField is displayed on the upload form, so we need to refresh the form
# with the received template_refresh_field_contents. There are 4 forms on this page, and the template is
# contained in the 4th form named "edit_info".
self.refresh_form( template_refresh_field_name, template_refresh_field_contents, form_no=4 )
if template_fields:
# We have an information template associated with the folder, so
# there are 2 forms on this page and the template is the 2nd form
for field_name, field_value in template_fields:
tc.fv( "edit_info", field_name, field_value )
tc.submit( 'edit_info_button' )
for check_str in strings_displayed:
self.check_page_for_string( check_str )
for check_str in strings_not_displayed:
try:
self.check_page_for_string( check_str )
raise AssertionError( "String (%s) should not have been displayed on ldda Edit Attributes page." % check_str )
except:
pass
def library_info( self, cntrller, library_id, library_name='', new_name='', new_description='', new_synopsis='',
template_fields=[], strings_displayed=[] ):
"""Edit information about a library, optionally using an existing template with up to 2 elements"""
self.visit_url( "%s/library_common/library_info?cntrller=%s&id=%s" % ( self.url, cntrller, library_id ) )
for check_str in strings_displayed:
self.check_page_for_string( check_str )
if new_name and new_description and new_synopsis:
tc.fv( '1', 'name', new_name )
tc.fv( '1', 'description', new_description )
tc.fv( '1', 'synopsis', new_synopsis )
tc.submit( 'library_info_button' )
self.check_page_for_string( "Information updated for library" )
if template_fields:
for field_name, field_value in template_fields:
# The 2nd form on the page contains the template, and the form is named edit_info.
# Set the template field value
tc.fv( "edit_info", field_name, field_value )
tc.submit( 'edit_info_button' )
def library_wait( self, library_id, cntrller='library_admin', maxiter=90 ):
"""Waits for the tools to finish"""
count = 0
sleep_amount = 1
while count < maxiter:
count += 1
self.visit_url( "%s/library_common/browse_library?cntrller=%s&id=%s" % ( self.url, cntrller, library_id ) )
page = tc.browser.get_html()
if page.find( '<!-- running: do not change this comment, used by TwillTestCase.library_wait -->' ) > -1:
time.sleep( sleep_amount )
sleep_amount += 1
else:
break
self.assertNotEqual(count, maxiter)
def manage_library_template_inheritance( self, cntrller, item_type, library_id, folder_id=None, ldda_id=None, inheritable=True ):
# If inheritable is True, the item is currently inheritable.
if item_type == 'library':
url = "%s/library_common/manage_template_inheritance?cntrller=%s&item_type=%s&library_id=%s" % \
( self.url, cntrller, item_type, library_id )
elif item_type == 'folder':
url = "%s/library_common/manage_template_inheritance?cntrller=%s&item_type=%s&library_id=%s&folder_id=%s" % \
( self.url, cntrller, item_type, library_id, folder_id )
elif item_type == 'ldda':
url = "%s/library_common/manage_template_inheritance?cntrller=%s&item_type=%s&library_id=%s&folder_id=%s&ldda_id=%s" % \
( self.url, cntrller, item_type, library_id, folder_id, ldda_id )
self.visit_url( url )
if inheritable:
self.check_page_for_string = 'will no longer be inherited to contained folders and datasets'
else:
self.check_page_for_string = 'will now be inherited to contained folders and datasets'
def mark_form_deleted( self, form_id ):
"""Mark a form_definition as deleted"""
url = "%s/forms/delete_form_definition?id=%s" % ( self.url, form_id )
self.visit_url( url )
check_str = "1 forms have been deleted."
self.check_page_for_string( check_str )
def purge_library( self, library_id, library_name ):
"""Purge a library"""
params = dict( id=library_id )
self.visit_url( "/library_admin/purge_library", params )
check_str = "Library '%s' and all of its contents have been purged" % library_name
self.check_page_for_string( check_str )
def upload_library_dataset( self, cntrller, library_id, folder_id, filename='', server_dir='', replace_id='',
upload_option='upload_file', file_type='auto', dbkey='hg18', space_to_tab='',
link_data_only='copy_files', preserve_dirs='Yes', filesystem_paths='', roles=[],
ldda_message='', hda_ids='', template_refresh_field_name='1_field_name',
template_refresh_field_contents='', template_fields=[], show_deleted='False', strings_displayed=[] ):
"""Add datasets to library using any upload_option"""
# NOTE: due to the library_wait() method call at the end of this method, no tests should be done
# for strings_displayed_after_submit.
params = dict( cntrller=cntrller, library_id=library_id, folder_id=folder_id )
url = "/library_common/upload_library_dataset"
if replace_id:
# If we're uploading a new version of a library dataset, we have to include the replace_id param in the
# request because the form field named replace_id will not be displayed on the upload form if we dont.
params[ 'replace_id' ] = replace_id
self.visit_url( url, params=params )
if template_refresh_field_contents:
# A template containing an AddressField is displayed on the upload form, so we need to refresh the form
# with the received template_refresh_field_contents.
self.refresh_form( template_refresh_field_name, template_refresh_field_contents )
for tup in template_fields:
tc.fv( "1", tup[0], tup[1] )
tc.fv( "upload_library_dataset", "library_id", library_id )
tc.fv( "upload_library_dataset", "folder_id", folder_id )
tc.fv( "upload_library_dataset", "show_deleted", show_deleted )
tc.fv( "upload_library_dataset", "ldda_message", ldda_message )
tc.fv( "upload_library_dataset", "file_type", file_type )
tc.fv( "upload_library_dataset", "dbkey", dbkey )
if space_to_tab:
tc.fv( "upload_library_dataset", "space_to_tab", space_to_tab )
for role_id in roles:
tc.fv( "upload_library_dataset", "roles", role_id )
# Refresh the form by selecting the upload_option - we do this here to ensure
# all previously entered form contents are retained.
self.refresh_form( 'upload_option', upload_option )
if upload_option == 'import_from_history':
for check_str in strings_displayed:
self.check_page_for_string( check_str )
if hda_ids:
# Twill cannot handle multi-checkboxes, so the form can only have 1 hda_ids checkbox
try:
tc.fv( "add_history_datasets_to_library", "hda_ids", hda_ids )
except:
tc.fv( "add_history_datasets_to_library", "hda_ids", '1' )
tc.submit( 'add_history_datasets_to_library_button' )
else:
if upload_option in [ 'upload_paths', 'upload_directory' ]:
tc.fv( "upload_library_dataset", "link_data_only", link_data_only )
if upload_option == 'upload_paths':
tc.fv( "upload_library_dataset", "filesystem_paths", filesystem_paths )
if upload_option == 'upload_directory' and server_dir:
tc.fv( "upload_library_dataset", "server_dir", server_dir )
if upload_option == 'upload_file':
if filename:
filename = self.get_filename( filename )
tc.formfile( "upload_library_dataset", "files_0|file_data", filename )
for check_str in strings_displayed:
self.check_page_for_string( check_str )
tc.submit( "runtool_btn" )
# Give the files some time to finish uploading
self.library_wait( library_id )
def view_form( self, id, form_type='', form_name='', form_desc='', form_layout_name='', field_dicts=[] ):
'''View form details'''
self.visit_url( "%s/forms/view_latest_form_definition?id=%s" % ( self.url, id ) )
# self.check_page_for_string( form_type )
self.check_page_for_string( form_name )
# self.check_page_for_string( form_desc )
self.check_page_for_string( form_layout_name )
for i, field_dict in enumerate( field_dicts ):
self.check_page_for_string( field_dict[ 'label' ] )
self.check_page_for_string( field_dict[ 'desc' ] )
self.check_page_for_string( field_dict[ 'type' ] )
if field_dict[ 'type' ].lower() == 'selectfield':
for option_index, option in enumerate( field_dict[ 'selectlist' ] ):
self.check_page_for_string( option )
def test_000_initiate_users( self ):
"""Ensuring all required user accounts exist"""
self.login( email='test1@bx.psu.edu', username='regular-user1' )