2 new commits in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/f8fc2bc86635/ Changeset: f8fc2bc86635 User: Dave Bouvier Date: 2013-11-25 22:23:51 Summary: Add API method to list datatype sniffers. Add functional tests for repositories defining datatype sniffers. Affected #: 1 file diff -r d0a3879c0708983fccb24b809bfe29d96a8dbb59 -r f8fc2bc8663593075a820157606cca11b905e0e9 test/tool_shed/test_data/proteomics_datatypes/proteomics_datatypes.tar Binary file test/tool_shed/test_data/proteomics_datatypes/proteomics_datatypes.tar has changed https://bitbucket.org/galaxy/galaxy-central/commits/ec2a03eea18e/ Changeset: ec2a03eea18e User: Dave Bouvier Date: 2013-11-25 22:29:41 Summary: Add API method to list datatype sniffers. Add functional tests for repositories defining datatype sniffers. Affected #: 4 files diff -r f8fc2bc8663593075a820157606cca11b905e0e9 -r ec2a03eea18ee82c71618d291394da81414cfb45 lib/galaxy/webapps/galaxy/api/datatypes.py --- a/lib/galaxy/webapps/galaxy/api/datatypes.py +++ b/lib/galaxy/webapps/galaxy/api/datatypes.py @@ -4,20 +4,45 @@ from galaxy import web from galaxy.web.base.controller import BaseAPIController +from galaxy.util import asbool import logging log = logging.getLogger( __name__ ) + class DatatypesController( BaseAPIController ): + @web.expose_api_anonymous def index( self, trans, **kwd ): """ GET /api/datatypes - Return an object containing datatypes. + Return an object containing upload datatypes. """ + upload_only = asbool( kwd.get( 'upload_only', True ) ) try: - return trans.app.datatypes_registry.upload_file_formats + if upload_only: + return trans.app.datatypes_registry.upload_file_formats + else: + return [ ext for ext in trans.app.datatypes_registry.datatypes_by_extension ] except Exception, exception: log.error( 'could not get datatypes: %s', str( exception ), exc_info=True ) trans.response.status = 500 return { 'error': str( exception ) } + + @web.expose_api_anonymous + def sniffers( self, trans, **kwd ): + ''' + GET /api/datatypes/sniffers + Return a list of sniffers. + ''' + try: + rval = [] + for sniffer_elem in trans.app.datatypes_registry.sniffer_elems: + datatype = sniffer_elem.get( 'type' ) + if datatype is not None: + rval.append( datatype ) + return rval + except Exception, exception: + log.error( 'could not get datatypes: %s', str( exception ), exc_info=True ) + trans.response.status = 500 + return { 'error': str( exception ) } diff -r f8fc2bc8663593075a820157606cca11b905e0e9 -r ec2a03eea18ee82c71618d291394da81414cfb45 lib/galaxy/webapps/galaxy/buildapp.py --- a/lib/galaxy/webapps/galaxy/buildapp.py +++ b/lib/galaxy/webapps/galaxy/buildapp.py @@ -163,7 +163,11 @@ webapp.mapper.resource( 'workflow', 'workflows', path_prefix='/api' ) webapp.mapper.resource_with_deleted( 'history', 'histories', path_prefix='/api' ) webapp.mapper.resource( 'configuration', 'configuration', path_prefix='/api' ) - webapp.mapper.resource( 'datatype', 'datatypes', path_prefix='/api' ) + webapp.mapper.resource( 'datatype', + 'datatypes', + path_prefix='/api', + collection={ 'sniffers': 'GET' }, + parent_resources=dict( member_name='datatype', collection_name='datatypes' ) ) #webapp.mapper.connect( 'run_workflow', '/api/workflow/{workflow_id}/library/{library_id}', controller='workflows', action='run', workflow_id=None, library_id=None, conditions=dict(method=["GET"]) ) webapp.mapper.resource( 'search', 'search', path_prefix='/api' ) diff -r f8fc2bc8663593075a820157606cca11b905e0e9 -r ec2a03eea18ee82c71618d291394da81414cfb45 test/tool_shed/base/twilltestcase.py --- a/test/tool_shed/base/twilltestcase.py +++ b/test/tool_shed/base/twilltestcase.py @@ -618,13 +618,11 @@ return temp_path def get_datatypes_count( self ): - url = '/admin/view_datatypes_registry' + url = '/api/datatypes?upload_only=false' self.visit_galaxy_url( url ) html = self.last_page() - datatypes_count = re.search( 'registry contains (\d+) data types', html ) - if datatypes_count: - return datatypes_count.group( 1 ) - return None + datatypes = from_json_string( html ) + return len( datatypes ) def get_env_sh_path( self, tool_dependency_name, tool_dependency_version, repository ): '''Return the absolute path to an installed repository's env.sh file.''' @@ -735,6 +733,13 @@ repo = self.get_hg_repo( self.get_repo_path( repository ) ) return str( repo.changectx( repo.changelog.tip() ) ) + def get_sniffers_count( self ): + url = '/api/datatypes/sniffers' + self.visit_galaxy_url( url ) + html = self.last_page() + sniffers = from_json_string( html ) + return len( sniffers ) + def get_tools_from_repository_metadata( self, repository, include_invalid=False ): '''Get a list of valid and (optionally) invalid tool dicts from the repository metadata.''' valid_tools = [] diff -r f8fc2bc8663593075a820157606cca11b905e0e9 -r ec2a03eea18ee82c71618d291394da81414cfb45 test/tool_shed/functional/test_1450_installing_datatypes_sniffers.py --- /dev/null +++ b/test/tool_shed/functional/test_1450_installing_datatypes_sniffers.py @@ -0,0 +1,191 @@ +from tool_shed.base.twilltestcase import ShedTwillTestCase, common, os +import tool_shed.base.test_db_util as test_db_util + +repository_name = 'proteomics_datatypes_1450' +repository_description = "Proteomics datatypes" +repository_long_description = "Datatypes used in proteomics" + +category_name = 'Test 1450 Datatype Sniffers' +category_description = 'Test 1450 - Installing Datatype Sniffers' + + +''' +1. Get a count of datatypes and sniffers. +2. Install proteomics_datatypes_1450. +3. Verify the count of datatypes and sniffers is the previous count + the datatypes contained within proteomics_datatypes_1450. +4. Deactivate proteomics_datatypes_1450, verify the count of datatypes and sniffers is equal to the count determined in step 1. +5. Reactivate proteomics_datatypes_1450, verify that the count of datatypes and sniffers has been increased by the contents of the repository. +6. Uninstall proteomics_datatypes_1450, verify the count of datatypes and sniffers is equal to the count determined in step 1. +7. Reinstall proteomics_datatypes_1450, verify that the count of datatypes and sniffers has been increased by the contents of the repository. +''' + +base_datatypes_count = 0 +repository_datatypes_count = 0 +base_sniffers_count = 0 + + +class TestInstallDatatypesSniffers( ShedTwillTestCase ): + '''Test installing a repository that defines datatypes and datatype sniffers.''' + + def test_0000_initiate_users( self ): + """Create necessary user accounts.""" + global base_datatypes_count + self.logout() + self.login( email=common.test_user_1_email, username=common.test_user_1_name ) + test_user_1 = test_db_util.get_user( common.test_user_1_email ) + assert test_user_1 is not None, 'Problem retrieving user with email %s from the database' % test_user_1_email + test_user_1_private_role = test_db_util.get_private_role( test_user_1 ) + self.logout() + self.login( email=common.admin_email, username=common.admin_username ) + admin_user = test_db_util.get_user( common.admin_email ) + assert admin_user is not None, 'Problem retrieving user with email %s from the database' % common.admin_email + admin_user_private_role = test_db_util.get_private_role( admin_user ) + self.galaxy_logout() + self.galaxy_login( email=common.admin_email, username=common.admin_username ) + galaxy_admin_user = test_db_util.get_galaxy_user( common.admin_email ) + assert galaxy_admin_user is not None, 'Problem retrieving user with email %s from the database' % common.admin_email + galaxy_admin_user_private_role = test_db_util.get_galaxy_private_role( galaxy_admin_user ) + base_datatypes_count = self.get_datatypes_count() + base_sniffers_count = self.get_sniffers_count() + + def test_0005_ensure_repositories_and_categories_exist( self ): + '''Create the 1450 category and proteomics_datatypes_1450 repository.''' + global repository_datatypes_count + category = self.create_category( name=category_name, description=category_description ) + self.logout() + self.login( email=common.test_user_1_email, username=common.test_user_1_name ) + repository = self.get_or_create_repository( name=repository_name, + description=repository_description, + long_description=repository_long_description, + owner=common.test_user_1_name, + category_id=self.security.encode_id( category.id ), + strings_displayed=[] ) + if self.repository_is_new( repository ): + self.upload_file( repository, + filename='proteomics_datatypes/proteomics_datatypes.tar', + filepath=None, + valid_tools_only=True, + uncompress_file=False, + remove_repo_files_not_in_tar=False, + commit_message='Uploaded datatype and sniffer definitions.', + strings_displayed=[], + strings_not_displayed=[] ) + repository_datatypes_count = self.get_repository_datatypes_count( repository ) + + def test_0010_install_datatypes_repository( self ): + '''Install the proteomics_datatypes_1450 repository into the Galaxy instance.''' + ''' + This includes steps 1 and 2 - Get a count of datatypes and sniffers. + Store a count of the current datatypes registry and sniffers in global variables, to compare with the updated count + after changing the installation status of the proteomics_datatypes_1450 repository. + ''' + global repository_datatypes_count + global base_datatypes_count + global base_sniffers_count + base_sniffers_count = self.get_sniffers_count() + self.galaxy_logout() + self.galaxy_login( email=common.admin_email, username=common.admin_username ) + strings_displayed = [ 'proteomics' ] + self.install_repository( 'proteomics_datatypes_1450', + common.test_user_1_name, + category_name, + strings_displayed=strings_displayed, + new_tool_panel_section='test_1450' ) + installed_repository = test_db_util.get_installed_repository_by_name_owner( 'proteomics_datatypes_1450', common.test_user_1_name ) + strings_displayed = [ 'user1', + self.url.replace( 'http://', '' ), + installed_repository.installed_changeset_revision ] + self.display_galaxy_browse_repositories_page( strings_displayed=strings_displayed ) + + def test_0015_verify_datatypes_count( self ): + '''Verify that datatypes were added in the previous step.''' + ''' + This is step 3 - Verify the count of datatypes and sniffers is the previous count + the datatypes + contained within proteomics_datatypes_1450. + Compare the current datatypes registry and sniffers with the values that were retrieved in the previous step. + ''' + current_datatypes = self.get_datatypes_count() + assert current_datatypes == base_datatypes_count + repository_datatypes_count, \ + 'Found %d datatypes, expected %d.' % ( current_datatypes, base_datatypes_count + repository_datatypes_count ) + current_sniffers = self.get_sniffers_count() + assert current_sniffers > base_sniffers_count, \ + 'Sniffer count after installing proteomics_datatypes_1450 is %d, which is not greater than %d' % \ + ( current_sniffers, base_sniffers_count ) + + def test_0020_deactivate_datatypes_repository( self ): + '''Deactivate the installed proteomics_datatypes_1450 repository.''' + ''' + This is step 4 - Deactivate proteomics_datatypes_1450, verify the count of datatypes and sniffers is equal to + the count determined in step 1. + Deactivate proteomics_datatypes_1450 and check that the in-memory datatypes and sniffers match the base values + determined in the first step. + ''' + repository = test_db_util.get_installed_repository_by_name_owner( repository_name, common.test_user_1_name ) + global repository_datatypes_count + global base_datatypes_count + global base_sniffers_count + self.uninstall_repository( repository, remove_from_disk=False ) + new_datatypes_count = self.get_datatypes_count() + assert new_datatypes_count == base_datatypes_count, 'Expected %d datatypes, got %d' % ( base_datatypes_count, new_datatypes_count ) + current_sniffers = self.get_sniffers_count() + assert current_sniffers == base_sniffers_count, \ + 'Sniffer count after deactivating proteomics_datatypes_1450 is %d, expected %d' % \ + ( current_sniffers, base_sniffers_count ) + + def test_0025_reactivate_datatypes_repository( self ): + '''Reactivate the deactivated proteomics_datatypes_1450 repository.''' + ''' + This is step 5 - Reactivate proteomics_datatypes, verify that the count of datatypes and sniffers has been + increased by the contents of the repository. + ''' + repository = test_db_util.get_installed_repository_by_name_owner( repository_name, common.test_user_1_name ) + global repository_datatypes_count + global base_datatypes_count + global base_sniffers_count + self.reactivate_repository( repository ) + new_datatypes_count = self.get_datatypes_count() + assert new_datatypes_count == base_datatypes_count + repository_datatypes_count, \ + 'Found %d datatypes, expected %d.' % ( new_datatypes_count, base_datatypes_count + repository_datatypes_count ) + current_sniffers = self.get_sniffers_count() + assert current_sniffers > base_sniffers_count, \ + 'Sniffer count after reactivating proteomics_datatypes_1450 is %d, which is not greater than %d' % \ + ( current_sniffers, base_sniffers_count ) + + def test_0030_uninstall_datatypes_repository( self ): + '''Uninstall the installed proteomics_datatypes_1450 repository.''' + ''' + This is step 6 - Uninstall proteomics_datatypes_1450, verify the count of datatypes and sniffers is equal + to the count determined in step 1. + Uninstall proteomics_datatypes_1450 and check that the in-memory datatypes and sniffers match the base values + determined in the first step. + ''' + repository = test_db_util.get_installed_repository_by_name_owner( repository_name, common.test_user_1_name ) + global repository_datatypes_count + global base_datatypes_count + self.uninstall_repository( repository, remove_from_disk=True ) + new_datatypes_count = self.get_datatypes_count() + assert new_datatypes_count == base_datatypes_count, 'Expected %d datatypes, got %d' % ( base_datatypes_count, new_datatypes_count ) + current_sniffers = self.get_sniffers_count() + assert current_sniffers == base_sniffers_count, \ + 'Sniffer count after uninstalling proteomics_datatypes_1450 is %d, expected %d' % \ + ( current_sniffers, base_sniffers_count ) + + def test_0035_reinstall_datatypes_repository( self ): + '''Reinstall the uninstalled proteomics_datatypes_1450 repository.''' + ''' + This is step 7 - Reinstall proteomics_datatypes_1450, verify that the count of datatypes and sniffers has been + increased by the contents of the repository. + ''' + repository = test_db_util.get_installed_repository_by_name_owner( repository_name, common.test_user_1_name ) + global repository_datatypes_count + global base_datatypes_count + self.reinstall_repository( repository ) + new_datatypes_count = self.get_datatypes_count() + assert new_datatypes_count == base_datatypes_count + repository_datatypes_count, \ + 'Found %d datatypes, expected %d.' % ( new_datatypes_count, base_datatypes_count + repository_datatypes_count ) + current_sniffers = self.get_sniffers_count() + assert current_sniffers > base_sniffers_count, \ + 'Sniffer count after reinstalling proteomics_datatypes_1450 is %d, which is not greater than %d' % \ + ( current_sniffers, base_sniffers_count ) + + 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.