def test_00_metadata_edit(self):
     """test_metadata_edit: Testing metadata editing"""
     sa_session = database_contexts.galaxy_context
     self.logout()
     self.login(email='*****@*****.**', username='******')
     admin_user = sa_session.query( galaxy.model.User ) \
                           .filter( galaxy.model.User.table.c.email == '*****@*****.**' ) \
                           .one()
     self.new_history(name='Test Metadata Edit')
     history1 = sa_session.query( galaxy.model.History ) \
                         .filter( and_( galaxy.model.History.table.c.deleted == False,
                                        galaxy.model.History.table.c.user_id == admin_user.id ) ) \
                         .order_by( desc( galaxy.model.History.table.c.create_time ) ) \
                         .first()
     self.upload_file('1.bed')
     latest_hda = sa_session.query( galaxy.model.HistoryDatasetAssociation ) \
                           .order_by( desc( galaxy.model.HistoryDatasetAssociation.table.c.create_time ) ) \
                           .first()
     # Due to twill not being able to handle the permissions forms, we'll eliminate
     # DefaultHistoryPermissions prior to uploading a dataset so that the permission
     # form will not be displayed on ted edit attributes page.
     for dp in latest_hda.dataset.actions:
         sa_session.delete(dp)
         sa_session.flush()
     sa_session.refresh(latest_hda.dataset)
     self.check_history_for_string('1.bed')
     self.check_metadata_for_string(
         '1.bed uploaded file unspecified (\?) chromCol value="1" selected endCol value="3" is_strandCol value="true" checked',
         hid=str(latest_hda.hid))
     """test editing attributes"""
     self.edit_hda_attribute_info(hda_id=str(latest_hda.id),
                                  new_name='Testdata',
                                  new_info="Uploaded my file",
                                  new_dbkey='hg16',
                                  new_startcol='6')
     self.check_metadata_for_string(
         'Testdata bed Uploaded my file hg16 "bed" selected="yes" "startCol" value="6" selected',
         hid=str(latest_hda.hid))
     """test Auto-detecting attributes"""
     self.auto_detect_metadata(hda_id=str(latest_hda.id))
     self.check_metadata_for_string(
         'Testdata bed Uploaded my file hg16 "bed" selected="yes" "startCol" value="2" selected',
         hid=str(latest_hda.hid))
     """test converting formats"""
     self.convert_format(hda_id=str(latest_hda.id), target_type='gff')
     self.check_metadata_for_string('"gff" selected="yes"',
                                    hid=str(latest_hda.hid))
     """test changing data type"""
     self.change_datatype(hda_id=str(latest_hda.id), datatype='gff3')
     self.check_metadata_for_string('gff3', hid=str(latest_hda.hid))
     self.delete_history(id=self.security.encode_id(history1.id))
     self.logout()
Example #2
0
    def index( self, trans, deleted='False', **kwd ):
        """
        GET /api/histories
        GET /api/histories/deleted
        Displays a collection (list) of histories.
        """
        #TODO: query (by name, date, etc.)
        rval = []
        deleted = string_as_bool( deleted )
        try:
            if trans.user:
                query = trans.sa_session.query(trans.app.model.History ).filter_by( user=trans.user, deleted=deleted ).order_by(
                    desc(trans.app.model.History.table.c.update_time)).all()
                for history in query:
                    item = history.get_api_value(value_mapper={'id':trans.security.encode_id})
                    item['url'] = url_for( 'history', id=trans.security.encode_id( history.id ) )
                    rval.append( item )

            elif trans.galaxy_session.current_history:
                #No user, this must be session authentication with an anonymous user.
                history = trans.galaxy_session.current_history
                item = history.get_api_value(value_mapper={'id':trans.security.encode_id})
                item['url'] = url_for( 'history', id=trans.security.encode_id( history.id ) )
                rval.append(item)

        except Exception, e:
            rval = "Error in history API"
            log.error( rval + ": %s" % str(e) )
            trans.response.status = 500
 def test_00_metadata_edit( self ):
     """test_metadata_edit: Testing metadata editing"""
     sa_session = database_contexts.galaxy_context
     self.logout()
     self.login( email='*****@*****.**', username='******' )
     admin_user = sa_session.query( galaxy.model.User ) \
                           .filter( galaxy.model.User.table.c.email == '*****@*****.**' ) \
                           .one()
     self.new_history( name='Test Metadata Edit' )
     history1 = sa_session.query( galaxy.model.History ) \
                         .filter( and_( galaxy.model.History.table.c.deleted == False,
                                        galaxy.model.History.table.c.user_id == admin_user.id ) ) \
                         .order_by( desc( galaxy.model.History.table.c.create_time ) ) \
                         .first()
     self.upload_file( '1.bed' )
     latest_hda = sa_session.query( galaxy.model.HistoryDatasetAssociation ) \
                           .order_by( desc( galaxy.model.HistoryDatasetAssociation.table.c.create_time ) ) \
                           .first()
     self.home()
     # Due to twill not being able to handle the permissions forms, we'll eliminate
     # DefaultHistoryPermissions prior to uploading a dataset so that the permission
     # form will not be displayed on ted edit attributes page.
     for dp in latest_hda.dataset.actions:
         sa_session.delete( dp )
         sa_session.flush()
     sa_session.refresh( latest_hda.dataset )
     self.check_history_for_string( '1.bed' )
     self.check_metadata_for_string( '1.bed uploaded file unspecified (\?) chromCol value="1" selected endCol value="3" is_strandCol value="true" checked', hid=str( latest_hda.hid ) )
     """test editing attributes"""
     self.edit_hda_attribute_info( hda_id=str( latest_hda.id ),
                                   new_name='Testdata',
                                   new_info="Uploaded my file",
                                   new_dbkey='hg16',
                                   new_startcol='6' )
     self.check_metadata_for_string( 'Testdata bed Uploaded my file hg16 "bed" selected="yes" "startCol" value="6" selected', hid=str( latest_hda.hid ) )
     """test Auto-detecting attributes"""
     self.auto_detect_metadata( hda_id=str( latest_hda.id ) )
     self.check_metadata_for_string('Testdata bed Uploaded my file hg16 "bed" selected="yes" "startCol" value="2" selected', hid=str( latest_hda.hid ) )
     """test converting formats"""
     self.convert_format( hda_id=str( latest_hda.id ), target_type='gff' )
     self.check_metadata_for_string( '"gff" selected="yes"', hid=str( latest_hda.hid ) )
     """test changing data type"""
     self.change_datatype( hda_id=str( latest_hda.id ), datatype='gff3' )
     self.check_metadata_for_string( 'gff3', hid=str( latest_hda.hid ) )
     self.delete_history( id=self.security.encode_id( history1.id ) )
     self.logout()
Example #4
0
 def disk_usage( self, trans, **kwd ):
     file_path = trans.app.config.file_path
     disk_usage = self.get_disk_usage( file_path )
     min_file_size = 2**32 # 4 Gb
     file_size_str = nice_size( min_file_size )
     datasets = trans.sa_session.query( model.Dataset ) \
                                .filter( and_( model.Dataset.table.c.purged == False,
                                               model.Dataset.table.c.file_size > min_file_size ) ) \
                                .order_by( desc( model.Dataset.table.c.file_size ) )
     return file_path, disk_usage, datasets, file_size_str
Example #5
0
 def disk_usage( self, trans, **kwd ):
     file_path = trans.app.config.file_path
     disk_usage = self.get_disk_usage( file_path )
     min_file_size = 2**32 # 4 Gb
     file_size_str = nice_size( min_file_size )
     datasets = trans.sa_session.query( model.Dataset ) \
                                .filter( and_( model.Dataset.table.c.purged == False,
                                               model.Dataset.table.c.file_size > min_file_size ) ) \
                                .order_by( desc( model.Dataset.table.c.file_size ) )
     return file_path, disk_usage, datasets, file_size_str
    def most_recent( self, trans, user=None, deleted=False ):
        user = user or trans.user
        if not user:
            return None if trans.history.deleted else trans.history

        #TODO: dup with by_user - should return query from there and call first and not all
        history_model = trans.model.History
        query = ( trans.sa_session.query( history_model )
                  .filter( history_model.user == user )
                  .order_by( orm.desc( history_model.table.c.update_time ) ) )
        if not deleted:
            query = query.filter( history_model.deleted == False )
        return query.first()
Example #7
0
    def most_recent(self, trans, user=None, deleted=False):
        user = user or trans.user
        if not user:
            return None if trans.history.deleted else trans.history

        #TODO: dup with by_user - should return query from there and call first and not all
        history_model = trans.model.History
        query = (trans.sa_session.query(history_model).filter(
            history_model.user == user).order_by(
                orm.desc(history_model.table.c.update_time)))
        if not deleted:
            query = query.filter(history_model.deleted == False)
        return query.first()
Example #8
0
 def new_history( self ):
     # Start with a new history
     self.twill_test_case.logout()
     self.twill_test_case.login( email='*****@*****.**' )
     admin_user = database_contexts.galaxy_context.query( galaxy.model.User ).filter( galaxy.model.User.table.c.email == '*****@*****.**' ).one()
     self.twill_test_case.new_history()
     latest_history = database_contexts.galaxy_context.query( galaxy.model.History ) \
                                .filter( and_( galaxy.model.History.table.c.deleted == False,
                                               galaxy.model.History.table.c.user_id == admin_user.id ) ) \
                                .order_by( desc( galaxy.model.History.table.c.create_time ) ) \
                                .first()
     assert latest_history is not None, "Problem retrieving latest_history from database"
     if len( self.twill_test_case.get_history_as_data_list() ) > 0:
         raise AssertionError("ToolTestCase.do_it failed")
     return latest_history
    def by_user( self, trans, user=None, include_deleted=False, only_deleted=False ):
        """
        Get all the histories for a given user (defaulting to `trans.user`)
        ordered by update time and filtered on whether they've been deleted.
        """
        # handle default and/or anonymous user (which still may not have a history yet)
        user = user or trans.user
        if not user:
            current_history = trans.get_history()
            return [ current_history ] if current_history else []

        history_model = trans.model.History
        query = ( trans.sa_session.query( history_model )
                  .filter( history_model.user == user )
                  .order_by( orm.desc( history_model.table.c.update_time ) ) )
        if only_deleted:
            query = query.filter( history_model.deleted == True )
        elif not include_deleted:
            query = query.filter( history_model.deleted == False )
        return query.all()
Example #10
0
    def by_user( self, trans, user=None, include_deleted=False, only_deleted=False ):
        """
        Get all the histories for a given user (defaulting to `trans.user`)
        ordered by update time and filtered on whether they've been deleted.
        """
        # handle default and/or anonymous user (which still may not have a history yet)
        user = user or trans.user
        if not user:
            current_history = trans.get_history()
            return [ current_history ] if current_history else []

        history_model = trans.model.History
        query = ( trans.sa_session.query( history_model )
                  .filter( history_model.user == user )
                  .order_by( orm.desc( history_model.table.c.update_time ) ) )
        if only_deleted:
            query = query.filter( history_model.deleted == True )
        elif not include_deleted:
            query = query.filter( history_model.deleted == False )
        return query.all()
Example #11
0
 def new_history(self):
     # Start with a new history
     self.twill_test_case.logout()
     self.twill_test_case.login(email='*****@*****.**')
     admin_user = database_contexts.galaxy_context.query(
         galaxy.model.User).filter(
             galaxy.model.User.table.c.email == '*****@*****.**').one()
     self.twill_test_case.new_history()
     latest_history = database_contexts.galaxy_context.query( galaxy.model.History ) \
                                .filter( and_( galaxy.model.History.table.c.deleted == False,
                                               galaxy.model.History.table.c.user_id == admin_user.id ) ) \
                                .order_by( desc( galaxy.model.History.table.c.create_time ) ) \
                                .first()
     assert latest_history is not None, "Problem retrieving latest_history from database"
     if len(
             self.twill_test_case.get_hids_in_history(
                 self.twill_test_case.get_latest_history()['id'])) > 0:
         raise AssertionError(
             "ToolTestCase.do_it failed to create a new empty history")
     return latest_history
Example #12
0
    def index(self, trans, deleted='False', **kwd):
        """
        GET /api/histories
        GET /api/histories/deleted
        Displays a collection (list) of histories.
        """
        #TODO: query (by name, date, etc.)
        rval = []
        deleted = string_as_bool(deleted)
        try:
            if trans.user:
                query = trans.sa_session.query(
                    trans.app.model.History
                ).filter_by(user=trans.user, deleted=deleted).order_by(
                    desc(trans.app.model.History.table.c.update_time)).all()
                for history in query:
                    item = history.get_api_value(
                        value_mapper={'id': trans.security.encode_id})
                    item['url'] = url_for('history',
                                          id=trans.security.encode_id(
                                              history.id))
                    rval.append(item)

            elif trans.galaxy_session.current_history:
                #No user, this must be session authentication with an anonymous user.
                history = trans.galaxy_session.current_history
                item = history.get_api_value(
                    value_mapper={'id': trans.security.encode_id})
                item['url'] = url_for('history',
                                      id=trans.security.encode_id(history.id))
                rval.append(item)

        except Exception, e:
            rval = "Error in history API"
            log.error(rval + ": %s" % str(e))
            trans.response.status = 500