diff --git a/lib/galaxy/visualization/registry.py b/lib/galaxy/visualization/registry.py index 053862a4137..e758ba26924 100644 --- a/lib/galaxy/visualization/registry.py +++ b/lib/galaxy/visualization/registry.py @@ -13,6 +13,7 @@ import galaxy.model from galaxy.web import url_for from galaxy.web.base import pluginframework +from galaxy.web.base.interactive_environments import InteractiveEnviornmentRequest from galaxy.managers import api_keys import logging @@ -105,6 +106,7 @@ class VisualizationsRegistry( pluginframework.PageServingPluginManager ): 'sweepster', 'phyloviz' ] + IE_REQUEST_FACTORY = InteractiveEnviornmentRequest def __str__( self ): return self.__class__.__name__ @@ -349,12 +351,18 @@ class VisualizationsRegistry( pluginframework.PageServingPluginManager ): # as an external visualization plugin is deprecated in favor of core interactive # environment plugin. if 'get_api_key' not in kwargs: - def get_api_key(): return api_keys.ApiKeyManager( trans.app ).get_or_create_api_key( trans.user ) - kwargs[ 'get_api_key' ] = get_api_key + if 'plugin_path' not in kwargs: + kwargs[ 'plugin_path' ] = os.path.abspath( plugin.path ) + + plugin_config = plugin.get( 'config', {} ) + if plugin_config.get( 'plugin_type', 'visualization' ) == "interactive_environment": + request = self.IE_REQUEST_FACTORY( trans, plugin ) + kwargs[ "ie_request" ] = request + return super( VisualizationsRegistry, self ).fill_template( trans, plugin, template_filename, **kwargs ) diff --git a/lib/galaxy/web/base/pluginframework.py b/lib/galaxy/web/base/pluginframework.py index c3c9ccbd29d..95102dc50d6 100644 --- a/lib/galaxy/web/base/pluginframework.py +++ b/lib/galaxy/web/base/pluginframework.py @@ -20,7 +20,6 @@ import mako.lookup from galaxy import util from galaxy.util import odict from galaxy.util import bunch -from .interactive_environments import InteractiveEnviornmentRequest import logging @@ -589,14 +588,6 @@ class PageServingPluginManager( PluginManager ): ``plugin.template_path`` :returns: rendered template """ - if 'plugin_path' not in kwargs: - kwargs[ 'plugin_path' ] = os.path.abspath( plugin.path ) - - plugin_config = plugin.get( 'config', {} ) - if plugin_config.get( 'plugin_type', 'visualization' ) == "interactive_environment": - request = InteractiveEnviornmentRequest(trans, plugin) - kwargs[ "ie_request" ] = request - # defined here to be overridden return trans.fill_template( template_filename, template_lookup=plugin.template_lookup, **kwargs ) diff --git a/test/unit/unittest_utils/galaxy_mock.py b/test/unit/unittest_utils/galaxy_mock.py index ecd2c19d4a8..b06f65f61c4 100644 --- a/test/unit/unittest_utils/galaxy_mock.py +++ b/test/unit/unittest_utils/galaxy_mock.py @@ -1,19 +1,10 @@ """ Mock infrastructure for testing ModelManagers. """ -import sys import os import tempfile import shutil - -__GALAXY_ROOT__ = os.getcwd() + '/../../../' -sys.path.insert( 1, __GALAXY_ROOT__ + 'lib' ) - -from galaxy import eggs -eggs.require( 'SQLAlchemy >= 0.4' ) -import sqlalchemy - from galaxy.web import security from galaxy import objectstore from galaxy.model import mapping @@ -22,6 +13,7 @@ from galaxy.util.bunch import Bunch from galaxy.managers import tags from galaxy import quota + # ============================================================================= class OpenObject( object ): pass diff --git a/test/unit/visualizations/test_VisualizationsRegistry.py b/test/unit/visualizations/test_VisualizationsRegistry.py index 2ec09af3d5d..b36470c798e 100644 --- a/test/unit/visualizations/test_VisualizationsRegistry.py +++ b/test/unit/visualizations/test_VisualizationsRegistry.py @@ -3,11 +3,13 @@ import os import imp import unittest +import re test_utils = imp.load_source( 'test_utils', os.path.join( os.path.dirname( __file__), '../unittest_utils/utility.py' ) ) import galaxy_mock +from galaxy import model from galaxy.visualization.registry import VisualizationsRegistry # ----------------------------------------------------------------------------- globals @@ -33,6 +35,28 @@ config1 = """\ """ +ipython_config = """\ + + + + + + HistoryDatasetAssociation + tabular.Tabular + data.Text + dataset_id + + + + dataset_id + + + +""" +ipython_template = """\ +${ ie_request }-${ get_api_key() } +""" + # ----------------------------------------------------------------------------- class VisualizationsRegistry_TestCase( unittest.TestCase ): @@ -46,10 +70,8 @@ class VisualizationsRegistry_TestCase( unittest.TestCase ): template_cache_dir=template_cache_dir ) expected_plugins_path = os.path.join( glx_dir, vis_reg_path ) - print 'expected_plugins_path:', expected_plugins_path self.assertEqual( plugin_mgr.base_url, 'visualizations' ) self.assertItemsEqual( plugin_mgr.directories, [ expected_plugins_path ] ) - print plugin_mgr.plugins scatterplot = plugin_mgr.plugins[ 'scatterplot' ] self.assertEqual( scatterplot.name, 'scatterplot' ) @@ -138,6 +160,60 @@ class VisualizationsRegistry_TestCase( unittest.TestCase ): mock_app_dir.remove() + def test_interactive_environ_plugin_load( self ): + """ + """ + mock_app_dir = galaxy_mock.MockDir({ + 'plugins' : { + 'ipython' : { + 'config' : { + 'ipython.xml' : ipython_config + }, + 'templates' : { + 'ipython.mako': ipython_template + } + }, + } + }) + mock_app = galaxy_mock.MockApp( root=mock_app_dir.root_path ) + plugin_mgr = VisualizationsRegistry( mock_app, + directories_setting='plugins', + template_cache_dir=mock_app_dir.root_path ) + # use a mock request factory - this will be written into the filled template to show it was used + plugin_mgr.IE_REQUEST_FACTORY = lambda t, p: 'mock_ie' + + expected_plugins_path = os.path.join( mock_app_dir.root_path, 'plugins' ) + expected_plugin_names = [ 'ipython' ] + + self.assertEqual( plugin_mgr.base_url, 'visualizations' ) + self.assertItemsEqual( plugin_mgr.directories, [ expected_plugins_path ] ) + self.assertItemsEqual( plugin_mgr.plugins.keys(), expected_plugin_names ) + + ipython_ie = plugin_mgr.plugins[ 'ipython' ] + config = ipython_ie.get( 'config' ) + + self.assertEqual( ipython_ie.name, 'ipython' ) + self.assertEqual( config.get( 'plugin_type' ), 'interactive_environment' ) + + # get_api_key needs a user, fill_template a trans + user = model.User( email="blah@bler.blah", password="dockerDockerDOCKER" ) + trans = galaxy_mock.MockTrans( user=user ) + + # should return the (new) api key for the above user (see the template above) + response = plugin_mgr.fill_template( trans, ipython_ie, 'ipython.mako' ) + response.strip() + self.assertIsInstance( response, basestring ) + self.assertTrue( '-' in response ) + ie_request, api_key = response.split( '-' ) + + self.assertEqual( ie_request, 'mock_ie' ) + + match = re.match( r'[a-f0-9]{32}', api_key ) + self.assertIsNotNone( match ) + self.assertEqual( match.span(), ( 0, 32 ) ) + + mock_app_dir.remove() + # TODO: config parser tests (in separate file)