1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/8d74daa932a0/ Changeset: 8d74daa932a0 User: carlfeberhard Date: 2015-02-02 19:13:54+00:00 Summary: Managers: re-implement url_for as overridable service, add tests for history contents Affected #: 4 files diff -r d1b39530bd1ffa10c482e7f7c49b2b41c5a847a1 -r 8d74daa932a06f7bbd3e357f8216c8f58ae55965 lib/galaxy/managers/base.py --- a/lib/galaxy/managers/base.py +++ b/lib/galaxy/managers/base.py @@ -503,7 +503,7 @@ item_dict = MySerializer.serialize( trans, my_item, keys_to_serialize ) """ #: 'service' to use for getting urls - use class var to allow overriding when testing - #url_service = + url_for = staticmethod( routes.url_for ) def __init__( self, app ): """ @@ -544,7 +544,7 @@ If `include_keys_from` is a proper view name, extend `key_list` by the list in that view. """ - key_list += self.views.get( include_keys_from, [] ) + key_list = list( set( key_list + self.views.get( include_keys_from, [] ) ) ) self.views[ view_name ] = key_list self.serializable_keyset.update( key_list ) return key_list @@ -590,10 +590,6 @@ id = getattr( item, key ) return self.app.security.encode_id( id ) if id is not None else None - @staticmethod - def url_for( *args, **kwargs ): - return routes.url_for( *args, **kwargs ) - # serializing to a view where a view is a predefied list of keys to serialize def serialize_to_view( self, trans, item, view=None, keys=None, default_view=None ): """ diff -r d1b39530bd1ffa10c482e7f7c49b2b41c5a847a1 -r 8d74daa932a06f7bbd3e357f8216c8f58ae55965 test/unit/managers/mock.py --- a/test/unit/managers/mock.py +++ b/test/unit/managers/mock.py @@ -21,6 +21,14 @@ class OpenObject( object ): pass +class MockApp( object ): + def __init__( self, **kwargs ): + self.config = MockAppConfig( **kwargs ) + self.security = self.config.security + self.object_store = objectstore.build_object_store_from_config( self.config ) + self.model = mapping.init( "/tmp", "sqlite:///:memory:", create_tables=True, object_store=self.object_store ) + self.security_agent = self.model.security_agent + self.visualizations_registry = MockVisualizationsRegistry() class MockAppConfig( Bunch ): def __init__( self, **kwargs ): @@ -40,15 +48,6 @@ self.expose_dataset_path = True self.allow_user_dataset_purge = True self.enable_old_display_applications = True - - -class MockApp( object ): - def __init__( self, **kwargs ): - self.config = MockAppConfig( **kwargs ) - self.security = self.config.security - self.object_store = objectstore.build_object_store_from_config( self.config ) - self.model = mapping.init( "/tmp", "sqlite:///:memory:", create_tables=True, object_store=self.object_store ) - self.security_agent = self.model.security_agent class MockWebapp( object ): def __init__( self, **kwargs ): @@ -92,3 +91,7 @@ template = template_lookup.get_template( filename ) template.output_encoding = 'utf-8' return template.render( **kwargs ) + +class MockVisualizationsRegistry( object ): + def get_visualizations( self, trans, target ): + return [] diff -r d1b39530bd1ffa10c482e7f7c49b2b41c5a847a1 -r 8d74daa932a06f7bbd3e357f8216c8f58ae55965 test/unit/managers/test_HistoryManager.py --- a/test/unit/managers/test_HistoryManager.py +++ b/test/unit/managers/test_HistoryManager.py @@ -312,15 +312,12 @@ # ============================================================================= # web.url_for doesn't work well in the framework testable_url_for = lambda *a, **k: '(fake url): %s, %s' % ( a, k ) -HistorySerializer.url_for = testable_url_for -hdas.HDASerializer.url_for = testable_url_for +HistorySerializer.url_for = staticmethod( testable_url_for ) +hdas.HDASerializer.url_for = staticmethod( testable_url_for ) class HistorySerializerTestCase( BaseTestCase ): - def assertHasKeys( self, obj, key_list ): - self.assertEqual( sorted( obj.keys() ), sorted( key_list ) ) - def set_up_managers( self ): super( HistorySerializerTestCase, self ).set_up_managers() self.history_mgr = HistoryManager( self.app ) @@ -333,15 +330,15 @@ self.log( 'should have a summary view' ) summary_view = self.history_serializer.serialize_to_view( self.trans, history1, view='summary' ) - self.assertHasKeys( summary_view, self.history_serializer.views[ '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.assertHasKeys( detailed_view, self.history_serializer.views[ '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.assertHasKeys( summary_view, self.history_serializer.views[ '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 ) ) @@ -360,13 +357,13 @@ 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.assertHasKeys( serialized, + 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.assertHasKeys( serialized, [ 'state_ids', 'user_id' ] ) + self.assertKeys( serialized, [ 'state_ids', 'user_id' ] ) def test_sharable( self ): user2 = self.user_mgr.create( self.trans, **user2_data ) @@ -375,7 +372,7 @@ 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.assertHasKeys( serialized, sharable_attrs ) + self.assertKeys( serialized, sharable_attrs ) def test_purgable( self ): user2 = self.user_mgr.create( self.trans, **user2_data ) @@ -398,8 +395,6 @@ self.assertEqual( serialized[ 'deleted' ], True ) self.assertEqual( serialized[ 'purged' ], True ) - #pprint.pprint( self.history_serializer.serialize( self.trans, history1, [ 'contents' ] ) ) - 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 ) @@ -435,6 +430,8 @@ self.assertIsInstance( serialized[ 'hdas' ], list ) self.assertIsInstance( serialized[ 'hdas' ][0], basestring ) + serialized = self.history_serializer.serialize( self.trans, history1, [ 'contents' ] ) + self.assertHasKeys( serialized[ 'contents' ][0], [ 'id', 'name', 'peek', 'create_time' ]) # ============================================================================= class HistoryDeserializerTestCase( BaseTestCase ): diff -r d1b39530bd1ffa10c482e7f7c49b2b41c5a847a1 -r 8d74daa932a06f7bbd3e357f8216c8f58ae55965 test/unit/managers/test_ModelManager.py --- a/test/unit/managers/test_ModelManager.py +++ b/test/unit/managers/test_ModelManager.py @@ -75,6 +75,17 @@ def log( self, *args, **kwargs ): print( *args, **kwargs ) + # ---- additional test types + def assertKeys( self, obj, key_list ): + self.assertEqual( sorted( obj.keys() ), sorted( key_list ) ) + + def assertHasKeys( self, obj, key_list ): + for key in key_list: + if key not in obj: + self.fail( 'Missing key: ' + key ) + else: + self.assertTrue( True, 'keys found in object' ) + # ============================================================================= if __name__ == '__main__': 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.