本文整理汇总了Python中galaxy.managers.histories.HistoryManager.error_unless_owner方法的典型用法代码示例。如果您正苦于以下问题:Python HistoryManager.error_unless_owner方法的具体用法?Python HistoryManager.error_unless_owner怎么用?Python HistoryManager.error_unless_owner使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类galaxy.managers.histories.HistoryManager
的用法示例。
在下文中一共展示了HistoryManager.error_unless_owner方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: HistoryManagerTestCase
# 需要导入模块: from galaxy.managers.histories import HistoryManager [as 别名]
# 或者: from galaxy.managers.histories.HistoryManager import error_unless_owner [as 别名]
#.........这里部分代码省略.........
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))
self.assertFalse(self.history_manager.is_owner(item1, non_owner))
self.log("should raise an error when checking ownership with non-owner")
self.assertRaises(exceptions.ItemOwnershipException,
self.history_manager.error_unless_owner, item1, non_owner)
self.assertRaises(exceptions.ItemOwnershipException,
self.history_manager.get_owned, item1.id, non_owner)
self.log("should not raise an error when checking ownership with owner")
self.assertEqual(self.history_manager.error_unless_owner(item1, owner), item1)
self.assertEqual(self.history_manager.get_owned(item1.id, owner), item1)
self.log("should not raise an error when checking ownership with admin")
self.assertTrue(self.history_manager.is_owner(item1, self.admin_user))
self.assertEqual(self.history_manager.error_unless_owner(item1, self.admin_user), item1)
self.assertEqual(self.history_manager.get_owned(item1.id, self.admin_user), item1)
def test_accessible(self):
owner = self.user_manager.create(**user2_data)
item1 = self.history_manager.create(user=owner)
non_owner = self.user_manager.create(**user3_data)
self.log("should be inaccessible by default except to owner")
self.assertTrue(self.history_manager.is_accessible(item1, owner))
self.assertTrue(self.history_manager.is_accessible(item1, self.admin_user))
self.assertFalse(self.history_manager.is_accessible(item1, non_owner))
self.log("should raise an error when checking accessibility with non-owner")
self.assertRaises(exceptions.ItemAccessibilityException,
self.history_manager.error_unless_accessible, item1, non_owner)
self.assertRaises(exceptions.ItemAccessibilityException,
self.history_manager.get_accessible, item1.id, non_owner)
self.log("should not raise an error when checking ownership with owner")
self.assertEqual(self.history_manager.error_unless_accessible(item1, owner), item1)
self.assertEqual(self.history_manager.get_accessible(item1.id, owner), item1)
示例2: HistoryManagerTestCase
# 需要导入模块: from galaxy.managers.histories import HistoryManager [as 别名]
# 或者: from galaxy.managers.histories.HistoryManager import error_unless_owner [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,
#.........这里部分代码省略.........