Skip to content

Commit

Permalink
History contents: remove HistoryAsContainer mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
carlfeberhard committed Jul 27, 2015
1 parent 7aace6d commit c9a5ce7
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 92 deletions.
22 changes: 0 additions & 22 deletions lib/galaxy/managers/containers.py
Expand Up @@ -9,10 +9,6 @@

import operator

import pkg_resources
pkg_resources.require( "SQLAlchemy" )
from sqlalchemy import literal

from galaxy import model
import galaxy.exceptions
import galaxy.util
Expand Down Expand Up @@ -75,24 +71,6 @@ def _content_manager( self, content ):
raise galaxy.exceptions.NotImplemented( 'Abstract class' )


class HistoryAsContainerManagerMixin( ContainerManagerMixin ):

contained_class = model.HistoryDatasetAssociation
subcontainer_class = model.HistoryDatasetCollectionAssociation
order_contents_on = operator.attrgetter( 'hid' )

def _filter_to_contained( self, container, content_class ):
return content_class.history == container

def _content_manager( self, content ):
# type sniffing is inevitable
if isinstance( content, model.HistoryDatasetAssociation ):
return self.hda_manager
elif isinstance( content, model.HistoryDatasetCollectionAssociation ):
return self.hdca_manager
raise TypeError( 'Unknown contents class: ' + str( content ) )


class LibraryFolderAsContainerManagerMixin( ContainerManagerMixin ):
# can contain two types of subcontainer: LibraryFolder, LibraryDatasetCollectionAssociation
# has as the top level container: Library
Expand Down
4 changes: 1 addition & 3 deletions lib/galaxy/managers/histories.py
Expand Up @@ -17,9 +17,7 @@
log = logging.getLogger( __name__ )


class HistoryManager( sharable.SharableModelManager,
deletable.PurgableManagerMixin,
containers.HistoryAsContainerManagerMixin ):
class HistoryManager( sharable.SharableModelManager, deletable.PurgableManagerMixin ):

model_class = model.History
foreign_key_name = 'history'
Expand Down
6 changes: 2 additions & 4 deletions lib/galaxy/managers/history_contents.py
Expand Up @@ -10,8 +10,6 @@
from sqlalchemy import literal

from galaxy import model
# import galaxy.exceptions
import galaxy.util

from galaxy.managers import containers
from galaxy.managers import hdas
Expand Down Expand Up @@ -61,7 +59,7 @@ def contents( self, container, filters=None, limit=None, offset=None, order_by=N
contents_query = contents_query.limit( limit )
if offset is not None:
contents_query = contents_query.offset( offset )
# if limit is not None:
# if order_by is not None:
# contents_query = contents_query.order_by( order_by )
contents_results = contents_query.all()

Expand All @@ -79,7 +77,7 @@ def contents( self, container, filters=None, limit=None, offset=None, order_by=N
raise TypeError( 'Unknown contents type:', result_type )
print id_map

# query the id_lists for each
# query the contained classes using the id_lists for each
for subclass in subclasses:
id_list = id_map[ subclass.__name__ ]
id_map[ subclass.__name__ ] = self._by_ids( subclass, id_list )
Expand Down
63 changes: 0 additions & 63 deletions test/unit/managers/test_HistoryManager.py
Expand Up @@ -728,69 +728,6 @@ def test_list( self ):
self.assertEqual( found, deleted_and_annotated )


# =============================================================================
class HistoryAsContainerTestCase( BaseTestCase, CreatesCollectionsMixin ):

def set_up_managers( self ):
super( HistoryAsContainerTestCase, self ).set_up_managers()
self.history_manager = HistoryManager( self.app )
self.hda_manager = hdas.HDAManager( self.app )
self.collection_manager = collections.DatasetCollectionManager( self.app )

def add_hda_to_history( self, history, **kwargs ):
dataset = self.hda_manager.dataset_manager.create()
hda = self.hda_manager.create( history=history, dataset=dataset, **kwargs )
return hda

def add_list_collection_to_history( self, history, hdas, name='test collection', **kwargs ):
hdca = self.collection_manager.create( self.trans, history, name, 'list',
element_identifiers=self.build_element_identifiers( hdas ) )
return hdca

def test_contents( self ):
user2 = self.user_manager.create( **user2_data )
history = self.history_manager.create( name='history', user=user2 )

self.log( "calling contents on an empty history should return an empty list" )
self.assertEqual( [], list( self.history_manager.contents( history ) ) )

self.log( "calling contents on an history with hdas should return those in order of their hids" )
hdas = [ self.add_hda_to_history( history, name=( 'hda-' + str( x ) ) ) for x in xrange( 3 ) ]
random.shuffle( hdas )
ordered_hda_contents = list( self.history_manager.contents( history ) )
self.assertEqual( map( lambda hda: hda.hid, ordered_hda_contents ), [ 1, 2, 3 ] )

self.log( "calling contents on an history with both hdas and collections should return both" )
hdca = self.add_list_collection_to_history( history, hdas )
all_contents = list( self.history_manager.contents( history ) )
self.assertEqual( all_contents, list( ordered_hda_contents ) + [ hdca ] )

def test_contained( self ):
user2 = self.user_manager.create( **user2_data )
history = self.history_manager.create( name='history', user=user2 )

self.log( "calling contained on an empty history should return an empty list" )
self.assertEqual( [], list( self.history_manager.contained( history ) ) )

self.log( "calling contained on an history with both hdas and collections should return only hdas" )
hdas = [ self.add_hda_to_history( history, name=( 'hda-' + str( x ) ) ) for x in xrange( 3 ) ]
self.add_list_collection_to_history( history, hdas )
self.assertEqual( list( self.history_manager.contained( history ) ), hdas )

def test_subcontainers( self ):
user2 = self.user_manager.create( **user2_data )
history = self.history_manager.create( name='history', user=user2 )

self.log( "calling subcontainers on an empty history should return an empty list" )
self.assertEqual( [], list( self.history_manager.subcontainers( history ) ) )

self.log( "calling subcontainers on an history with both hdas and collections should return only collections" )
hdas = [ self.add_hda_to_history( history, name=( 'hda-' + str( x ) ) ) for x in xrange( 3 ) ]
hdca = self.add_list_collection_to_history( history, hdas )
subcontainers = list( self.history_manager.subcontainers( history ) )
self.assertEqual( subcontainers, [ hdca ] )


# =============================================================================
if __name__ == '__main__':
# or more generally, nosetests test_resourcemanagers.py -s -v
Expand Down

0 comments on commit c9a5ce7

Please sign in to comment.