Пример #1
0
    def test_multiple_sources( self ):
        # clean the following contents, write them to tmpfiles, open them,
        #   and pass as a list to the provider
        contents = [
            """
                One
                Two
                Three
                Four
                Five
            """,
            """
                Six
                Seven
                Eight
                Nine
                Ten
            """,
            """
                Eleven
                Twelve! (<-- http://youtu.be/JZshZp-cxKg)
            """
        ]
        contents = [ utility.clean_multiline_string( c ) for c in contents ]
        source_list = [ open( self.tmpfiles.create_tmpfile( c ) ) for c in contents ]

        provider = self.provider_class( source_list )
        log.debug( 'provider: %s', provider )
        data = list( provider )
        log.debug( 'data: %s', str( data ) )
        self.assertEqual( ''.join( data ), ''.join( contents) )
Пример #2
0
    def test_multiple_sources(self):
        # clean the following contents, write them to tmpfiles, open them,
        #   and pass as a list to the provider
        contents = [
            """
                One
                Two
                Three
                Four
                Five
            """, """
                Six
                Seven
                Eight
                Nine
                Ten
            """, """
                Eleven
                Twelve! (<-- http://youtu.be/JZshZp-cxKg)
            """
        ]
        contents = [utility.clean_multiline_string(c) for c in contents]
        source_list = [open(self.tmpfiles.create_tmpfile(c)) for c in contents]

        provider = self.provider_class(source_list)
        log.debug('provider: %s', provider)
        data = list(provider)
        log.debug('data: %s', str(data))
        self.assertEqual(''.join(data), ''.join(contents))
Пример #3
0
 def test_stringio( self ):
     """should work with StringIO
     """
     contents = utility.clean_multiline_string( """
         One
         Two
         Three
     """ )
     source = StringIO( contents )
     provider = self.provider_class( source )
     data = list( provider )
     log.debug( 'data: %s', str( data ) )
     # provider should call close on file
     self.assertEqual( data, self.parses_default_content_as() )
     self.assertTrue( source.closed )
Пример #4
0
 def test_stringio(self):
     """should work with StringIO
     """
     contents = utility.clean_multiline_string("""
         One
         Two
         Three
     """)
     source = StringIO(contents)
     provider = self.provider_class(source)
     data = list(provider)
     log.debug('data: %s', str(data))
     # provider should call close on file
     self.assertEqual(data, self.parses_default_content_as())
     self.assertTrue(source.closed)
Пример #5
0
    def test_script_entry(self):
        """"""
        script_entry_config = utility.clean_multiline_string("""\
        <?xml version="1.0" encoding="UTF-8"?>
        <visualization name="js-test">
            <data_sources>
                <data_source>
                    <model_class>HistoryDatasetAssociation</model_class>
                </data_source>
            </data_sources>
            <entry_point entry_point_type="script" data-main="one" src="bler"></entry_point>
        </visualization>
        """)

        mock_app_dir = galaxy_mock.MockDir({
            'plugins': {
                'jstest': {
                    'config': {
                        'jstest.xml': script_entry_config
                    },
                    'static': {}
                },
            }
        })
        mock_app = galaxy_mock.MockApp(root=mock_app_dir.root_path)
        plugin_mgr = VisualizationsRegistry(
            mock_app,
            directories_setting='plugins',
            template_cache_dir=template_cache_dir)
        script_entry = plugin_mgr.plugins['jstest']

        self.assertIsInstance(script_entry, plugin.ScriptVisualizationPlugin)
        self.assertEqual(script_entry.name, 'jstest')
        self.assertTrue(script_entry.serves_static)
        self.assertTrue(script_entry.serves_templates)
        self.assertEqual(script_entry.static_path,
                         os.path.join(script_entry.path, 'static'))

        trans = galaxy_mock.MockTrans()
        script_entry._set_up_template_plugin(mock_app_dir.root_path,
                                             [addtional_templates_dir])
        response = script_entry._render({}, trans=trans, embedded=True)
        # print response
        self.assertTrue('src="bler"' in response)
        self.assertTrue('type="text/javascript"' in response)
        self.assertTrue('data-main="one"' in response)
        mock_app_dir.remove()
Пример #6
0
    def test_script_entry(self):
        """"""
        script_entry_config = utility.clean_multiline_string("""\
        <?xml version="1.0" encoding="UTF-8"?>
        <visualization name="js-test">
            <data_sources>
                <data_source>
                    <model_class>HistoryDatasetAssociation</model_class>
                </data_source>
            </data_sources>
            <entry_point entry_point_type="script" data-main="one" src="bler"></entry_point>
        </visualization>
        """)

        mock_app_dir = galaxy_mock.MockDir({
            'plugins': {
                'jstest': {
                    'config': {
                        'jstest.xml': script_entry_config
                    },
                    'static': {}
                },
            }
        })
        mock_app = galaxy_mock.MockApp(root=mock_app_dir.root_path)
        plugin_mgr = VisualizationsRegistry(mock_app,
            directories_setting='plugins',
            template_cache_dir=template_cache_dir)
        script_entry = plugin_mgr.plugins['jstest']

        self.assertIsInstance(script_entry, plugin.ScriptVisualizationPlugin)
        self.assertEqual(script_entry.name, 'jstest')
        self.assertTrue(script_entry.serves_static)
        self.assertTrue(script_entry.serves_templates)
        self.assertEqual(script_entry.static_path, os.path.join(script_entry.path, 'static'))

        trans = galaxy_mock.MockTrans()
        script_entry._set_up_template_plugin(mock_app_dir.root_path, [addtional_templates_dir])
        response = script_entry._render({}, trans=trans, embedded=True)
        # print response
        self.assertTrue('src="bler"' in response)
        self.assertTrue('type="text/javascript"' in response)
        self.assertTrue('data-main="one"' in response)
        mock_app_dir.remove()
Пример #7
0
    def test_multiple_compound_sources(self):
        # clean the following contents, write them to tmpfiles, open them,
        #   and pass as a list to the provider
        contents = [
            """
                One
                Two
                Three
                Four
                Five
            """, """
                Six
                Seven
                Eight
                Nine
                Ten
            """, """
                Eleven
                Twelve! (<-- http://youtu.be/JZshZp-cxKg)
            """
        ]
        contents = [utility.clean_multiline_string(c) for c in contents]
        source_list = [open(self.tmpfiles.create_tmpfile(c)) for c in contents]

        def no_Fs(string):
            return None if string.startswith('F') else string

        def no_youtube(string):
            return None if ('youtu.be' in string) else string

        source_list = [
            base.LimitedOffsetDataProvider(source_list[0],
                                           filter_fn=no_Fs,
                                           limit=2,
                                           offset=1),
            base.LimitedOffsetDataProvider(source_list[1], limit=1, offset=3),
            base.FilteredDataProvider(source_list[2], filter_fn=no_youtube),
        ]
        provider = self.provider_class(source_list)
        log.debug('provider: %s', provider)
        data = list(provider)
        log.debug('data: %s', str(data))
        self.assertEqual(''.join(data), 'Two\nThree\nNine\nEleven\n')
Пример #8
0
    def test_multiple_compound_sources( self ):
        # clean the following contents, write them to tmpfiles, open them,
        #   and pass as a list to the provider
        contents = [
            """
                One
                Two
                Three
                Four
                Five
            """,
            """
                Six
                Seven
                Eight
                Nine
                Ten
            """,
            """
                Eleven
                Twelve! (<-- http://youtu.be/JZshZp-cxKg)
            """
        ]
        contents = [ utility.clean_multiline_string( c ) for c in contents ]
        source_list = [ open( self.tmpfiles.create_tmpfile( c ) ) for c in contents ]

        def no_Fs( string ):
            return None if string.startswith( 'F' ) else string

        def no_youtube( string ):
            return None if ( 'youtu.be' in string ) else string

        source_list = [
            base.LimitedOffsetDataProvider( source_list[0], filter_fn=no_Fs, limit=2, offset=1 ),
            base.LimitedOffsetDataProvider( source_list[1], limit=1, offset=3 ),
            base.FilteredDataProvider( source_list[2], filter_fn=no_youtube ),
        ]
        provider = self.provider_class( source_list )
        log.debug( 'provider: %s', provider )
        data = list( provider )
        log.debug( 'data: %s', str( data ) )
        self.assertEqual( ''.join( data ), 'Two\nThree\nNine\nEleven\n' )
Пример #9
0
    def test_render(self):
        """
        """
        # use the python in a template to test for variables that should be there
        # TODO: gotta be a better way
        testing_template = utility.clean_multiline_string("""\
        <%
            found_all = True
            should_have = [
                title, visualization_name, visualization_display_name,
                visualization_id, saved_visualization,
                query, config,
                embedded,
                vars
            ]
            for var in should_have:
                try:
                    var = str( var )
                except NameError as name_err:
                    found_all = False
                    break
        %>
        ${ found_all }
        """)

        mock_app_dir = galaxy_mock.MockDir({
            'cache': {},
            'template.mako': testing_template
        })
        mock_app = galaxy_mock.MockApp(root=mock_app_dir.root_path)
        plugin = self.plugin_class(mock_app, '', 'myvis',
                                   {"name": "Vlad News Bears"})

        # somewhat easier to set this up by hand
        plugin.config['entry_point'] = {'file': 'template.mako'}
        plugin.template_path = mock_app_dir.root_path
        plugin.template_lookup = plugin._build_template_lookup(
            mock_app_dir.root_path)

        response = plugin.render(trans=galaxy_mock.MockTrans(app=mock_app))
        self.assertIsInstance(response, string_types)
        self.assertEqual(response.strip(), "True")
Пример #10
0
    def test_render(self):
        """
        """
        # use the python in a template to test for variables that should be there
        # TODO: gotta be a better way
        testing_template = utility.clean_multiline_string("""\
        <%
            found_all = True
            should_have = [
                title, visualization_name, visualization_display_name,
                visualization_id, saved_visualization,
                query, config,
                embedded,
                vars
            ]
            for var in should_have:
                try:
                    var = str( var )
                except NameError as name_err:
                    found_all = False
                    break
        %>
        ${ found_all }
        """)

        mock_app_dir = galaxy_mock.MockDir({
            'cache': {},
            'template.mako': testing_template
        })
        mock_app = galaxy_mock.MockApp(root=mock_app_dir.root_path)
        plugin = self.plugin_class(mock_app, '', 'myvis', {
            "name": "Vlad News Bears"
        })

        # somewhat easier to set this up by hand
        plugin.config['entry_point'] = {'file': 'template.mako'}
        plugin.template_path = mock_app_dir.root_path
        plugin.template_lookup = plugin._build_template_lookup(mock_app_dir.root_path)

        response = plugin.render(trans=galaxy_mock.MockTrans(app=mock_app))
        self.assertIsInstance(response, string_types)
        self.assertEqual(response.strip(), "True")
Пример #11
0
 def format_tmpfile_contents( self, contents=None ):
     contents = contents or self.default_file_contents
     contents = utility.clean_multiline_string( contents )
     log.debug( 'file contents:\n%s', contents )
     return contents
Пример #12
0
 def contents_and_tmpfile( self, contents=None ):
     # TODO: hmmmm...
     contents = contents or self.default_file_contents
     contents = utility.clean_multiline_string( contents )
     return ( contents, self.tmpfiles.create_tmpfile( contents ) )
Пример #13
0
    def test_interactive_environ_plugin_load(self):
        """
        """
        ipython_config = utility.clean_multiline_string("""\
        <?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>
        """)

        mock_app_dir = {
            'plugins': {
                'ipython': {
                    'config': {
                        'ipython.xml': ipython_config
                    },
                    'templates': {}
                },
            },
        }

        # going to use a fake template here to simplify testing
        ipython_template = "${ ie_request }-${ get_api_key() }"
        mock_app_dir['plugins']['ipython']['templates'][
            'ipython.mako'] = ipython_template
        # so that we don't create a cached version of that fake template in the real mako caches
        #   we'll set up a cache in the temp dir
        mock_app_dir['caches'] = {}
        # and make sure the vis reg uses that
        mock_app_dir = galaxy_mock.MockDir(mock_app_dir)
        mock_app = galaxy_mock.MockApp(root=mock_app_dir.root_path)
        plugin_mgr = VisualizationsRegistry(mock_app,
                                            directories_setting='plugins',
                                            template_cache_dir=os.path.join(
                                                mock_app_dir.root_path,
                                                'caches'))

        # ...then start testing
        expected_plugins_path = os.path.join(mock_app_dir.root_path, 'plugins')
        expected_plugin_names = ['ipython']

        self.assertEqual(plugin_mgr.base_url, 'visualizations')
        self.assertEqual(plugin_mgr.directories, [expected_plugins_path])
        self.assertEqual(sorted(plugin_mgr.plugins.keys()),
                         expected_plugin_names)

        ipython = plugin_mgr.plugins['ipython']
        config = ipython.config

        self.assertEqual(ipython.name, 'ipython')
        self.assertEqual(config.get('plugin_type'), 'interactive_environment')

        # get_api_key needs a user, fill_template a trans
        user = model.User(email="*****@*****.**",
                          password="******")
        trans = galaxy_mock.MockTrans(user=user)
        # use a mock request factory - this will be written into the filled template to show it was used
        ipython.INTENV_REQUEST_FACTORY = lambda t, p: 'mock'

        # should return the (new) api key for the above user (see the template above)
        response = ipython._render({}, trans=trans)
        response.strip()
        self.assertIsInstance(response, string_types)
        self.assertTrue('-' in response)
        ie_request, api_key = response.split('-')

        self.assertEqual(ie_request, 'mock')

        match = re.match(r'[a-f0-9]{32}', api_key)
        self.assertIsNotNone(match)
        self.assertEqual(match.span(), (0, 32))

        mock_app_dir.remove()
Пример #14
0
    def test_interactive_environ_plugin_load(self):
        """
        """
        jupyter_config = utility.clean_multiline_string("""\
        <?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE interactive_environment SYSTEM "../../interactive_environments.dtd">
        <interactive_environment name="Jupyter">
            <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>jupyter.mako</template>
        </interactive_environment>
        """)

        mock_app_dir = {
            'plugins': {
                'jupyter': {
                    'config': {
                        'jupyter.xml': jupyter_config
                    },
                    'templates': {}
                },
            },
        }

        # going to use a fake template here to simplify testing
        jupyter_template = "${ ie_request }-${ get_api_key() }"
        mock_app_dir['plugins']['jupyter']['templates']['jupyter.mako'] = jupyter_template
        # so that we don't create a cached version of that fake template in the real mako caches
        #   we'll set up a cache in the temp dir
        mock_app_dir['caches'] = {}
        # and make sure the vis reg uses that
        mock_app_dir = galaxy_mock.MockDir(mock_app_dir)
        mock_app = galaxy_mock.MockApp(root=mock_app_dir.root_path)
        plugin_mgr = VisualizationsRegistry(mock_app,
            directories_setting='plugins',
            template_cache_dir=os.path.join(mock_app_dir.root_path, 'caches'))

        # ...then start testing
        expected_plugins_path = os.path.join(mock_app_dir.root_path, 'plugins')
        expected_plugin_names = ['jupyter']

        self.assertEqual(plugin_mgr.base_url, 'visualizations')
        self.assertEqual(plugin_mgr.directories, [expected_plugins_path])
        self.assertEqual(sorted(plugin_mgr.plugins.keys()), expected_plugin_names)

        jupyter = plugin_mgr.plugins['jupyter']
        config = jupyter.config

        self.assertEqual(jupyter.name, 'jupyter')
        self.assertEqual(config.get('plugin_type'), 'interactive_environment')

        # get_api_key needs a user, fill_template a trans
        user = model.User(email="*****@*****.**", password="******")
        trans = galaxy_mock.MockTrans(user=user)
        # use a mock request factory - this will be written into the filled template to show it was used
        jupyter.INTENV_REQUEST_FACTORY = lambda t, p: 'mock'

        # should return the (new) api key for the above user (see the template above)
        response = jupyter._render({}, trans=trans)
        response.strip()
        self.assertIsInstance(response, string_types)
        self.assertTrue('-' in response)
        ie_request, api_key = response.split('-')

        self.assertEqual(ie_request, 'mock')

        match = re.match(r'[a-f0-9]{32}', api_key)
        self.assertIsNotNone(match)
        self.assertEqual(match.span(), (0, 32))

        mock_app_dir.remove()
Пример #15
0
 def format_tmpfile_contents(self, contents=None):
     contents = contents or self.default_file_contents
     contents = utility.clean_multiline_string(contents)
     log.debug('file contents:\n%s', contents)
     return contents
Пример #16
0
 def contents_and_tmpfile(self, contents=None):
     # TODO: hmmmm...
     contents = contents or self.default_file_contents
     contents = utility.clean_multiline_string(contents)
     return (contents, self.tmpfiles.create_tmpfile(contents))