mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Interactive environments: move InteractiveEnviornmentRequest to registry.py (since we branch on intenv code there anyway) from pluginframework.py; Add tests for intenv within visreg
This commit is contained in:
@@ -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 )
|
||||
|
||||
|
||||
|
||||
@@ -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 )
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 = """\
|
||||
</visualization>
|
||||
"""
|
||||
|
||||
ipython_config = """\
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE interactive_environment SYSTEM "../../interactive_environments.dtd">
|
||||
<interactive_environment name="IPython">
|
||||
<data_sources>
|
||||
<data_source>
|
||||
<model_class>HistoryDatasetAssociation</model_class>
|
||||
<test type="isinstance" test_attr="datatype" result_type="datatype">tabular.Tabular</test>
|
||||
<test type="isinstance" test_attr="datatype" result_type="datatype">data.Text</test>
|
||||
<to_param param_attr="id">dataset_id</to_param>
|
||||
</data_source>
|
||||
</data_sources>
|
||||
<params>
|
||||
<param type="dataset" var_name_in_template="hda" required="true">dataset_id</param>
|
||||
</params>
|
||||
<template>ipython.mako</template>
|
||||
</interactive_environment>
|
||||
"""
|
||||
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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user