本文整理汇总了Python中galaxy.managers.histories.HistoryManager.create方法的典型用法代码示例。如果您正苦于以下问题:Python HistoryManager.create方法的具体用法?Python HistoryManager.create怎么用?Python HistoryManager.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类galaxy.managers.histories.HistoryManager
的用法示例。
在下文中一共展示了HistoryManager.create方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: HistoryAsContainerTestCase
# 需要导入模块: from galaxy.managers.histories import HistoryManager [as 别名]
# 或者: from galaxy.managers.histories.HistoryManager import create [as 别名]
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 ] )
示例2: HDCATestCase
# 需要导入模块: from galaxy.managers.histories import HistoryManager [as 别名]
# 或者: from galaxy.managers.histories.HistoryManager import create [as 别名]
class HDCATestCase( BaseTestCase, CreatesCollectionsMixin ):
def set_up_managers( self ):
super( HDCATestCase, self ).set_up_managers()
self.hdca_manager = hdcas.HDCAManager( self.app )
self.hda_manager = hdas.HDAManager( self.app )
self.history_manager = HistoryManager( self.app )
self.dataset_manager = DatasetManager( self.app )
self.collection_manager = collections.DatasetCollectionManager( self.app )
def _create_history( self, user_data=None, **kwargs ):
user_data = user_data or user2_data
owner = self.user_manager.create( **user_data )
return self.history_manager.create( user=owner, **kwargs )
def _create_hda( self, history, dataset=None, **kwargs ):
if not dataset:
dataset = self.hda_manager.dataset_manager.create()
hda = self.hda_manager.create( history=history, dataset=dataset, **kwargs )
return hda
def _create_list_hdca( self, hdas, history=None, name='test collection', **kwargs ):
if not history:
history = history or self._create_history()
for i, hda in enumerate( hdas ):
if not isinstance( hdas, self.hda_manager.model_class ):
hdas[ i ] = self._create_hda( history, **hda )
hdca = self.collection_manager.create( self.trans, history, name, 'list',
element_identifiers=self.build_element_identifiers( hdas ) )
return hdca
示例3: HDATestCase
# 需要导入模块: from galaxy.managers.histories import HistoryManager [as 别名]
# 或者: from galaxy.managers.histories.HistoryManager import create [as 别名]
class HDATestCase(BaseTestCase):
def set_up_managers(self):
super(HDATestCase, self).set_up_managers()
self.hda_manager = hdas.HDAManager(self.app)
self.history_manager = HistoryManager(self.app)
self.dataset_manager = DatasetManager(self.app)
def _create_vanilla_hda(self, user_data=None):
user_data = user_data or user2_data
owner = self.user_manager.create(**user_data)
history1 = self.history_manager.create(name="history1", user=owner)
dataset1 = self.dataset_manager.create()
return self.hda_manager.create(history=history1, dataset=dataset1)
示例4: HistoryFiltersTestCase
# 需要导入模块: from galaxy.managers.histories import HistoryManager [as 别名]
# 或者: from galaxy.managers.histories.HistoryManager import create [as 别名]
class HistoryFiltersTestCase(BaseTestCase):
def set_up_managers(self):
super(HistoryFiltersTestCase, self).set_up_managers()
self.history_manager = HistoryManager(self.app)
self.filter_parser = HistoryFilters(self.app)
# ---- functional and orm filter splitting and resolution
def test_parse_filters(self):
filters = self.filter_parser.parse_filters([
('name', 'eq', 'wot'),
('deleted', 'eq', 'True'),
('annotation', 'has', 'hrrmm')
])
self.log('both orm and fn filters should be parsed and returned')
self.assertEqual(len(filters), 3)
self.log('values should be parsed')
self.assertIsInstance(filters[1].right, sqlalchemy.sql.elements.True_)
def test_parse_filters_invalid_filters(self):
self.log('should error on non-column attr')
self.assertRaises(exceptions.RequestParameterInvalidException, self.filter_parser.parse_filters, [
('merp', 'eq', 'wot'),
])
self.log('should error on non-whitelisted attr')
self.assertRaises(exceptions.RequestParameterInvalidException, self.filter_parser.parse_filters, [
('user_id', 'eq', 'wot'),
])
self.log('should error on non-whitelisted op')
self.assertRaises(exceptions.RequestParameterInvalidException, self.filter_parser.parse_filters, [
('name', 'lt', 'wot'),
])
self.log('should error on non-listed fn op')
self.assertRaises(exceptions.RequestParameterInvalidException, self.filter_parser.parse_filters, [
('annotation', 'like', 'wot'),
])
self.log('should error on val parsing error')
self.assertRaises(exceptions.RequestParameterInvalidException, self.filter_parser.parse_filters, [
('deleted', 'eq', 'true'),
])
def test_orm_filter_parsing(self):
user2 = self.user_manager.create(**user2_data)
history1 = self.history_manager.create(name='history1', user=user2)
history2 = self.history_manager.create(name='history2', user=user2)
history3 = self.history_manager.create(name='history3', user=user2)
filters = self.filter_parser.parse_filters([
('name', 'like', 'history%'),
])
histories = self.history_manager.list(filters=filters)
# for h in histories:
# print h.name
self.assertEqual(histories, [history1, history2, history3])
filters = self.filter_parser.parse_filters([('name', 'like', '%2'), ])
self.assertEqual(self.history_manager.list(filters=filters), [history2])
filters = self.filter_parser.parse_filters([('name', 'eq', 'history2'), ])
self.assertEqual(self.history_manager.list(filters=filters), [history2])
self.history_manager.update(history1, dict(deleted=True))
filters = self.filter_parser.parse_filters([('deleted', 'eq', 'True'), ])
self.assertEqual(self.history_manager.list(filters=filters), [history1])
filters = self.filter_parser.parse_filters([('deleted', 'eq', 'False'), ])
self.assertEqual(self.history_manager.list(filters=filters), [history2, history3])
self.assertEqual(self.history_manager.list(), [history1, history2, history3])
self.history_manager.update(history3, dict(deleted=True))
self.history_manager.update(history1, dict(importable=True))
self.history_manager.update(history2, dict(importable=True))
filters = self.filter_parser.parse_filters([
('deleted', 'eq', 'True'),
('importable', 'eq', 'True'),
])
self.assertEqual(self.history_manager.list(filters=filters), [history1])
self.assertEqual(self.history_manager.list(), [history1, history2, history3])
def test_fn_filter_parsing(self):
user2 = self.user_manager.create(**user2_data)
history1 = self.history_manager.create(name='history1', user=user2)
history2 = self.history_manager.create(name='history2', user=user2)
history3 = self.history_manager.create(name='history3', user=user2)
filters = self.filter_parser.parse_filters([('annotation', 'has', 'no play'), ])
anno_filter = filters[0]
history3.add_item_annotation(self.trans.sa_session, user2, history3, "All work and no play")
self.trans.sa_session.flush()
self.assertTrue(anno_filter(history3))
self.assertFalse(anno_filter(history2))
self.assertEqual(self.history_manager.list(filters=filters), [history3])
self.log('should allow combinations of orm and fn filters')
self.history_manager.update(history3, dict(importable=True))
self.history_manager.update(history2, dict(importable=True))
history1.add_item_annotation(self.trans.sa_session, user2, history1, "All work and no play")
#.........这里部分代码省略.........
示例5: HistorySerializerTestCase
# 需要导入模块: from galaxy.managers.histories import HistoryManager [as 别名]
# 或者: from galaxy.managers.histories.HistoryManager import create [as 别名]
class HistorySerializerTestCase(BaseTestCase):
def set_up_managers(self):
super(HistorySerializerTestCase, self).set_up_managers()
self.history_manager = HistoryManager(self.app)
self.hda_manager = hdas.HDAManager(self.app)
self.history_serializer = HistorySerializer(self.app)
def test_views(self):
user2 = self.user_manager.create(**user2_data)
history1 = self.history_manager.create(name='history1', user=user2)
self.log('should have a summary view')
summary_view = self.history_serializer.serialize_to_view(history1, view='summary')
self.assertKeys(summary_view, self.history_serializer.views['summary'])
self.log('should have a detailed view')
detailed_view = self.history_serializer.serialize_to_view(history1, view='detailed')
self.assertKeys(detailed_view, self.history_serializer.views['detailed'])
self.log('should have the summary view as default view')
default_view = self.history_serializer.serialize_to_view(history1, default_view='summary')
self.assertKeys(default_view, self.history_serializer.views['summary'])
self.log('should have a serializer for all serializable keys')
for key in self.history_serializer.serializable_keyset:
instantiated_attribute = getattr(history1, key, None)
if not ((key in self.history_serializer.serializers) or
(isinstance(instantiated_attribute, self.TYPES_NEEDING_NO_SERIALIZERS))):
self.fail('no serializer for: %s (%s)' % (key, instantiated_attribute))
else:
self.assertTrue(True, 'all serializable keys have a serializer')
def test_views_and_keys(self):
user2 = self.user_manager.create(**user2_data)
history1 = self.history_manager.create(name='history1', user=user2)
self.log('should be able to use keys with views')
serialized = self.history_serializer.serialize_to_view(history1,
view='summary', keys=['state_ids', 'user_id'])
self.assertKeys(serialized,
self.history_serializer.views['summary'] + ['state_ids', 'user_id'])
self.log('should be able to use keys on their own')
serialized = self.history_serializer.serialize_to_view(history1,
keys=['state_ids', 'user_id'])
self.assertKeys(serialized, ['state_ids', 'user_id'])
def test_sharable(self):
user2 = self.user_manager.create(**user2_data)
history1 = self.history_manager.create(name='history1', user=user2)
self.log('should have a serializer for all SharableModel keys')
sharable_attrs = ['user_id', 'username_and_slug', 'importable', 'published', 'slug']
serialized = self.history_serializer.serialize(history1, sharable_attrs)
self.assertKeys(serialized, sharable_attrs)
self.log('should return user_id for user with whom it\'s been shared if the requester is the owner')
non_owner = self.user_manager.create(**user3_data)
self.history_manager.share_with(history1, non_owner)
serialized = self.history_serializer.serialize(history1, ['users_shared_with'], user=user2)
self.assertKeys(serialized, ['users_shared_with'])
self.assertIsInstance(serialized['users_shared_with'], list)
self.assertEqual(serialized['users_shared_with'][0], self.app.security.encode_id(non_owner.id))
self.log('should not return users_shared_with if the requester is not the owner')
serialized = self.history_serializer.serialize(history1, ['users_shared_with'], user=non_owner)
self.assertFalse(hasattr(serialized, 'users_shared_with'))
def test_purgable(self):
user2 = self.user_manager.create(**user2_data)
history1 = self.history_manager.create(name='history1', user=user2)
self.log('deleted and purged should be returned in their default states')
keys = ['deleted', 'purged']
serialized = self.history_serializer.serialize(history1, keys)
self.assertEqual(serialized['deleted'], False)
self.assertEqual(serialized['purged'], False)
self.log('deleted and purged should return their current state')
self.history_manager.delete(history1)
serialized = self.history_serializer.serialize(history1, keys)
self.assertEqual(serialized['deleted'], True)
self.assertEqual(serialized['purged'], False)
self.history_manager.purge(history1)
serialized = self.history_serializer.serialize(history1, keys)
self.assertEqual(serialized['deleted'], True)
self.assertEqual(serialized['purged'], True)
def test_history_serializers(self):
user2 = self.user_manager.create(**user2_data)
history1 = self.history_manager.create(name='history1', user=user2)
all_keys = list(self.history_serializer.serializable_keyset)
serialized = self.history_serializer.serialize(history1, all_keys, user=user2)
self.log('everything serialized should be of the proper type')
self.assertIsInstance(serialized['size'], int)
self.assertIsInstance(serialized['nice_size'], string_types)
#.........这里部分代码省略.........
示例6: HistoryManagerTestCase
# 需要导入模块: from galaxy.managers.histories import HistoryManager [as 别名]
# 或者: from galaxy.managers.histories.HistoryManager import create [as 别名]
class HistoryManagerTestCase(BaseTestCase):
def set_up_managers(self):
super(HistoryManagerTestCase, self).set_up_managers()
self.history_manager = HistoryManager(self.app)
self.hda_manager = hdas.HDAManager(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 test_base(self):
user2 = self.user_manager.create(**user2_data)
user3 = self.user_manager.create(**user3_data)
self.log("should be able to create a new history")
history1 = self.history_manager.create(name='history1', user=user2)
self.assertIsInstance(history1, model.History)
self.assertEqual(history1.name, 'history1')
self.assertEqual(history1.user, user2)
self.assertEqual(history1, self.trans.sa_session.query(model.History).get(history1.id))
self.assertEqual(history1,
self.trans.sa_session.query(model.History).filter(model.History.name == 'history1').one())
self.assertEqual(history1,
self.trans.sa_session.query(model.History).filter(model.History.user == user2).one())
history2 = self.history_manager.copy(history1, user=user3)
self.log("should be able to query")
histories = self.trans.sa_session.query(model.History).all()
self.assertEqual(self.history_manager.one(filters=(model.History.id == history1.id)), history1)
self.assertEqual(self.history_manager.list(), histories)
self.assertEqual(self.history_manager.by_id(history1.id), history1)
self.assertEqual(self.history_manager.by_ids([history2.id, history1.id]), [history2, history1])
self.log("should be able to limit and offset")
self.assertEqual(self.history_manager.list(limit=1), histories[0:1])
self.assertEqual(self.history_manager.list(offset=1), histories[1:])
self.assertEqual(self.history_manager.list(limit=1, offset=1), histories[1:2])
self.assertEqual(self.history_manager.list(limit=0), [])
self.assertEqual(self.history_manager.list(offset=3), [])
self.log("should be able to order")
history3 = self.history_manager.create(name="history3", user=user2)
name_first_then_time = (model.History.name, sqlalchemy.desc(model.History.create_time))
self.assertEqual(self.history_manager.list(order_by=name_first_then_time),
[history2, history1, history3])
def test_copy(self):
user2 = self.user_manager.create(**user2_data)
user3 = self.user_manager.create(**user3_data)
self.log("should be able to copy a history (and it's hdas)")
history1 = self.history_manager.create(name='history1', user=user2)
tags = [u'tag-one']
annotation = u'history annotation'
self.history_manager.set_tags(history1, tags, user=user2)
self.history_manager.annotate(history1, annotation, user=user2)
hda = self.add_hda_to_history(history1, name='wat')
hda_tags = [u'tag-one', u'tag-two']
hda_annotation = u'annotation'
self.hda_manager.set_tags(hda, hda_tags, user=user2)
self.hda_manager.annotate(hda, hda_annotation, user=user2)
history2 = self.history_manager.copy(history1, user=user3)
self.assertIsInstance(history2, model.History)
self.assertEqual(history2.user, user3)
self.assertEqual(history2, self.trans.sa_session.query(model.History).get(history2.id))
self.assertEqual(history2.name, history1.name)
self.assertNotEqual(history2, history1)
copied_hda = history2.datasets[0]
copied_hda_tags = self.hda_manager.get_tags(copied_hda)
self.assertEqual(sorted(hda_tags), sorted(copied_hda_tags))
copied_hda_annotation = self.hda_manager.annotation(copied_hda)
self.assertEqual(hda_annotation, copied_hda_annotation)
def test_has_user(self):
owner = self.user_manager.create(**user2_data)
non_owner = self.user_manager.create(**user3_data)
item1 = self.history_manager.create(user=owner)
item2 = self.history_manager.create(user=owner)
self.history_manager.create(user=non_owner)
self.log("should be able to list items by user")
user_histories = self.history_manager.by_user(owner)
self.assertEqual(user_histories, [item1, item2])
def test_ownable(self):
owner = self.user_manager.create(**user2_data)
non_owner = self.user_manager.create(**user3_data)
item1 = self.history_manager.create(user=owner)
self.log("should be able to poll whether a given user owns an item")
self.assertTrue(self.history_manager.is_owner(item1, owner))
#.........这里部分代码省略.........
示例7: DatasetCollectionManagerTestCase
# 需要导入模块: from galaxy.managers.histories import HistoryManager [as 别名]
# 或者: from galaxy.managers.histories.HistoryManager import create [as 别名]
class DatasetCollectionManagerTestCase( BaseTestCase ):
def set_up_managers( self ):
super( DatasetCollectionManagerTestCase, self ).set_up_managers()
self.dataset_manager = DatasetManager( self.app )
self.hda_manager = HDAManager( self.app )
self.history_manager = HistoryManager( self.app )
self.collection_manager = DatasetCollectionManager( self.app )
def build_element_identifiers( self, elements ):
identifier_list = []
for element in elements:
src = 'hda'
# if isinstance( element, model.DatasetCollection ):
# src = 'collection'#?
# elif isinstance( element, model.LibraryDatasetDatasetAssociation ):
# src = 'ldda'#?
encoded_id = self.trans.security.encode_id( element.id )
identifier_list.append( dict( src=src, name=element.name, id=encoded_id ) )
return identifier_list
def test_create_simple_list( self ):
owner = self.user_manager.create( **user2_data )
history = self.history_manager.create( name='history1', user=owner )
hda1 = self.hda_manager.create( name='one',
history=history, dataset=self.dataset_manager.create() )
hda2 = self.hda_manager.create( name='two',
history=history, dataset=self.dataset_manager.create() )
hda3 = self.hda_manager.create( name='three',
history=history, dataset=self.dataset_manager.create() )
self.log( "should be able to create a new Collection via ids" )
element_identifiers = self.build_element_identifiers( [ hda1, hda2, hda3 ] )
hdca = self.collection_manager.create( self.trans, history, 'test collection', 'list',
element_identifiers=element_identifiers )
self.assertIsInstance( hdca, model.HistoryDatasetCollectionAssociation )
self.assertEqual( hdca.name, 'test collection' )
self.assertEqual( hdca.hid, 4 )
self.assertFalse( hdca.deleted )
self.assertTrue( hdca.visible )
# print 'hdca dir:'
# for k in dir( hdca ):
# print k, getattr( hdca, k, '(?)' )
self.log( "should contain an underlying, well-formed DatasetCollection" )
self.assertIsInstance( hdca.collection, model.DatasetCollection )
collection = hdca.collection
self.assertEqual( collection.collection_type, 'list' )
self.assertEqual( collection.state, 'ok' )
self.assertEqual( len( collection.dataset_instances ), 3 )
self.assertEqual( len( collection.elements ), 3 )
# print 'hdca.collection dir:'
# for k in dir( hdca.collection ):
# print k, getattr( hdca.collection, k, '(?)' )
# elements = collection.elements
# print 'hdca.collection element dir:'
# for k in dir( elements[0] ):
# print k, getattr( elements[0], k, '(?)' )
self.log( "and that collection should have three well-formed Elements" )
self.assertIsInstance( collection.elements[0], model.DatasetCollectionElement )
self.assertEqual( collection.elements[0].element_identifier, 'one' )
self.assertEqual( collection.elements[0].element_index, 0 )
self.assertEqual( collection.elements[0].element_type, 'hda' )
self.assertEqual( collection.elements[0].element_object, hda1 )
self.assertIsInstance( collection.elements[1], model.DatasetCollectionElement )
self.assertEqual( collection.elements[1].element_identifier, 'two' )
self.assertEqual( collection.elements[1].element_index, 1 )
self.assertEqual( collection.elements[1].element_type, 'hda' )
self.assertEqual( collection.elements[1].element_object, hda2 )
self.assertIsInstance( collection.elements[2], model.DatasetCollectionElement )
self.assertEqual( collection.elements[2].element_identifier, 'three' )
self.assertEqual( collection.elements[2].element_index, 2 )
self.assertEqual( collection.elements[2].element_type, 'hda' )
self.assertEqual( collection.elements[2].element_object, hda3 )
self.log( "should be able to create a new Collection via objects" )
elements = dict( one=hda1, two=hda2, three=hda3 )
hdca2 = self.collection_manager.create( self.trans, history, 'test collection 2', 'list', elements=elements )
self.assertIsInstance( hdca2, model.HistoryDatasetCollectionAssociation )
def test_update_from_dict( self ):
owner = self.user_manager.create( **user2_data )
history = self.history_manager.create( name='history1', user=owner )
hda1 = self.hda_manager.create( name='one',
history=history, dataset=self.dataset_manager.create() )
hda2 = self.hda_manager.create( name='two',
history=history, dataset=self.dataset_manager.create() )
hda3 = self.hda_manager.create( name='three',
history=history, dataset=self.dataset_manager.create() )
#.........这里部分代码省略.........
示例8: HistoryManagerTestCase
# 需要导入模块: from galaxy.managers.histories import HistoryManager [as 别名]
# 或者: from galaxy.managers.histories.HistoryManager import create [as 别名]
class HistoryManagerTestCase( BaseTestCase ):
def set_up_managers( self ):
super( HistoryManagerTestCase, self ).set_up_managers()
self.history_mgr = HistoryManager( self.app )
def test_base( self ):
user2 = self.user_mgr.create( self.trans, **user2_data )
user3 = self.user_mgr.create( self.trans, **user3_data )
self.log( "should be able to create a new history" )
history1 = self.history_mgr.create( self.trans, name='history1', user=user2 )
self.assertIsInstance( history1, model.History )
self.assertEqual( history1.name, 'history1' )
self.assertEqual( history1.user, user2 )
self.assertEqual( history1, self.trans.sa_session.query( model.History ).get( history1.id ) )
self.assertEqual( history1,
self.trans.sa_session.query( model.History ).filter( model.History.name == 'history1' ).one() )
self.assertEqual( history1,
self.trans.sa_session.query( model.History ).filter( model.History.user == user2 ).one() )
self.log( "should be able to copy a history" )
history2 = self.history_mgr.copy( self.trans, history1, user=user3 )
self.assertIsInstance( history2, model.History )
self.assertEqual( history2.user, user3 )
self.assertEqual( history2, self.trans.sa_session.query( model.History ).get( history2.id ) )
self.assertEqual( history2.name, history1.name )
self.assertNotEqual( history2, history1 )
self.log( "should be able to query" )
histories = self.trans.sa_session.query( model.History ).all()
self.assertEqual( self.history_mgr.one( self.trans, filters=( model.History.id == history1.id ) ), history1 )
self.assertEqual( self.history_mgr.list( self.trans ), histories )
self.assertEqual( self.history_mgr.by_id( self.trans, history1.id ), history1 )
self.assertEqual( self.history_mgr.by_ids( self.trans, [ history2.id, history1.id ] ), [ history2, history1 ] )
self.log( "should be able to limit and offset" )
self.assertEqual( self.history_mgr.list( self.trans, limit=1 ), histories[0:1] )
self.assertEqual( self.history_mgr.list( self.trans, offset=1 ), histories[1:] )
self.assertEqual( self.history_mgr.list( self.trans, limit=1, offset=1 ), histories[1:2] )
self.assertEqual( self.history_mgr.list( self.trans, limit=0 ), [] )
self.assertEqual( self.history_mgr.list( self.trans, offset=3 ), [] )
self.log( "should be able to order" )
history3 = self.history_mgr.create( self.trans, name="history3", user=user2 )
name_first_then_time = ( model.History.name, sqlalchemy.desc( model.History.create_time ) )
self.assertEqual( self.history_mgr.list( self.trans, order_by=name_first_then_time ),
[ history2, history1, history3 ] )
def test_has_user( self ):
owner = self.user_mgr.create( self.trans, **user2_data )
non_owner = self.user_mgr.create( self.trans, **user3_data )
item1 = self.history_mgr.create( self.trans, user=owner )
item2 = self.history_mgr.create( self.trans, user=owner )
item3 = self.history_mgr.create( self.trans, user=non_owner )
self.log( "should be able to list items by user" )
user_histories = self.history_mgr.by_user( self.trans, owner )
self.assertEqual( user_histories, [ item1, item2 ] )
def test_ownable( self ):
owner = self.user_mgr.create( self.trans, **user2_data )
non_owner = self.user_mgr.create( self.trans, **user3_data )
item1 = self.history_mgr.create( self.trans, user=owner )
self.log( "should be able to poll whether a given user owns an item" )
self.assertTrue( self.history_mgr.is_owner( self.trans, item1, owner ) )
self.assertFalse( self.history_mgr.is_owner( self.trans, item1, non_owner ) )
self.log( "should raise an error when checking ownership with non-owner" )
self.assertRaises( exceptions.ItemOwnershipException,
self.history_mgr.error_unless_owner, self.trans, item1, non_owner )
self.assertRaises( exceptions.ItemOwnershipException,
self.history_mgr.get_owned, self.trans, item1.id, non_owner )
self.log( "should not raise an error when checking ownership with owner" )
self.assertEqual( self.history_mgr.error_unless_owner( self.trans, item1, owner ), item1 )
self.assertEqual( self.history_mgr.get_owned( self.trans, item1.id, owner ), item1 )
self.log( "should not raise an error when checking ownership with admin" )
self.assertTrue( self.history_mgr.is_owner( self.trans, item1, self.admin_user ) )
self.assertEqual( self.history_mgr.error_unless_owner( self.trans, item1, self.admin_user ), item1 )
self.assertEqual( self.history_mgr.get_owned( self.trans, item1.id, self.admin_user ), item1 )
def test_accessible( self ):
owner = self.user_mgr.create( self.trans, **user2_data )
item1 = self.history_mgr.create( self.trans, user=owner )
non_owner = self.user_mgr.create( self.trans, **user3_data )
self.log( "should be inaccessible by default except to owner" )
self.assertTrue( self.history_mgr.is_accessible( self.trans, item1, owner ) )
self.assertTrue( self.history_mgr.is_accessible( self.trans, item1, self.admin_user ) )
self.assertFalse( self.history_mgr.is_accessible( self.trans, item1, non_owner ) )
self.log( "should raise an error when checking accessibility with non-owner" )
self.assertRaises( exceptions.ItemAccessibilityException,
#.........这里部分代码省略.........
示例9: HistorySerializerTestCase
# 需要导入模块: from galaxy.managers.histories import HistoryManager [as 别名]
# 或者: from galaxy.managers.histories.HistoryManager import create [as 别名]
class HistorySerializerTestCase( BaseTestCase ):
def set_up_managers( self ):
super( HistorySerializerTestCase, self ).set_up_managers()
self.history_mgr = HistoryManager( self.app )
self.hda_mgr = hdas.HDAManager( self.app )
self.history_serializer = HistorySerializer( self.app )
def test_views( self ):
user2 = self.user_mgr.create( self.trans, **user2_data )
history1 = self.history_mgr.create( self.trans, name='history1', user=user2 )
self.log( 'should have a summary view' )
summary_view = self.history_serializer.serialize_to_view( self.trans, history1, view='summary' )
self.assertKeys( summary_view, self.history_serializer.views[ 'summary' ] )
self.log( 'should have a detailed view' )
detailed_view = self.history_serializer.serialize_to_view( self.trans, history1, view='detailed' )
self.assertKeys( detailed_view, self.history_serializer.views[ 'detailed' ] )
self.log( 'should have the summary view as default view' )
default_view = self.history_serializer.serialize_to_view( self.trans, history1, default_view='summary' )
self.assertKeys( summary_view, self.history_serializer.views[ 'summary' ] )
self.log( 'should have a serializer for all serializable keys' )
need_no_serializers = ( basestring, bool, type( None ) )
for key in self.history_serializer.serializable_keyset:
instantiated_attribute = getattr( history1, key, None )
if not ( ( key in self.history_serializer.serializers )
or ( isinstance( instantiated_attribute, need_no_serializers ) ) ):
self.fail( 'no serializer for: %s (%s)' % ( key, instantiated_attribute ) )
else:
self.assertTrue( True, 'all serializable keys have a serializer' )
def test_views_and_keys( self ):
user2 = self.user_mgr.create( self.trans, **user2_data )
history1 = self.history_mgr.create( self.trans, name='history1', user=user2 )
self.log( 'should be able to use keys with views' )
serialized = self.history_serializer.serialize_to_view( self.trans, history1,
view='summary', keys=[ 'state_ids', 'user_id' ] )
self.assertKeys( serialized,
self.history_serializer.views[ 'summary' ] + [ 'state_ids', 'user_id' ] )
self.log( 'should be able to use keys on their own' )
serialized = self.history_serializer.serialize_to_view( self.trans, history1,
keys=[ 'state_ids', 'user_id' ] )
self.assertKeys( serialized, [ 'state_ids', 'user_id' ] )
def test_sharable( self ):
user2 = self.user_mgr.create( self.trans, **user2_data )
history1 = self.history_mgr.create( self.trans, name='history1', user=user2 )
self.log( 'should have a serializer for all SharableModel keys' )
sharable_attrs = [ 'user_id', 'username_and_slug', 'importable', 'published', 'slug' ]
serialized = self.history_serializer.serialize( self.trans, history1, sharable_attrs )
self.assertKeys( serialized, sharable_attrs )
def test_purgable( self ):
user2 = self.user_mgr.create( self.trans, **user2_data )
history1 = self.history_mgr.create( self.trans, name='history1', user=user2 )
self.log( 'deleted and purged should be returned in their default states' )
keys = [ 'deleted', 'purged' ]
serialized = self.history_serializer.serialize( self.trans, history1, keys )
self.assertEqual( serialized[ 'deleted' ], False )
self.assertEqual( serialized[ 'purged' ], False )
self.log( 'deleted and purged should return their current state' )
self.history_mgr.delete( self.trans, history1 )
serialized = self.history_serializer.serialize( self.trans, history1, keys )
self.assertEqual( serialized[ 'deleted' ], True )
self.assertEqual( serialized[ 'purged' ], False )
self.history_mgr.purge( self.trans, history1 )
serialized = self.history_serializer.serialize( self.trans, history1, keys )
self.assertEqual( serialized[ 'deleted' ], True )
self.assertEqual( serialized[ 'purged' ], True )
def test_history_serializers( self ):
user2 = self.user_mgr.create( self.trans, **user2_data )
history1 = self.history_mgr.create( self.trans, name='history1', user=user2 )
serialized = self.history_serializer.serialize( self.trans, history1, [ 'size', 'nice_size' ])
self.assertIsInstance( serialized[ 'size' ], int )
self.assertIsInstance( serialized[ 'nice_size' ], basestring )
def test_contents( self ):
user2 = self.user_mgr.create( self.trans, **user2_data )
history1 = self.history_mgr.create( self.trans, name='history1', user=user2 )
self.log( 'a history with no contents should be properly reflected in empty, etc.' )
keys = [ 'empty', 'count', 'state_ids', 'state_details', 'state', 'hdas' ]
serialized = self.history_serializer.serialize( self.trans, history1, keys )
self.assertEqual( serialized[ 'state' ], 'new' )
self.assertEqual( serialized[ 'empty' ], True )
self.assertEqual( serialized[ 'count' ], 0 )
self.assertEqual( sum( serialized[ 'state_details' ].values() ), 0 )
self.assertEqual( serialized[ 'state_ids' ][ 'ok' ], [] )
self.assertIsInstance( serialized[ 'hdas' ], list )
#.........这里部分代码省略.........
示例10: TagManagerTestCase
# 需要导入模块: from galaxy.managers.histories import HistoryManager [as 别名]
# 或者: from galaxy.managers.histories.HistoryManager import create [as 别名]
class TagManagerTestCase(BaseTestCase):
def set_up_managers(self):
super(TagManagerTestCase, self).set_up_managers()
self.hda_manager = hdas.HDAManager(self.app)
self.history_manager = HistoryManager(self.app)
self.dataset_manager = DatasetManager(self.app)
self.tag_manager = GalaxyTagManager(self.trans.sa_session)
self.user = self.user_manager.create(**user2_data)
def _create_vanilla_hda(self, user=None):
owner = user or self.user
history1 = self.history_manager.create(name='history1', user=owner)
dataset1 = self.dataset_manager.create()
return self.hda_manager.create(history=history1, dataset=dataset1)
def _check_tag_list(self, tags, expected_tags):
self.assertEqual(len(tags), len(expected_tags))
actual_tags = []
for tag in tags:
if tag.user_value:
tag = "%s:%s" % (tag.user_tname, tag.user_value)
else:
tag = tag.user_tname
actual_tags.append(tag)
expected = [unicodify(e) for e in expected_tags]
assert sorted(expected) == sorted(actual_tags), "%s vs %s" % (expected, actual_tags)
def test_apply_item_tags(self):
tag_strings = [
'tag1',
'tag1:value1',
'tag1:value1:value11',
'\x00tag1',
'tag1:\x00value1',
'tag1,tag2'
]
expected_tags = [
['tag1'],
['tag1:value1'],
['tag1:value1:value11'],
['tag1'],
['tag1:value1'],
['tag1', 'tag2']
]
for tag_string, expected_tag in zip(tag_strings, expected_tags):
hda = self._create_vanilla_hda()
self.tag_manager.apply_item_tags(user=self.user, item=hda, tags_str=tag_string)
self._check_tag_list(hda.tags, expected_tag)
def test_set_tag_from_list(self):
hda = self._create_vanilla_hda()
tags = ['tag1', 'tag2']
self.tag_manager.set_tags_from_list(self.user, hda, tags)
self._check_tag_list(hda.tags, tags)
# Setting tags should erase previous tags
self.tag_manager.set_tags_from_list(self.user, hda, ['tag1'])
self._check_tag_list(hda.tags, expected_tags=['tag1'])
def test_add_tag_from_list(self):
hda = self._create_vanilla_hda()
tags = ['tag1', 'tag2']
self.tag_manager.add_tags_from_list(self.user, hda, tags)
self._check_tag_list(tags=hda.tags, expected_tags=tags)
# Adding tags should keep previous tags
self.tag_manager.add_tags_from_list(self.user, hda, ['tag3'])
self._check_tag_list(hda.tags, expected_tags=['tag1', 'tag2', 'tag3'])
def test_remove_tag_from_list(self):
hda = self._create_vanilla_hda()
tags = ['tag1', 'tag2']
self.tag_manager.set_tags_from_list(self.user, hda, tags)
self._check_tag_list(hda.tags, tags)
self.tag_manager.remove_tags_from_list(self.user, hda, ['tag1'])
self._check_tag_list(hda.tags, ['tag2'])
def test_delete_item_tags(self):
hda = self._create_vanilla_hda()
tags = ['tag1']
self.tag_manager.set_tags_from_list(self.user, hda, tags)
self.tag_manager.delete_item_tags(user=self.user, item=hda)
self.assertEqual(hda.tags, [])
def test_item_has_tag(self):
hda = self._create_vanilla_hda()
tags = ['tag1']
self.tag_manager.set_tags_from_list(self.user, hda, tags)
self.assertTrue(self.tag_manager.item_has_tag(self.user, item=hda, tag='tag1'))
# ItemTagAssociation
self.assertTrue(self.tag_manager.item_has_tag(self.user, item=hda, tag=hda.tags[0]))
# Tag
self.assertTrue(self.tag_manager.item_has_tag(self.user, item=hda, tag=hda.tags[0].tag))
self.assertFalse(self.tag_manager.item_has_tag(self.user, item=hda, tag='tag2'))
示例11: HDAManagerTestCase
# 需要导入模块: from galaxy.managers.histories import HistoryManager [as 别名]
# 或者: from galaxy.managers.histories.HistoryManager import create [as 别名]
class HDAManagerTestCase( BaseTestCase ):
def set_up_managers( self ):
super( HDAManagerTestCase, self ).set_up_managers()
self.history_mgr = HistoryManager( self.app )
self.dataset_mgr = DatasetManager( self.app )
self.hda_mgr = HDAManager( self.app )
def test_base( self ):
hda_model = model.HistoryDatasetAssociation
owner = self.user_mgr.create( self.trans, **user2_data )
history1 = self.history_mgr.create( self.trans, name='history1', user=owner )
hda1 = self.hda_mgr.create( self.trans, history=history1, hid=1 )
hda2 = self.hda_mgr.create( self.trans, history=history1, hid=2 )
hda3 = self.hda_mgr.create( self.trans, history=history1, hid=3 )
self.log( "should be able to query" )
hdas = self.trans.sa_session.query( hda_model ).all()
self.assertEqual( self.hda_mgr.list( self.trans ), hdas )
self.assertEqual( self.hda_mgr.one( self.trans, filters=( hda_model.id == hda1.id ) ), hda1 )
self.assertEqual( self.hda_mgr.by_id( self.trans, hda1.id ), hda1 )
self.assertEqual( self.hda_mgr.by_ids( self.trans, [ hda2.id, hda1.id ] ), [ hda2, hda1 ] )
self.log( "should be able to limit and offset" )
self.assertEqual( self.hda_mgr.list( self.trans, limit=1 ), hdas[0:1] )
self.assertEqual( self.hda_mgr.list( self.trans, offset=1 ), hdas[1:] )
self.assertEqual( self.hda_mgr.list( self.trans, limit=1, offset=1 ), hdas[1:2] )
self.assertEqual( self.hda_mgr.list( self.trans, limit=0 ), [] )
self.assertEqual( self.hda_mgr.list( self.trans, offset=3 ), [] )
self.log( "should be able to order" )
self.assertEqual( self.hda_mgr.list( self.trans, order_by=sqlalchemy.desc( hda_model.create_time ) ),
[ hda3, hda2, hda1 ] )
def test_create( self ):
owner = self.user_mgr.create( self.trans, **user2_data )
non_owner = self.user_mgr.create( self.trans, **user3_data )
history1 = self.history_mgr.create( self.trans, name='history1', user=owner )
dataset1 = self.dataset_mgr.create( self.trans )
self.log( "should be able to create a new HDA with a specified history and dataset" )
hda1 = self.hda_mgr.create( self.trans, history=history1, dataset=dataset1 )
self.assertIsInstance( hda1, model.HistoryDatasetAssociation )
self.assertEqual( hda1, self.trans.sa_session.query( model.HistoryDatasetAssociation ).get( hda1.id ) )
self.assertEqual( hda1.history, history1 )
self.assertEqual( hda1.dataset, dataset1 )
self.assertEqual( hda1.hid, 1 )
self.log( "should be able to create a new HDA with only a specified history and no dataset" )
hda2 = self.hda_mgr.create( self.trans, history=history1 )
self.assertIsInstance( hda2, model.HistoryDatasetAssociation )
self.assertIsInstance( hda2.dataset, model.Dataset )
self.assertEqual( hda2.history, history1 )
self.assertEqual( hda2.hid, 2 )
self.log( "should be able to create a new HDA with no history and no dataset" )
hda3 = self.hda_mgr.create( self.trans, hid=None )
self.assertIsInstance( hda3, model.HistoryDatasetAssociation )
self.assertIsInstance( hda3.dataset, model.Dataset, msg="dataset will be auto created" )
self.assertIsNone( hda3.history, msg="history will be None" )
self.assertEqual( hda3.hid, None, msg="should allow setting hid to None (or any other value)" )
def test_copy_from_hda( self ):
owner = self.user_mgr.create( self.trans, **user2_data )
history1 = self.history_mgr.create( self.trans, name='history1', user=owner )
dataset1 = self.dataset_mgr.create( self.trans )
hda1 = self.hda_mgr.create( self.trans, history=history1, dataset=dataset1 )
self.log( "should be able to copy an HDA" )
hda2 = self.hda_mgr.copy( self.trans, hda1, history=history1 )
self.assertIsInstance( hda2, model.HistoryDatasetAssociation )
self.assertEqual( hda2, self.trans.sa_session.query( model.HistoryDatasetAssociation ).get( hda2.id ) )
self.assertEqual( hda2.name, hda1.name )
self.assertEqual( hda2.history, hda1.history )
self.assertEqual( hda2.dataset, hda1.dataset )
self.assertNotEqual( hda2, hda1 )
#def test_copy_from_ldda( self ):
# owner = self.user_mgr.create( self.trans, **user2_data )
# history1 = self.history_mgr.create( self.trans, name='history1', user=owner )
#
# self.log( "should be able to copy an HDA" )
# hda2 = self.hda_mgr.copy_ldda( self.trans, history1, hda1 )
def test_delete( self ):
owner = self.user_mgr.create( self.trans, **user2_data )
history1 = self.history_mgr.create( self.trans, name='history1', user=owner )
dataset1 = self.dataset_mgr.create( self.trans )
item1 = self.hda_mgr.create( self.trans, history=history1, dataset=dataset1 )
self.log( "should be able to delete and undelete an hda" )
self.assertFalse( item1.deleted )
self.assertEqual( self.hda_mgr.delete( self.trans, item1 ), item1 )
self.assertTrue( item1.deleted )
self.assertEqual( self.hda_mgr.undelete( self.trans, item1 ), item1 )
self.assertFalse( item1.deleted )
def test_purge_allowed( self ):
#.........这里部分代码省略.........
示例12: DatasetCollectionManagerTestCase
# 需要导入模块: from galaxy.managers.histories import HistoryManager [as 别名]
# 或者: from galaxy.managers.histories.HistoryManager import create [as 别名]
class DatasetCollectionManagerTestCase(BaseTestCase, CreatesCollectionsMixin):
def set_up_managers(self):
super(DatasetCollectionManagerTestCase, self).set_up_managers()
self.dataset_manager = DatasetManager(self.app)
self.hda_manager = HDAManager(self.app)
self.history_manager = HistoryManager(self.app)
self.collection_manager = DatasetCollectionManager(self.app)
def test_create_simple_list(self):
owner = self.user_manager.create(**user2_data)
history = self.history_manager.create(name='history1', user=owner)
hda1 = self.hda_manager.create(name='one',
history=history, dataset=self.dataset_manager.create())
hda2 = self.hda_manager.create(name='two',
history=history, dataset=self.dataset_manager.create())
hda3 = self.hda_manager.create(name='three',
history=history, dataset=self.dataset_manager.create())
self.log("should be able to create a new Collection via ids")
element_identifiers = self.build_element_identifiers([hda1, hda2, hda3])
hdca = self.collection_manager.create(self.trans, history, 'test collection', 'list',
element_identifiers=element_identifiers)
self.assertIsInstance(hdca, model.HistoryDatasetCollectionAssociation)
self.assertEqual(hdca.name, 'test collection')
self.assertEqual(hdca.hid, 4)
self.assertFalse(hdca.deleted)
self.assertTrue(hdca.visible)
self.log("should contain an underlying, well-formed DatasetCollection")
self.assertIsInstance(hdca.collection, model.DatasetCollection)
collection = hdca.collection
self.assertEqual(collection.collection_type, 'list')
self.assertEqual(collection.state, 'ok')
self.assertEqual(len(collection.dataset_instances), 3)
self.assertEqual(len(collection.elements), 3)
self.log("and that collection should have three well-formed Elements")
self.assertIsInstance(collection.elements[0], model.DatasetCollectionElement)
self.assertEqual(collection.elements[0].element_identifier, 'one')
self.assertEqual(collection.elements[0].element_index, 0)
self.assertEqual(collection.elements[0].element_type, 'hda')
self.assertEqual(collection.elements[0].element_object, hda1)
self.assertIsInstance(collection.elements[1], model.DatasetCollectionElement)
self.assertEqual(collection.elements[1].element_identifier, 'two')
self.assertEqual(collection.elements[1].element_index, 1)
self.assertEqual(collection.elements[1].element_type, 'hda')
self.assertEqual(collection.elements[1].element_object, hda2)
self.assertIsInstance(collection.elements[2], model.DatasetCollectionElement)
self.assertEqual(collection.elements[2].element_identifier, 'three')
self.assertEqual(collection.elements[2].element_index, 2)
self.assertEqual(collection.elements[2].element_type, 'hda')
self.assertEqual(collection.elements[2].element_object, hda3)
self.log("should be able to create a new Collection via objects")
elements = dict(one=hda1, two=hda2, three=hda3)
hdca2 = self.collection_manager.create(self.trans, history, 'test collection 2', 'list', elements=elements)
self.assertIsInstance(hdca2, model.HistoryDatasetCollectionAssociation)
def test_update_from_dict(self):
owner = self.user_manager.create(**user2_data)
history = self.history_manager.create(name='history1', user=owner)
hda1 = self.hda_manager.create(name='one',
history=history, dataset=self.dataset_manager.create())
hda2 = self.hda_manager.create(name='two',
history=history, dataset=self.dataset_manager.create())
hda3 = self.hda_manager.create(name='three',
history=history, dataset=self.dataset_manager.create())
elements = dict(one=hda1, two=hda2, three=hda3)
hdca = self.collection_manager.create(self.trans, history, 'test collection', 'list', elements=elements)
self.log("should be set from a dictionary")
self.collection_manager._set_from_dict(self.trans, hdca, {
'deleted': True,
'visible': False,
'name': 'New Name',
# TODO: doesn't work
# 'tags' : [ 'one', 'two', 'three' ]
# 'annotations' : [?]
})
self.assertEqual(hdca.name, 'New Name')
self.assertTrue(hdca.deleted)
self.assertFalse(hdca.visible)