
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/changeset/d69b780edd18/ changeset: d69b780edd18 user: inithello date: 2012-11-20 15:17:41 summary: Extend the tool shed functional test framework. affected #: 3 files diff -r 0741ac889c4b85286a9baadcf6110f3e052a79f0 -r d69b780edd1816171c2751e2ce4d987f7254019e test/tool_shed/base/test_db_util.py --- a/test/tool_shed/base/test_db_util.py +++ b/test/tool_shed/base/test_db_util.py @@ -2,6 +2,7 @@ from galaxy.model.orm import * from galaxy.webapps.community.model.mapping import context as sa_session from base.twilltestcase import * +from sqlalchemy import desc import sys def delete_obj( obj ): @@ -31,9 +32,20 @@ return sa_session.query( model.User ) \ .filter( model.User.table.c.email==email ) \ .first() +def get_user_by_name( username ): + return sa_session.query( model.User ) \ + .filter( model.User.table.c.username==username ) \ + .first() def mark_obj_deleted( obj ): obj.deleted = True sa_session.add( obj ) sa_session.flush() def refresh( obj ): sa_session.refresh( obj ) +def get_repository_by_name( name, owner_username ): + owner = get_user_by_name( owner_username ) + repository = sa_session.query( model.Repository ) \ + .filter( model.Repository.table.c.name==name ) \ + .filter( model.Repository.table.c.user_id==owner.id ) \ + .first() + return repository diff -r 0741ac889c4b85286a9baadcf6110f3e052a79f0 -r d69b780edd1816171c2751e2ce4d987f7254019e test/tool_shed/base/twilltestcase.py --- a/test/tool_shed/base/twilltestcase.py +++ b/test/tool_shed/base/twilltestcase.py @@ -1,4 +1,5 @@ from base.twilltestcase import * +from tool_shed.base.test_db_util import * class ShedTwillTestCase( TwillTestCase ): def setUp( self ): @@ -18,3 +19,123 @@ except: pass self.home() + def browse_repository( self, repository, strings_displayed=[], strings_not_displayed=[] ): + url = '/repository/browse_repository?id=%s' % self.security.encode_id( repository.id ) + self.visit_url( url ) + self.check_for_strings( strings_displayed, strings_not_displayed ) + def check_for_strings( self, strings_displayed=[], strings_not_displayed=[] ): + if strings_displayed: + for string in strings_displayed: + self.check_page_for_string( string ) + if strings_not_displayed: + for string in strings_not_displayed: + self.check_string_not_in_page( string ) + def check_for_valid_tools( self, repository ): + self.manage_repository( repository ) + self.check_page_for_string( '<b>Valid tools</b><i> - click the name to preview the tool' ) + def check_repository_changelog( self, repository, strings_displayed=[], strings_not_displayed=[] ): + url = '/repository/view_changelog?id=%s' % self.security.encode_id( repository.id ) + self.visit_url( url ) + self.check_for_strings( strings_displayed, strings_not_displayed ) + def create_category( self, category_name, category_description ): + self.visit_url( '/admin/manage_categories?operation=create' ) + tc.fv( "1", "name", category_name ) + tc.fv( "1", "description", category_description ) + tc.submit( "create_category_button" ) + def create_repository( self, repository_name, repository_description, repository_long_description=None, categories=[], strings_displayed=[], strings_not_displayed=[] ): + self.visit_url( '/repository/create_repository' ) + tc.fv( "1", "name", repository_name ) + tc.fv( "1", "description", repository_description ) + if repository_long_description is not None: + tc.fv( "1", "long_description", repository_long_description ) + for category in categories: + tc.fv( "1", "category_id", "+%s" % category ) + tc.submit( "create_repository_button" ) + self.check_for_strings( strings_displayed, strings_not_displayed ) + def display_repository_clone_page( self, owner_name, repository_name, strings_displayed=[], strings_not_displayed=[] ): + url = '/repos/%s/%s' % ( owner_name, repository_name ) + self.visit_url( url ) + self.check_for_strings( strings_displayed, strings_not_displayed ) + def edit_repository_categories( self, repository, categories_to_add=[], categories_to_remove=[], restore_original=True ): + url = '/repository/manage_repository?id=%s' % self.security.encode_id( repository.id ) + self.visit_url( url ) + strings_displayed = [] + strings_not_displayed = [] + for category in categories_to_add: + tc.fv( "2", "category_id", '+%s' % category) + strings_displayed.append( "selected>%s</option>" % category ) + for category in categories_to_remove: + tc.fv( "2", "category_id", '-%s' % category) + strings_not_displayed.append( "selected>%s</option>" % category ) + tc.submit( "manage_categories_button" ) + self.check_for_strings( strings_displayed, strings_not_displayed ) + if restore_original: + strings_displayed = [] + strings_not_displayed = [] + for category in categories_to_remove: + tc.fv( "2", "category_id", '+%s' % category) + strings_displayed.append( "selected>%s</option>" % category ) + for category in categories_to_add: + tc.fv( "2", "category_id", '-%s' % category) + strings_not_displayed.append( "selected>%s</option>" % category ) + tc.submit( "manage_categories_button" ) + self.check_for_strings( strings_displayed, strings_not_displayed ) + def edit_repository_information( self, repository, **kwargs ): + url = '/repository/manage_repository?id=%s' % self.security.encode_id( repository.id ) + self.visit_url( url ) + original_information = dict( repo_name=repository.name, description=repository.description, long_description=repository.long_description ) + strings_displayed = [] + strings_not_displayed = [] + for input_elem_name in [ 'repo_name', 'description', 'long_description' ]: + if input_elem_name in kwargs: + tc.fv( "1", input_elem_name, kwargs[ input_elem_name ] ) + strings_displayed.append( self.escape_html( kwargs[ input_elem_name ] ) ) + tc.submit( "edit_repository_button" ) + self.check_for_strings( strings_displayed ) + strings_displayed = [] + for input_elem_name in [ 'repo_name', 'description', 'long_description' ]: + tc.fv( "1", input_elem_name, original_information[ input_elem_name ] ) + strings_displayed.append( self.escape_html( original_information[ input_elem_name ] ) ) + tc.submit( "edit_repository_button" ) + self.check_for_strings( strings_displayed ) + def escape_html( self, string ): + html_entities = [ ('&', 'X' ), ( "'", ''' ), ( '"', '"' ) ] + for character, replacement in html_entities: + string = string.replace( character, replacement ) + return string + def get_latest_repository_metadata_for_repository( self, repository ): + return repository.metadata_revisions[ 0 ] + def get_readme( self, repository, strings_displayed=[], strings_not_displayed=[] ): + repository_metadata = self.get_latest_repository_metadata_for_repository( repository ) + changeset_revision = repository_metadata.changeset_revision + repository_id = self.security.encode_id( repository.id ) + self.visit_url( '/repository/view_readme?changeset_revision=%s&id=%s' % ( changeset_revision, repository_id ) ) + self.check_for_strings( strings_displayed, strings_not_displayed ) + def grant_write_access( self, repository, usernames=[], strings_displayed=[], strings_not_displayed=[] ): + self.manage_repository( repository ) + tc.fv( "3", "allow_push", '-Select one' ) + for username in usernames: + tc.fv( "3", "allow_push", '+%s' % username ) + tc.submit( 'user_access_button' ) + self.check_for_strings( strings_displayed, strings_not_displayed ) + def manage_repository( self, repository, strings_displayed=[], strings_not_displayed=[] ): + url = '/repository/manage_repository?id=%s' % self.security.encode_id( repository.id ) + self.visit_url( url ) + self.check_for_strings( strings_displayed, strings_not_displayed ) + def set_repository_malicious( self, repository, strings_displayed=[], strings_not_displayed=[] ): + self.manage_repository( repository ) + tc.fv( "malicious", "malicious", True ) + tc.submit( "malicious_button" ) + self.check_for_strings( strings_displayed, strings_not_displayed ) + def unset_repository_malicious( self, repository, strings_displayed=[], strings_not_displayed=[] ): + self.manage_repository( repository ) + tc.fv( "malicious", "malicious", False ) + tc.submit( "malicious_button" ) + self.check_for_strings( strings_displayed, strings_not_displayed ) + def upload( self, repository, filename, strings_displayed=[], strings_not_displayed=[], **kwargs ): + self.visit_url( '/upload/upload?repository_id=%s' % self.security.encode_id( repository.id ) ) + for key in kwargs: + tc.fv( "1", key, kwargs[ key ] ) + tc.formfile( "1", "file_data", filename ) + tc.submit( "upload_button" ) + self.check_for_strings( strings_displayed, strings_not_displayed ) diff -r 0741ac889c4b85286a9baadcf6110f3e052a79f0 -r d69b780edd1816171c2751e2ce4d987f7254019e test/tool_shed/functional/test_0000_create_repository.py --- a/test/tool_shed/functional/test_0000_create_repository.py +++ b/test/tool_shed/functional/test_0000_create_repository.py @@ -11,34 +11,77 @@ admin_email = 'test@bx.psu.edu' admin_username = 'admin-user' +regular_user = None +regular_user_private_role = None +regular_email = 'test-1@bx.psu.edu' +regular_username = 'user1' + +repository_name = 'filter' +repository_description = "Galaxy's filter tool" +repository_long_description = "Long description of Galaxy's filter tool" +files_path = os.path.abspath( os.path.join( "test", "tool_shed", "test_data" ) ) +filter_filename = os.path.join( files_path, "filtering_1.1.0.tar" ) + class TestCreateRepository( ShedTwillTestCase ): def test_0000_initiate_users( self ): """Create necessary users and login as an admin user.""" + self.login( email=regular_email, username=regular_username ) + regular_user = get_user( regular_email ) + assert regular_user is not None, 'Problem retrieving user with email %s from the database' % regular_email + regular_user_private_role = get_private_role( regular_user ) self.logout() self.login( email=admin_email, username=admin_username ) admin_user = get_user( admin_email ) assert admin_user is not None, 'Problem retrieving user with email %s from the database' % admin_email admin_user_private_role = get_private_role( admin_user ) - def test_0005_create_category( self ): + def test_0005_create_categories( self ): """Create a category""" - self.visit_url( '/admin/manage_categories?operation=create' ) - try: - tc.fv( "1", "name", "Text Manipulation" ) - tc.fv( "1", "description", "Tools for manipulating text" ) - tc.submit( "create_category_button" ) - except Exception, e: - errmsg = "Problem creating a category: %s" % str( e ) - raise AssertionError( e ) - def test_0010_create_filter_repository( self ): + self.create_category( 'Text Manipulation', 'Tools for manipulating text' ) + self.create_category( 'Text Analysis', 'Tools for analyzing text' ) + def test_0010_create_repository( self ): """Create a repository""" - self.visit_url( '/repository/create_repository' ) - try: - tc.fv( "1", "name", "filter" ) - tc.fv( "1", "description", "Galaxy's filter tool" ) - tc.fv( "1", "long_description", "Long description of Galaxy's filter tool" ) - tc.fv( "1", "category_id", "Text Manipulation" ) - tc.submit( "create_repository_button" ) - except Exception, e: - errmsg = "Problem creating a repository: %s" % str( e ) - raise AssertionError( e ) + strings_displayed = [ '<div class="toolFormTitle">Repository %s</div>' % "'%s'" % repository_name, \ + 'Repository %s has been created' % "'%s'" % repository_name ] + self.create_repository( repository_name, repository_description, \ + repository_long_description=repository_long_description, \ + categories=[ 'Text Manipulation' ], \ + strings_displayed=strings_displayed ) + def test_0015_edit_repository( self ): + """Edit the repository name, description, and long description""" + repository = get_repository_by_name( repository_name, admin_username ) + new_name = "renamed_filter" + new_description = "Edited filter tool" + new_long_description = "Edited long description" + self.edit_repository_information( repository, repo_name=new_name, description=new_description, long_description=new_long_description ) + def test_0020_change_repository_category( self ): + """Change the category of a repository""" + repository = get_repository_by_name( repository_name, admin_username ) + self.edit_repository_categories( repository, categories_to_add=[ "Text Analysis" ], categories_to_remove=[ "Text Manipulation" ] ) +# def test_0025_grant_write_access( self ): +# '''Grant write access to another user''' +# repository = get_repository_by_name( repository_name, admin_username ) +# self.grant_write_access( repository, usernames=[ regular_username ] ) + def test_0030_upload_tarball( self ): + """Upload filtering_1.1.0.tar to the repository""" + repository = get_repository_by_name( repository_name, admin_username ) + self.upload( repository, filter_filename, \ + strings_displayed=[ "The file '%s' has been successfully uploaded to the repository." % filter_filename ], \ + commit_message="Uploaded filtering 1.1.0" ) + self.check_for_valid_tools( repository ) + latest_changeset_revision = self.get_latest_repository_metadata_for_repository( repository ) + self.check_repository_changelog( repository, strings_displayed=[ 'Repository metadata is associated with this change set.' ] ) + self.set_repository_malicious( repository, strings_displayed=[ 'The repository tip has been defined as malicious.' ] ) + self.unset_repository_malicious( repository, strings_displayed=[ 'The repository tip has been defined as <b>not</b> malicious.' ] ) +# self.check_tool_metadata( repository, latest_changeset_revision, strings_displayed=[ 'Filter1' ] ) + def test_0035_repository_browse_page( self ): + '''Visit the repository browse page''' + repository = get_repository_by_name( repository_name, admin_username ) + self.browse_repository( repository, strings_displayed=[ 'Browse %s revision' % repository.name, '(repository tip)' ] ) + def test_0040_visit_clone_url_via_hgweb( self ): + '''Visit the repository clone URL via hgweb''' + repository = get_repository_by_name( repository_name, admin_username ) + latest_changeset_revision = self.get_latest_repository_metadata_for_repository( repository ) + self.display_repository_clone_page( admin_username, \ + repository_name, \ + strings_displayed=[ 'Uploaded filtering 1.1.0', latest_changeset_revision.changeset_revision ] ) 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.