diff --git a/lib/galaxy/web/base/pluginframework.py b/lib/galaxy/web/base/pluginframework.py index 3a82aad659b..c3c9ccbd29d 100644 --- a/lib/galaxy/web/base/pluginframework.py +++ b/lib/galaxy/web/base/pluginframework.py @@ -15,7 +15,7 @@ import imp import pkg_resources pkg_resources.require( 'MarkupSafe' ) pkg_resources.require( 'Mako' ) -import mako +import mako.lookup from galaxy import util from galaxy.util import odict @@ -590,12 +590,12 @@ class PageServingPluginManager( PluginManager ): :returns: rendered template """ if 'plugin_path' not in kwargs: - kwargs[ 'plugin_path'] = os.path.abspath( plugin.path ) + kwargs[ 'plugin_path' ] = os.path.abspath( plugin.path ) - plugin_type = plugin.config["plugin_type"] - if plugin_type == "interactive_environment": + plugin_config = plugin.get( 'config', {} ) + if plugin_config.get( 'plugin_type', 'visualization' ) == "interactive_environment": request = InteractiveEnviornmentRequest(trans, plugin) - kwargs["ie_request"] = request + 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/datatypes/__init__.py b/test/unit/datatypes/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/unit/datatypes/dataproviders/__init__.py b/test/unit/datatypes/dataproviders/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/unit/datatypes/dataproviders/test_base_dataproviders.py b/test/unit/datatypes/dataproviders/test_base_dataproviders.py index 647b5ccb244..b1a949a81fd 100644 --- a/test/unit/datatypes/dataproviders/test_base_dataproviders.py +++ b/test/unit/datatypes/dataproviders/test_base_dataproviders.py @@ -2,24 +2,24 @@ Unit tests for base DataProviders. .. seealso:: galaxy.datatypes.dataproviders.base """ -# currently because of dataproviders.dataset importing galaxy.model this doesn't work -#TODO: fix imports there after dist and retry - -#TODO: fix off by ones in FilteredDataProvider counters import os.path import imp import unittest import StringIO +import logging +log = logging.getLogger( __name__ ) + +test_utils = imp.load_source( 'test_utils', + os.path.join( os.path.dirname( __file__), '../../unittest_utils/utility.py' ) ) import tempfilecache -utility = imp.load_source( 'utility', os.path.join( os.path.dirname( __file__), '../../util/utility.py' ) ) -log = utility.set_up_filelogger( __name__ + '.log' ) -utility.add_galaxy_lib_to_path( 'test/unit/datatypes/dataproviders' ) - from galaxy.datatypes.dataproviders import base, exceptions -from galaxy import eggs + +# TODO: fix imports there after dist and retry +# TODO: fix off by ones in FilteredDataProvider counters +# currently because of dataproviders.dataset importing galaxy.model this doesn't work class BaseTestCase( unittest.TestCase ): @@ -52,7 +52,7 @@ class BaseTestCase( unittest.TestCase ): def format_tmpfile_contents( self, contents=None ): contents = contents or self.default_file_contents - contents = utility.clean_multiline_string( contents ) + contents = test_utils.clean_multiline_string( contents ) log.debug( 'file contents:\n%s', contents ) return contents @@ -70,7 +70,7 @@ class Test_BaseDataProvider( BaseTestCase ): if not filename: contents = self.format_tmpfile_contents( contents ) filename = self.tmpfiles.create_tmpfile( contents ) - #TODO: if filename, contents == None + # TODO: if filename, contents == None if not source: source = open( filename ) provider = self.provider_class( source, *provider_args, **provider_kwargs ) @@ -113,10 +113,12 @@ class Test_BaseDataProvider( BaseTestCase ): """ source = ( str( x ) for x in xrange( 1, 10 ) ) provider = self.provider_class( source ) + # should throw error def call_method( provider, method_name, *args ): method = getattr( provider, method_name ) return method( *args ) + self.assertRaises( NotImplementedError, call_method, provider, 'truncate', 20 ) self.assertRaises( NotImplementedError, call_method, provider, 'write', 'bler' ) self.assertRaises( NotImplementedError, call_method, provider, 'writelines', [ 'one', 'two' ] ) @@ -133,7 +135,7 @@ class Test_BaseDataProvider( BaseTestCase ): def test_stringio( self ): """should work with StringIO """ - contents = utility.clean_multiline_string( """ + contents = test_utils.clean_multiline_string( """ One Two Three @@ -234,31 +236,31 @@ class Test_LimitedOffsetDataProvider( Test_FilteredDataProvider ): self.assertEqual( data, [] ) self.assertCounters( provider, 0, 0, 0 ) - def test_limit_zero( self ): + def test_limit_none( self ): """when limit is None, should return all """ ( contents, provider, data ) = self.contents_provider_and_data( limit=None ) self.assertEqual( data, self.parses_default_content_as() ) self.assertCounters( provider, 3, 3, 3 ) - #TODO: somehow re-use tmpfile here + # TODO: somehow re-use tmpfile here def test_limit_with_offset( self ): def limit_offset_combo( limit, offset, data_should_be, read, valid, returned ): ( contents, provider, data ) = self.contents_provider_and_data( limit=limit, offset=offset ) self.assertEqual( data, data_should_be ) - #self.assertCounters( provider, read, valid, returned ) + # self.assertCounters( provider, read, valid, returned ) result_data = self.parses_default_content_as() test_data = [ ( 0, 0, [], 0, 0, 0 ), - ( 1, 0, self.parses_default_content_as()[:1], 1, 1, 1 ), - ( 2, 0, self.parses_default_content_as()[:2], 2, 2, 2 ), - ( 3, 0, self.parses_default_content_as()[:3], 3, 3, 3 ), - ( 1, 1, self.parses_default_content_as()[1:2], 1, 1, 1 ), - ( 2, 1, self.parses_default_content_as()[1:3], 2, 2, 2 ), - ( 3, 1, self.parses_default_content_as()[1:3], 2, 2, 2 ), - ( 1, 2, self.parses_default_content_as()[2:3], 1, 1, 1 ), - ( 2, 2, self.parses_default_content_as()[2:3], 1, 1, 1 ), - ( 3, 2, self.parses_default_content_as()[2:3], 1, 1, 1 ), + ( 1, 0, result_data[:1], 1, 1, 1 ), + ( 2, 0, result_data[:2], 2, 2, 2 ), + ( 3, 0, result_data[:3], 3, 3, 3 ), + ( 1, 1, result_data[1:2], 1, 1, 1 ), + ( 2, 1, result_data[1:3], 2, 2, 2 ), + ( 3, 1, result_data[1:3], 2, 2, 2 ), + ( 1, 2, result_data[2:3], 1, 1, 1 ), + ( 2, 2, result_data[2:3], 1, 1, 1 ), + ( 3, 2, result_data[2:3], 1, 1, 1 ), ] for test in test_data: log.debug( 'limit_offset_combo: %s', ', '.join([ str( e ) for e in test ]) ) @@ -273,7 +275,7 @@ class Test_LimitedOffsetDataProvider( Test_FilteredDataProvider ): ( contents, provider, data ) = self.contents_provider_and_data( limit=limit, offset=offset, filter_fn=only_ts ) self.assertEqual( data, data_should_be ) - #self.assertCounters( provider, read, valid, returned ) + # self.assertCounters( provider, read, valid, returned ) result_data = [ c for c in self.parses_default_content_as() if c.lower().startswith( 't' ) ] test_data = [ ( 0, 0, [], 0, 0, 0 ), @@ -293,9 +295,9 @@ class Test_MultiSourceDataProvider( BaseTestCase ): provider_class = base.MultiSourceDataProvider def contents_and_tmpfile( self, contents=None ): - #TODO: hmmmm... + # TODO: hmmmm... contents = contents or self.default_file_contents - contents = utility.clean_multiline_string( contents ) + contents = test_utils.clean_multiline_string( contents ) return ( contents, self.tmpfiles.create_tmpfile( contents ) ) def test_multiple_sources( self ): @@ -321,7 +323,7 @@ class Test_MultiSourceDataProvider( BaseTestCase ): Twelve! (<-- http://youtu.be/JZshZp-cxKg) """ ] - contents = [ utility.clean_multiline_string( c ) for c in contents ] + contents = [ test_utils.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 ) @@ -353,13 +355,15 @@ class Test_MultiSourceDataProvider( BaseTestCase ): Twelve! (<-- http://youtu.be/JZshZp-cxKg) """ ] - contents = [ utility.clean_multiline_string( c ) for c in contents ] + contents = [ test_utils.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 ), diff --git a/test/unit/datatypes/dataproviders/test_line_dataproviders.py b/test/unit/datatypes/dataproviders/test_line_dataproviders.py index c5a7863db8b..d060cc68c79 100644 --- a/test/unit/datatypes/dataproviders/test_line_dataproviders.py +++ b/test/unit/datatypes/dataproviders/test_line_dataproviders.py @@ -2,31 +2,22 @@ Unit tests for base DataProviders. .. seealso:: galaxy.datatypes.dataproviders.base """ -# currently because of dataproviders.dataset importing galaxy.model this doesn't work -#TODO: fix imports there after dist and retry - -#TODO: fix off by ones in FilteredDataProvider counters import imp import os import unittest -import StringIO -import tempfilecache +import logging +log = logging.getLogger( __name__ ) + +test_utils = imp.load_source( 'test_utils', + os.path.join( os.path.dirname( __file__), '../../unittest_utils/utility.py' ) ) + import test_base_dataproviders - -utility = imp.load_source( 'utility', os.path.join( os.path.dirname( __file__ ), '../../util/utility.py' ) ) -log = utility.set_up_filelogger( __name__ + '.log' ) -utility.add_galaxy_lib_to_path( 'test/unit/datatypes/dataproviders' ) - -from galaxy import eggs from galaxy.datatypes.dataproviders import line -_TODO = """ -TestCase hierarchy is a bit of mess here. -""" - +# TODO: TestCase hierarchy is a bit of mess here. class Test_FilteredLineDataProvider( test_base_dataproviders.Test_FilteredDataProvider ): provider_class = line.FilteredLineDataProvider default_file_contents = """ @@ -63,19 +54,19 @@ class Test_FilteredLineDataProvider( test_base_dataproviders.Test_FilteredDataPr def limit_offset_combo( limit, offset, data_should_be, read, valid, returned ): ( contents, provider, data ) = self.contents_provider_and_data( limit=limit, offset=offset ) self.assertEqual( data, data_should_be ) - #self.assertCounters( provider, read, valid, returned ) + # self.assertCounters( provider, read, valid, returned ) result_data = self.parses_default_content_as() test_data = [ ( 0, 0, [], 0, 0, 0 ), - ( 1, 0, self.parses_default_content_as()[:1], 1, 1, 1 ), - ( 2, 0, self.parses_default_content_as()[:2], 2, 2, 2 ), - ( 3, 0, self.parses_default_content_as()[:3], 3, 3, 3 ), - ( 1, 1, self.parses_default_content_as()[1:2], 1, 1, 1 ), - ( 2, 1, self.parses_default_content_as()[1:3], 2, 2, 2 ), - ( 3, 1, self.parses_default_content_as()[1:3], 2, 2, 2 ), - ( 1, 2, self.parses_default_content_as()[2:3], 1, 1, 1 ), - ( 2, 2, self.parses_default_content_as()[2:3], 1, 1, 1 ), - ( 3, 2, self.parses_default_content_as()[2:3], 1, 1, 1 ), + ( 1, 0, result_data[:1], 1, 1, 1 ), + ( 2, 0, result_data[:2], 2, 2, 2 ), + ( 3, 0, result_data[:3], 3, 3, 3 ), + ( 1, 1, result_data[1:2], 1, 1, 1 ), + ( 2, 1, result_data[1:3], 2, 2, 2 ), + ( 3, 1, result_data[1:3], 2, 2, 2 ), + ( 1, 2, result_data[2:3], 1, 1, 1 ), + ( 2, 2, result_data[2:3], 1, 1, 1 ), + ( 3, 2, result_data[2:3], 1, 1, 1 ), ] for test in test_data: log.debug( 'limit_offset_combo: %s', ', '.join([ str( e ) for e in test ]) ) @@ -149,7 +140,7 @@ class Test_RegexLineDataProvider( Test_FilteredLineDataProvider ): """ ( contents, provider, data ) = self.contents_provider_and_data( regex_list=[ r'^T' ], limit=1 ) self.assertEqual( data, [ 'Two' ] ) - #TODO: once again, valid data, returned data is off + # TODO: once again, valid data, returned data is off self.assertCounters( provider, 6, 1, 1 ) ( contents, provider, data ) = self.contents_provider_and_data( regex_list=[ r'^T' ], limit=1, offset=1 ) @@ -167,14 +158,19 @@ class Test_BlockDataProvider( test_base_dataproviders.Test_FilteredDataProvider EFGH Three """ - + def parses_default_content_as( self ): return [ ['One'], ['ABCD'], ['Two'], ['ABCD'], ['EFGH'], ['Three'] ] - #TODO: well, this is ham-handed... - def test_stringio( self ): pass - def test_iterators( self ): pass - def test_readlines( self ): pass + # TODO: well, this is ham-handed... + def test_stringio( self ): + pass + + def test_iterators( self ): + pass + + def test_readlines( self ): + pass def test_file( self ): """should work with files @@ -223,14 +219,16 @@ class Test_BlockDataProvider( test_base_dataproviders.Test_FilteredDataProvider def is_not_indented( line ): strip_diff = len( line ) - len( line.lstrip() ) return ( strip_diff == 0 ) - #def empty_block( block ): + # def empty_block( block ): # if len( block ) <= 1: # return None # return block + def no_tw( block ): if block[0].startswith( 'Tw' ): return None return block + ( contents, provider, data ) = self.contents_provider_and_data( strip_lines=False, strip_newlines=True, new_block_delim_fn=is_not_indented, block_filter_fn=no_tw ) self.assertEqual( data, [[ 'One', ' ABCD' ], [ 'Three' ]] ) @@ -244,10 +242,12 @@ class Test_BlockDataProvider( test_base_dataproviders.Test_FilteredDataProvider def is_not_indented( line ): strip_diff = len( line ) - len( line.lstrip() ) return ( strip_diff == 0 ) + def empty_block( block ): if len( block ) <= 1: return None return { 'header': block[0].strip(), 'data': [ b.strip() for b in block[1:] if b.strip() ] } + ( contents, provider, data ) = self.contents_provider_and_data( strip_lines=False, strip_newlines=True, new_block_delim_fn=is_not_indented, block_filter_fn=empty_block ) @@ -261,10 +261,12 @@ class Test_BlockDataProvider( test_base_dataproviders.Test_FilteredDataProvider def is_not_indented( line ): strip_diff = len( line ) - len( line.lstrip() ) return ( strip_diff == 0 ) + def empty_block( block ): if len( block ) <= 1: return None return block + ( contents, provider, data ) = self.contents_provider_and_data( strip_lines=False, strip_newlines=True, new_block_delim_fn=is_not_indented, block_filter_fn=empty_block, limit=1 ) self.assertEqual( data, [[ 'One', ' ABCD' ]] ) @@ -286,10 +288,13 @@ class Test_BlockDataProvider( test_base_dataproviders.Test_FilteredDataProvider ABCD EFGH """ + def fasta_header( line ): return line.startswith( '>' ) + def id_seq( block ): return { 'id': block[0][1:], 'seq': ( ''.join( block[1:] ) ) } + ( contents, provider, data ) = self.contents_provider_and_data( contents=file_contents, new_block_delim_fn=fasta_header, block_filter_fn=id_seq ) self.assertEqual( data, [{ 'id': 'One', 'seq': 'ABCD' }, { 'id': 'Two', 'seq': 'ABCDEFGH' }] ) diff --git a/test/unit/managers/__init__.py b/test/unit/managers/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/unit/managers/test_ModelManager.py b/test/unit/managers/base.py similarity index 90% rename from test/unit/managers/test_ModelManager.py rename to test/unit/managers/base.py index fbaf0eb68af..3cda853977d 100644 --- a/test/unit/managers/test_ModelManager.py +++ b/test/unit/managers/base.py @@ -2,39 +2,26 @@ """ from __future__ import print_function -import sys import os -import pprint +import imp import unittest import json -__GALAXY_ROOT__ = os.getcwd() + '/../../../' -sys.path.insert( 1, __GALAXY_ROOT__ + 'lib' ) +test_utils = imp.load_source( 'test_utils', + os.path.join( os.path.dirname( __file__), '../unittest_utils/utility.py' ) ) +import galaxy_mock from galaxy import eggs eggs.require( 'SQLAlchemy >= 0.4' ) import sqlalchemy -from galaxy import model -from galaxy import exceptions -from galaxy.util.bunch import Bunch - -import mock from galaxy.managers.users import UserManager -from galaxy.managers import base - # ============================================================================= admin_email = 'admin@admin.admin' admin_users = admin_email default_password = '123456' -#def setUpModule(): -# print '=' * 20, 'begin module' -# -#def tearDownModule(): -# print '=' * 20, 'end module' - # ============================================================================= class BaseTestCase( unittest.TestCase ): @@ -57,7 +44,7 @@ class BaseTestCase( unittest.TestCase ): self.set_up_trans() def set_up_mocks( self ): - self.trans = mock.MockTrans( admin_users=admin_users ) + self.trans = galaxy_mock.MockTrans( admin_users=admin_users ) self.app = self.trans.app def set_up_managers( self ): diff --git a/test/unit/managers/test_CollectionManager.py b/test/unit/managers/test_CollectionManager.py index cbc0eecc53d..6d5f3da4ffe 100644 --- a/test/unit/managers/test_CollectionManager.py +++ b/test/unit/managers/test_CollectionManager.py @@ -1,23 +1,16 @@ #!/usr/bin/env python """ """ -import sys import os -import pprint +import imp import unittest -__GALAXY_ROOT__ = os.getcwd() + '/../../../' -sys.path.insert( 1, __GALAXY_ROOT__ + 'lib' ) - -from galaxy import eggs -eggs.require( 'SQLAlchemy >= 0.4' ) -import sqlalchemy +test_utils = imp.load_source( 'test_utils', + os.path.join( os.path.dirname( __file__), '../unittest_utils/utility.py' ) ) from galaxy import model -from galaxy import exceptions -import mock -from test_ModelManager import BaseTestCase +from base import BaseTestCase from galaxy.managers.datasets import DatasetManager from galaxy.managers.histories import HistoryManager from galaxy.managers.hdas import HDAManager @@ -45,9 +38,9 @@ class DatasetCollectionManagerTestCase( BaseTestCase ): identifier_list = [] for element in elements: src = 'hda' - #if isinstance( element, model.DatasetCollection ): + # if isinstance( element, model.DatasetCollection ): # src = 'collection'#? - #elif isinstance( element, model.LibraryDatasetDatasetAssociation ): + # elif isinstance( element, model.LibraryDatasetDatasetAssociation ): # src = 'ldda'#? encoded_id = self.trans.security.encode_id( element.id ) identifier_list.append( dict( src=src, name=element.name, id=encoded_id ) ) @@ -75,9 +68,9 @@ class DatasetCollectionManagerTestCase( BaseTestCase ): self.assertFalse( hdca.deleted ) self.assertTrue( hdca.visible ) - #print 'hdca dir:' - #for k in dir( hdca ): - # print k, getattr( hdca, k, '(?)' ) + # print 'hdca dir:' + # for k in dir( hdca ): + # print k, getattr( hdca, k, '(?)' ) self.log( "should contain an underlying, well-formed DatasetCollection" ) self.assertIsInstance( hdca.collection, model.DatasetCollection ) @@ -87,14 +80,14 @@ class DatasetCollectionManagerTestCase( BaseTestCase ): self.assertEqual( len( collection.dataset_instances ), 3 ) self.assertEqual( len( collection.elements ), 3 ) - #print 'hdca.collection dir:' - #for k in dir( hdca.collection ): - # print k, getattr( hdca.collection, k, '(?)' ) + # print 'hdca.collection dir:' + # for k in dir( hdca.collection ): + # print k, getattr( hdca.collection, k, '(?)' ) - #elements = collection.elements - #print 'hdca.collection element dir:' - #for k in dir( elements[0] ): - # print k, getattr( elements[0], k, '(?)' ) + # elements = collection.elements + # print 'hdca.collection element dir:' + # for k in dir( elements[0] ): + # print k, getattr( elements[0], k, '(?)' ) self.log( "and that collection should have three well-formed Elements" ) self.assertIsInstance( collection.elements[0], model.DatasetCollectionElement ) @@ -140,17 +133,17 @@ class DatasetCollectionManagerTestCase( BaseTestCase ): 'deleted' : True, 'visible' : False, 'name' : 'New Name', - #TODO: doesn't work - #'tags' : [ 'one', 'two', 'three' ] - #'annotations' : [?] + # TODO: doesn't work + # 'tags' : [ 'one', 'two', 'three' ] + # 'annotations' : [?] }) self.assertEqual( hdca.name, 'New Name' ) self.assertTrue( hdca.deleted ) self.assertFalse( hdca.visible ) - #self.assertEqual( hdca.tags, [ 'one', 'two', 'three' ] ) - #self.assertEqual( hdca.annotations, [ 'one', 'two', 'three' ] ) + # self.assertEqual( hdca.tags, [ 'one', 'two', 'three' ] ) + # self.assertEqual( hdca.annotations, [ 'one', 'two', 'three' ] ) - #def test_validation( self ): + # def test_validation( self ): # self.log( "should be able to change the name" ) # self.log( "should be able to set deleted" ) # self.log( "should be able to set visible" ) diff --git a/test/unit/managers/test_DatasetManager.py b/test/unit/managers/test_DatasetManager.py index e902bd14510..b5659126a2c 100644 --- a/test/unit/managers/test_DatasetManager.py +++ b/test/unit/managers/test_DatasetManager.py @@ -1,13 +1,12 @@ # -*- coding: utf-8 -*- """ """ -import sys import os -import pprint +import imp import unittest -__GALAXY_ROOT__ = os.getcwd() + '/../../../' -sys.path.insert( 1, __GALAXY_ROOT__ + 'lib' ) +test_utils = imp.load_source( 'test_utils', + os.path.join( os.path.dirname( __file__), '../unittest_utils/utility.py' ) ) from galaxy import eggs eggs.require( 'SQLAlchemy >= 0.4' ) @@ -15,12 +14,12 @@ import sqlalchemy from galaxy import model from galaxy import exceptions -from galaxy.util.bunch import Bunch -import mock -from test_ModelManager import BaseTestCase +from base import BaseTestCase + from galaxy.managers.datasets import ( DatasetManager, DatasetRBACPermissions, DatasetSerializer, DatasetDeserializer ) + from galaxy.managers.datasets import DatasetAssociationManager from galaxy.managers.histories import HistoryManager from galaxy.managers.hdas import HDAManager diff --git a/test/unit/managers/test_HDAManager.py b/test/unit/managers/test_HDAManager.py index 6e7d51c17da..7daa5d1ebe4 100644 --- a/test/unit/managers/test_HDAManager.py +++ b/test/unit/managers/test_HDAManager.py @@ -1,11 +1,10 @@ # -*- coding: utf-8 -*- -import sys import os -import pprint +import imp import unittest -__GALAXY_ROOT__ = os.getcwd() + '/../../../' -sys.path.insert( 1, __GALAXY_ROOT__ + 'lib' ) +test_utils = imp.load_source( 'test_utils', + os.path.join( os.path.dirname( __file__), '../unittest_utils/utility.py' ) ) from galaxy import eggs eggs.require( 'SQLAlchemy >= 0.4' ) @@ -13,10 +12,9 @@ import sqlalchemy from galaxy import model from galaxy import exceptions -from galaxy.util.bunch import Bunch -import mock -from test_ModelManager import BaseTestCase +from base import BaseTestCase + from galaxy.managers.histories import HistoryManager from galaxy.managers.datasets import DatasetManager from galaxy.managers import hdas @@ -27,6 +25,8 @@ default_password = '123456' user2_data = dict( email='user2@user2.user2', username='user2', password=default_password ) user3_data = dict( email='user3@user3.user3', username='user3', password=default_password ) + +# ============================================================================= class HDATestCase( BaseTestCase ): def set_up_managers( self ): @@ -74,8 +74,7 @@ class HDAManagerTestCase( HDATestCase ): [ hda3, hda2, hda1 ] ) def test_create( self ): - owner = self.user_manager.create( **user2_data ) - non_owner = self.user_manager.create( **user3_data ) + owner = self.user_manager.create( self.trans, **user2_data ) history1 = self.history_manager.create( name='history1', user=owner ) dataset1 = self.dataset_manager.create() @@ -117,9 +116,9 @@ class HDAManagerTestCase( HDATestCase ): self.assertEqual( hda2.dataset, hda1.dataset ) self.assertNotEqual( hda2, hda1 ) - #def test_copy_from_ldda( self ): - # owner = self.user_manager.create( **user2_data ) - # history1 = self.history_manager.create( name='history1', user=owner ) + # def test_copy_from_ldda( self ): + # owner = self.user_manager.create( self.trans, **user2_data ) + # history1 = self.history_mgr.create( self.trans, name='history1', user=owner ) # # self.log( "should be able to copy an HDA" ) # hda2 = self.hda_manager.copy_ldda( history1, hda1 ) @@ -198,6 +197,7 @@ class HDAManagerTestCase( HDATestCase ): item1 = self.hda_manager.create( history1, dataset1 ) self.log( "(by default, dataset permissions are lax) should be accessible to all" ) + for user in self.user_manager.list(): self.assertTrue( self.hda_manager.is_accessible( item1, user ) ) @@ -225,7 +225,7 @@ class HDAManagerTestCase( HDATestCase ): anon_user = None self.trans.set_user( anon_user ) history3 = self.history_manager.create( name='anon_history', user=anon_user ) - self.trans.set_history( history2 ) + self.trans.set_history( history3 ) self.assertRaises( exceptions.ItemAccessibilityException, self.hda_manager.get_accessible, item1.id, anon_user, current_history=self.trans.history ) @@ -314,6 +314,7 @@ class HDAManagerTestCase( HDATestCase ): testable_url_for = lambda *a, **k: '(fake url): %s, %s' % ( a, k ) hdas.HDASerializer.url_for = staticmethod( testable_url_for ) + class HDASerializerTestCase( HDATestCase ): def set_up_managers( self ): @@ -329,7 +330,7 @@ class HDASerializerTestCase( HDATestCase ): self.log( 'should have the summary view as default view' ) default_view = self.hda_serializer.serialize_to_view( hda, default_view='summary' ) - self.assertKeys( summary_view, self.hda_serializer.views[ 'summary' ] ) + self.assertKeys( default_view, self.hda_serializer.views[ 'summary' ] ) # self.log( 'should have a detailed view' ) # detailed_view = self.hda_serializer.serialize_to_view( hda, view='detailed' ) @@ -581,7 +582,6 @@ class HDAFilterParserTestCase( HDATestCase ): # annotatable self.assertFnFilter( self.filter_parser.parse_filter( 'annotation', 'has', 'wot' ) ) - def test_genome_build_filters( self ): pass diff --git a/test/unit/managers/test_HistoryManager.py b/test/unit/managers/test_HistoryManager.py index b727b3dddff..c55c25e4f0e 100644 --- a/test/unit/managers/test_HistoryManager.py +++ b/test/unit/managers/test_HistoryManager.py @@ -1,13 +1,13 @@ # -*- coding: utf-8 -*- """ """ -import sys import os -import pprint +import imp import unittest -__GALAXY_ROOT__ = os.getcwd() + '/../../../' -sys.path.insert( 1, __GALAXY_ROOT__ + 'lib' ) +test_utils = imp.load_source( 'test_utils', + os.path.join( os.path.dirname( __file__), '../unittest_utils/utility.py' ) ) +import galaxy_mock from galaxy import eggs eggs.require( 'SQLAlchemy >= 0.4' ) @@ -15,10 +15,8 @@ import sqlalchemy from galaxy import model from galaxy import exceptions -from galaxy.util.bunch import Bunch -import mock -from test_ModelManager import BaseTestCase +from base import BaseTestCase from galaxy.managers.histories import HistoryManager from galaxy.managers.histories import HistorySerializer @@ -221,7 +219,7 @@ class HistoryManagerTestCase( BaseTestCase ): item1 = self.history_manager.create( user=owner ) non_owner = self.user_manager.create( **user3_data ) - #third_party = self.user_manager.create( **user4_data ) + # third_party = self.user_manager.create( **user4_data ) self.log( "should be unshared by default" ) self.assertEqual( self.history_manager.get_share_assocs( item1 ), [] ) @@ -245,7 +243,7 @@ class HistoryManagerTestCase( BaseTestCase ): self.assertEqual( self.history_manager.get_share_assocs( item1, user=non_owner ), [] ) - #TODO: test slug formation + # TODO: test slug formation def test_anon( self ): anon_user = None @@ -318,6 +316,7 @@ testable_url_for = lambda *a, **k: '(fake url): %s, %s' % ( a, k ) HistorySerializer.url_for = staticmethod( testable_url_for ) hdas.HDASerializer.url_for = staticmethod( testable_url_for ) + class HistorySerializerTestCase( BaseTestCase ): def set_up_managers( self ): @@ -340,7 +339,7 @@ class HistorySerializerTestCase( BaseTestCase ): self.log( 'should have the summary view as default view' ) default_view = self.history_serializer.serialize_to_view( history1, default_view='summary' ) - self.assertKeys( summary_view, self.history_serializer.views[ 'summary' ] ) + self.assertKeys( default_view, self.history_serializer.views[ 'summary' ] ) self.log( 'should have a serializer for all serializable keys' ) for key in self.history_serializer.serializable_keyset: @@ -508,7 +507,7 @@ class HistoryFiltersTestCase( BaseTestCase ): ( 'name', 'like', 'history%' ), ]) histories = self.history_manager.list( filters=filters ) - #for h in histories: + # for h in histories: # print h.name self.assertEqual( histories, [ history1, history2, history3 ]) @@ -577,7 +576,7 @@ class HistoryFiltersTestCase( BaseTestCase ): self.assertEqual( len( filters ), 1 ) filter_ = filters[0] - fake = mock.OpenObject() + fake = galaxy_mock.OpenObject() fake.name = '123' self.log( '123 should return true through the filter' ) self.assertTrue( filter_( fake ) ) diff --git a/test/unit/managers/test_UserManager.py b/test/unit/managers/test_UserManager.py index 843f4f0630c..773c11fcd3c 100644 --- a/test/unit/managers/test_UserManager.py +++ b/test/unit/managers/test_UserManager.py @@ -1,13 +1,12 @@ # -*- coding: utf-8 -*- """ """ -import sys import os -import pprint +import imp import unittest -__GALAXY_ROOT__ = os.getcwd() + '/../../../' -sys.path.insert( 1, __GALAXY_ROOT__ + 'lib' ) +test_utils = imp.load_source( 'test_utils', + os.path.join( os.path.dirname( __file__), '../unittest_utils/utility.py' ) ) from galaxy import eggs eggs.require( 'SQLAlchemy >= 0.4' ) @@ -15,10 +14,8 @@ import sqlalchemy from galaxy import model from galaxy import exceptions -from galaxy.util.bunch import Bunch -import mock -from test_ModelManager import BaseTestCase +from base import BaseTestCase from galaxy.managers import users from galaxy.managers import histories @@ -67,7 +64,7 @@ class UserManagerTestCase( BaseTestCase ): [ user3, user2, self.admin_user ] ) def test_invalid_create( self ): - user2 = self.user_manager.create( **user2_data ) + self.user_manager.create( **user2_data ) self.log( "emails must be unique" ) self.assertRaises( exceptions.Conflict, self.user_manager.create, @@ -83,13 +80,11 @@ class UserManagerTestCase( BaseTestCase ): self.log( "should be able to query by email" ) self.assertEqual( self.user_manager.by_email( user2_data[ 'email' ] ), user2 ) - #note: sorted by email alpha - users = self.trans.sa_session.query( model.User ).all() + # note: sorted by email alpha self.assertEqual( self.user_manager.by_email_like( '%@%' ), [ self.admin_user, user2, user3 ] ) def test_admin( self ): user2 = self.user_manager.create( **user2_data ) - user3 = self.user_manager.create( **user3_data ) self.log( "should be able to test whether admin" ) self.assertTrue( self.user_manager.is_admin( self.admin_user ) ) @@ -108,7 +103,6 @@ class UserManagerTestCase( BaseTestCase ): def test_current( self ): user2 = self.user_manager.create( **user2_data ) - user3 = self.user_manager.create( **user3_data ) self.log( "should be able to tell if a user is the current (trans) user" ) self.assertEqual( self.user_manager.current_user( self.trans ), self.admin_user ) @@ -116,7 +110,6 @@ class UserManagerTestCase( BaseTestCase ): def test_api_keys( self ): user2 = self.user_manager.create( **user2_data ) - user3 = self.user_manager.create( **user3_data ) self.log( "should return None if no APIKey has been created" ) self.assertEqual( self.user_manager.valid_api_key( user2 ), None ) @@ -147,7 +140,7 @@ class UserSerializerTestCase( BaseTestCase ): self.log( 'should have the summary view as default view' ) default_view = self.user_serializer.serialize_to_view( user, default_view='summary' ) - self.assertKeys( summary_view, self.user_serializer.views[ 'summary' ] ) + self.assertKeys( default_view, self.user_serializer.views[ 'summary' ] ) self.log( 'should have a serializer for all serializable keys' ) for key in self.user_serializer.serializable_keyset: diff --git a/test/unit/unittest_utils/__init__.py b/test/unit/unittest_utils/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/unit/managers/mock.py b/test/unit/unittest_utils/galaxy_mock.py similarity index 69% rename from test/unit/managers/mock.py rename to test/unit/unittest_utils/galaxy_mock.py index adc67c6a52d..ecd2c19d4a8 100644 --- a/test/unit/managers/mock.py +++ b/test/unit/unittest_utils/galaxy_mock.py @@ -3,6 +3,9 @@ Mock infrastructure for testing ModelManagers. """ import sys import os +import tempfile +import shutil + __GALAXY_ROOT__ = os.getcwd() + '/../../../' sys.path.insert( 1, __GALAXY_ROOT__ + 'lib' ) @@ -23,7 +26,9 @@ from galaxy import quota class OpenObject( object ): pass + class MockApp( object ): + def __init__( self, **kwargs ): self.config = MockAppConfig( **kwargs ) self.security = self.config.security @@ -34,8 +39,10 @@ class MockApp( object ): self.tag_handler = tags.GalaxyTagManager( self ) self.quota_agent = quota.QuotaAgent( self.model ) + class MockAppConfig( Bunch ): - def __init__( self, **kwargs ): + + def __init__( self, root=None, **kwargs ): Bunch.__init__( self, **kwargs ) self.security = security.SecurityHelper( id_secret='bler' ) self.file_path = '/tmp' @@ -53,17 +60,19 @@ class MockAppConfig( Bunch ): self.allow_user_dataset_purge = True self.enable_old_display_applications = True + # set by MockDir + self.root = root + + class MockWebapp( object ): + def __init__( self, **kwargs ): self.name = kwargs.get( 'name', 'galaxy' ) -class MockVisualizationsRegistry( object ): - def get_visualizations( self, trans, target ): - return [] class MockTrans( object ): - def __init__( self, user=None, history=None, **kwargs ): + def __init__( self, user=None, history=None, **kwargs ): self.app = MockApp( **kwargs ) self.model = self.app.model self.webapp = MockWebapp( **kwargs ) @@ -100,3 +109,42 @@ class MockTrans( object ): 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 [] + + +class MockDir( object ): + + def __init__( self, structure_dict, where=None ): + self.structure_dict = structure_dict + self.create_root( structure_dict, where ) + + def create_root( self, structure_dict, where=None ): + self.root_path = tempfile.mkdtemp( dir=where ) + # print 'created root:', self.root_path + self.create_structure( self.root_path, structure_dict ) + + def create_structure( self, current_path, structure_dict ): + for k, v in structure_dict.items(): + # if value is string, create a file in the current path and write v as file contents + if isinstance( v, str ): + self.create_file( os.path.join( current_path, k ), v ) + # if it's a dict, create a dir here named k and recurse into it + if isinstance( v, dict ): + subdir_path = os.path.join( current_path, k ) + # print 'subdir:', subdir_path + os.mkdir( subdir_path ) + self.create_structure( subdir_path, v ) + + def create_file( self, path, contents ): + # print 'file:', path + with open( path, 'w' ) as newfile: + newfile.write( contents ) + + def remove( self ): + # print 'removing:', self.root_path + shutil.rmtree( self.root_path ) diff --git a/test/unit/datatypes/dataproviders/tempfilecache.py b/test/unit/unittest_utils/tempfilecache.py similarity index 99% rename from test/unit/datatypes/dataproviders/tempfilecache.py rename to test/unit/unittest_utils/tempfilecache.py index 84f00e4f07b..6f7cbf7c782 100644 --- a/test/unit/datatypes/dataproviders/tempfilecache.py +++ b/test/unit/unittest_utils/tempfilecache.py @@ -6,10 +6,12 @@ import logging logging.getLogger( __name__ ) log = logging + class TempFileCache( object ): """ Creates and caches tempfiles with/based-on the given contents. """ + def __init__( self, logger=None ): if logger: global log diff --git a/test/unit/unittest_utils/utility.py b/test/unit/unittest_utils/utility.py new file mode 100644 index 00000000000..80af563be3e --- /dev/null +++ b/test/unit/unittest_utils/utility.py @@ -0,0 +1,40 @@ +""" +Unit test utilities. +""" +import os +import sys +import textwrap + + +# ============================================================================= +def get_unittest_utils_path(): + return os.path.normpath( os.path.join( os.getcwd(), os.path.dirname( __file__ ) ) ) + + +def get_galaxy_root(): + # precondition: this file must be at /test/unit/unittest_utils/utility.py + return os.path.normpath( os.path.join( get_unittest_utils_path(), '../../../' ) ) + + +def get_galaxy_libpath(): + # precondition: this file must be at /test/unit/unittest_utils/utility.py + return os.path.join( get_galaxy_root(), 'lib' ) + + +def clean_multiline_string( multiline_string, sep='\n' ): + """ + Dedent, split, remove first and last empty lines, rejoin. + """ + multiline_string = textwrap.dedent( multiline_string ) + string_list = multiline_string.split( sep ) + if not string_list[0]: + string_list = string_list[1:] + if not string_list[-1]: + string_list = string_list[:-1] + # return '\n'.join( docstrings ) + return ''.join([ ( s + '\n' ) for s in string_list ]) + + +# ============================================================================= +sys.path.insert( 0, get_galaxy_libpath() ) +sys.path.insert( 1, get_unittest_utils_path() ) diff --git a/test/unit/util/utility.py b/test/unit/util/utility.py deleted file mode 100644 index e62034d7469..00000000000 --- a/test/unit/util/utility.py +++ /dev/null @@ -1,45 +0,0 @@ -""" -Unit test utilities. -""" - -import os -import sys -import logging -import textwrap - -def set_up_filelogger( logname, level=logging.DEBUG ): - """ - Sets up logging to a file named `logname` - (removing it first if it already exists). - - Usable with 'nosetests' to get logging msgs from failed tests - (no logfile created). - Usable with 'nosetests --nologcapture' to get logging msgs for all tests - (in logfile). - """ - if os.path.exists( logname ): os.unlink( logname ) - logging.basicConfig( filename=logname, level=logging.DEBUG ) - return logging - -def add_galaxy_lib_to_path( this_dir_relative_to_root ): - """ - Adds `/lib` to `sys.path` given the scripts directory relative - to ``. - .. example:: - utility.add_galaxy_lib_to_path( '/test/unit/datatypes/dataproviders' ) - """ - glx_lib = os.path.join( os.getcwd().replace( this_dir_relative_to_root, '' ), 'lib' ) - sys.path.insert( 1, glx_lib ) - -def clean_multiline_string( multiline_string, sep='\n' ): - """ - Dedent, split, remove first and last empty lines, rejoin. - """ - multiline_string = textwrap.dedent( multiline_string ) - string_list = multiline_string.split( sep ) - if not string_list[0]: - string_list = string_list[1:] - if not string_list[-1]: - string_list = string_list[:-1] - #return '\n'.join( docstrings ) - return ''.join([ ( s + '\n' ) for s in string_list ]) diff --git a/test/unit/visualizations/__init__.py b/test/unit/visualizations/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/unit/visualizations/registry/test_VisualizationsRegistry.py b/test/unit/visualizations/test_VisualizationsRegistry.py similarity index 89% rename from test/unit/visualizations/registry/test_VisualizationsRegistry.py rename to test/unit/visualizations/test_VisualizationsRegistry.py index 51c4faa2527..2ec09af3d5d 100644 --- a/test/unit/visualizations/registry/test_VisualizationsRegistry.py +++ b/test/unit/visualizations/test_VisualizationsRegistry.py @@ -4,18 +4,14 @@ import os import imp import unittest -utility = imp.load_source( 'utility', os.path.join( os.path.dirname( __file__ ), '../../util/utility.py' ) ) -log = utility.set_up_filelogger( __name__ + '.log' ) - -relative_test_path = '/test/unit/visualizations/registry' -utility.add_galaxy_lib_to_path( relative_test_path ) +test_utils = imp.load_source( 'test_utils', + os.path.join( os.path.dirname( __file__), '../unittest_utils/utility.py' ) ) +import galaxy_mock from galaxy.visualization.registry import VisualizationsRegistry -base_mock = imp.load_source( 'mock', os.path.join( os.path.dirname( __file__ ), '../../web/base/mock.py' ) ) - # ----------------------------------------------------------------------------- globals -glx_dir = os.getcwd().replace( relative_test_path, '' ) +glx_dir = test_utils.get_galaxy_root() template_cache_dir = os.path.join( glx_dir, 'database', 'compiled_templates' ) vis_reg_path = 'config/plugins/visualizations' @@ -37,21 +33,24 @@ config1 = """\ """ + # ----------------------------------------------------------------------------- class VisualizationsRegistry_TestCase( unittest.TestCase ): # ------------------------------------------------------------------------- vis plugin discovery def test_plugin_load_from_repo( self ): """should attempt load if criteria met""" - mock_app = base_mock.MockApp( glx_dir ) + mock_app = galaxy_mock.MockApp( root=glx_dir ) plugin_mgr = VisualizationsRegistry( mock_app, directories_setting=vis_reg_path, 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' ) self.assertEqual( scatterplot.path, os.path.join( expected_plugins_path, 'scatterplot' ) ) @@ -72,7 +71,7 @@ class VisualizationsRegistry_TestCase( unittest.TestCase ): def test_plugin_load( self ): """""" - mock_app_dir = base_mock.MockDir({ + mock_app_dir = galaxy_mock.MockDir({ 'plugins' : { 'vis1' : { 'config' : { @@ -107,7 +106,7 @@ class VisualizationsRegistry_TestCase( unittest.TestCase ): }, } }) - mock_app = base_mock.MockApp( mock_app_dir.root_path ) + mock_app = galaxy_mock.MockApp( root=mock_app_dir.root_path ) plugin_mgr = VisualizationsRegistry( mock_app, directories_setting='plugins', template_cache_dir='bler' ) @@ -140,7 +139,7 @@ class VisualizationsRegistry_TestCase( unittest.TestCase ): mock_app_dir.remove() -#TODO: config parser tests (in separate file) +# TODO: config parser tests (in separate file) if __name__ == '__main__': unittest.main() diff --git a/test/unit/web/__init__.py b/test/unit/web/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/unit/web/base/__init__.py b/test/unit/web/base/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/unit/web/base/mock.py b/test/unit/web/base/mock.py deleted file mode 100644 index cb119749389..00000000000 --- a/test/unit/web/base/mock.py +++ /dev/null @@ -1,61 +0,0 @@ -""" -""" -import tempfile -import os -import shutil - -class MockDir( object ): - - def __init__( self, structure_dict, where=None ): - self.structure_dict = structure_dict - self.create_root( structure_dict, where ) - - def create_root( self, structure_dict, where=None ): - self.root_path = tempfile.mkdtemp( dir=where ) - #print 'created root:', self.root_path - self.create_structure( self.root_path, structure_dict ) - - def create_structure( self, current_path, structure_dict ): - for k, v in structure_dict.items(): - # if value is string, create a file in the current path and write v as file contents - if isinstance( v, str ): - self.create_file( os.path.join( current_path, k ), v ) - # if it's a dict, create a dir here named k and recurse into it - if isinstance( v, dict ): - subdir_path = os.path.join( current_path, k ) - #print 'subdir:', subdir_path - os.mkdir( subdir_path ) - self.create_structure( subdir_path, v ) - - def create_file( self, path, contents ): - #print 'file:', path - with open( path, 'w' ) as newfile: - newfile.write( contents ) - - def remove( self ): - #print 'removing:', self.root_path - shutil.rmtree( self.root_path ) - - -class MockAppConfig( object ): - def __init__( self, root ): - self.root = root - -class MockApp( object ): - def __init__( self, root ): - self.config = MockAppConfig( root ) - -class MockTrans( object ): - def fill_template( self, filename, template_lookup=None, **kwargs ): - template = template_lookup.get_template( filename ) - template.output_encoding = 'utf-8' - return template.render( **kwargs ) - -if __name__ == '__main__': - td = MockDir({ - 'file1' : 'Hello\nthere,\t...you', - 'dir1' : { - 'file2' : 'Blerbler', - } - }) - td.remove() diff --git a/test/unit/web/base/test_HookPluginManager.py b/test/unit/web/base/test_HookPluginManager.py index 0684cc349ba..36b418d6d86 100644 --- a/test/unit/web/base/test_HookPluginManager.py +++ b/test/unit/web/base/test_HookPluginManager.py @@ -5,14 +5,15 @@ import imp import unittest import types -utility = imp.load_source( 'utility', os.path.join( os.path.dirname( __file__ ), '../../util/utility.py' ) ) -log = utility.set_up_filelogger( __name__ + '.log' ) -utility.add_galaxy_lib_to_path( 'test/unit/web/base' ) +import logging +log = logging.getLogger( __name__ ) + +test_utils = imp.load_source( 'test_utils', + os.path.join( os.path.dirname( __file__), '../../unittest_utils/utility.py' ) ) +import galaxy_mock from galaxy.web.base.pluginframework import HookPluginManager -import mock - # ----------------------------------------------------------------------------- globals loading_point = HookPluginManager.loading_point_filename @@ -67,12 +68,13 @@ def hook_filter_test( s ): raise Exception( 'bler' ) """ + # ----------------------------------------------------------------------------- class HookPluginManager_TestCase( unittest.TestCase ): def test_loading_point( self ): """should attempt load on dirs containing loading_point file""" - mock_app_dir = mock.MockDir({ + mock_app_dir = galaxy_mock.MockDir({ 'plugins' : { 'plugin1' : { loading_point : contents1 @@ -80,7 +82,7 @@ class HookPluginManager_TestCase( unittest.TestCase ): 'not_a_plugin' : 'blerbler' } }) - mock_app = mock.MockApp( mock_app_dir.root_path ) + mock_app = galaxy_mock.MockApp( root=mock_app_dir.root_path ) plugin_mgr = HookPluginManager( mock_app, directories_setting='plugins' ) app_path = mock_app_dir.root_path @@ -99,7 +101,7 @@ class HookPluginManager_TestCase( unittest.TestCase ): def test_bad_loading_points( self ): """should NOT attempt load on dirs NOT containing loading_point file""" - mock_app_dir = mock.MockDir({ + mock_app_dir = galaxy_mock.MockDir({ 'plugins' : { 'plugin1' : {}, 'plugin2' : { @@ -107,7 +109,7 @@ class HookPluginManager_TestCase( unittest.TestCase ): } } }) - mock_app = mock.MockApp( mock_app_dir.root_path ) + mock_app = galaxy_mock.MockApp( root=mock_app_dir.root_path ) plugin_mgr = HookPluginManager( mock_app, directories_setting='plugins' ) app_path = mock_app_dir.root_path @@ -120,14 +122,14 @@ class HookPluginManager_TestCase( unittest.TestCase ): def test_bad_import( self ): """should error gracefully (skip) on bad import""" - mock_app_dir = mock.MockDir({ + mock_app_dir = galaxy_mock.MockDir({ 'plugins' : { 'plugin1' : { loading_point : contents2 } } }) - mock_app = mock.MockApp( mock_app_dir.root_path ) + mock_app = galaxy_mock.MockApp( root=mock_app_dir.root_path ) plugin_mgr = HookPluginManager( mock_app, directories_setting='plugins' ) app_path = mock_app_dir.root_path @@ -140,7 +142,7 @@ class HookPluginManager_TestCase( unittest.TestCase ): def test_import_w_rel_import( self ): """should allow loading_point to rel. import other modules""" - mock_app_dir = mock.MockDir({ + mock_app_dir = galaxy_mock.MockDir({ 'plugins' : { 'plugin1' : { 'contents1.py': contents1, @@ -148,7 +150,7 @@ class HookPluginManager_TestCase( unittest.TestCase ): } } }) - mock_app = mock.MockApp( mock_app_dir.root_path ) + mock_app = galaxy_mock.MockApp( root=mock_app_dir.root_path ) plugin_mgr = HookPluginManager( mock_app, directories_setting='plugins', skip_bad_plugins=False ) app_path = mock_app_dir.root_path @@ -167,14 +169,14 @@ class HookPluginManager_TestCase( unittest.TestCase ): def test_import_w_galaxy_import( self ): """should allow loading_point to rel. import GALAXY modules""" - mock_app_dir = mock.MockDir({ + mock_app_dir = galaxy_mock.MockDir({ 'plugins' : { 'plugin1' : { loading_point : contents4 } } }) - mock_app = mock.MockApp( mock_app_dir.root_path ) + mock_app = galaxy_mock.MockApp( root=mock_app_dir.root_path ) plugin_mgr = HookPluginManager( mock_app, directories_setting='plugins', skip_bad_plugins=False ) app_path = mock_app_dir.root_path @@ -194,7 +196,7 @@ class HookPluginManager_TestCase( unittest.TestCase ): def test_run_hooks( self ): """should run hooks of loaded plugins""" - mock_app_dir = mock.MockDir({ + mock_app_dir = galaxy_mock.MockDir({ 'plugins' : { 'plugin1' : { loading_point : contents5 @@ -204,10 +206,8 @@ class HookPluginManager_TestCase( unittest.TestCase ): } } }) - mock_app = mock.MockApp( mock_app_dir.root_path ) + mock_app = galaxy_mock.MockApp( root=mock_app_dir.root_path ) plugin_mgr = HookPluginManager( mock_app, directories_setting='plugins', skip_bad_plugins=False ) - app_path = mock_app_dir.root_path - expected_plugins_path = os.path.join( app_path, 'plugins' ) self.assertItemsEqual( plugin_mgr.plugins.keys(), [ 'plugin1', 'plugin2' ] ) return_val_dict = plugin_mgr.run_hook( 'blah', 'one two check' ) @@ -220,7 +220,7 @@ class HookPluginManager_TestCase( unittest.TestCase ): def test_hook_errs( self ): """should fail gracefully if hook fails (and continue with other plugins)""" - mock_app_dir = mock.MockDir({ + mock_app_dir = galaxy_mock.MockDir({ 'plugins' : { 'plugin1' : { loading_point : contents5 @@ -233,10 +233,8 @@ class HookPluginManager_TestCase( unittest.TestCase ): } } }) - mock_app = mock.MockApp( mock_app_dir.root_path ) + mock_app = galaxy_mock.MockApp( root=mock_app_dir.root_path ) plugin_mgr = HookPluginManager( mock_app, directories_setting='plugins', skip_bad_plugins=False ) - app_path = mock_app_dir.root_path - expected_plugins_path = os.path.join( app_path, 'plugins' ) self.assertItemsEqual( plugin_mgr.plugins.keys(), [ 'plugin1', 'plugin2', 'plugin3' ] ) return_val_dict = plugin_mgr.run_hook( 'blah', 'one two check' ) diff --git a/test/unit/web/base/test_PageServingPluginManager.py b/test/unit/web/base/test_PageServingPluginManager.py index 380e9ec842c..4c51468e7af 100644 --- a/test/unit/web/base/test_PageServingPluginManager.py +++ b/test/unit/web/base/test_PageServingPluginManager.py @@ -4,23 +4,26 @@ import os import imp import unittest -utility = imp.load_source( 'utility', os.path.join( os.path.dirname( __file__ ), '../../util/utility.py' ) ) -log = utility.set_up_filelogger( __name__ + '.log' ) -utility.add_galaxy_lib_to_path( 'test/unit/web/base' ) +import logging +log = logging.getLogger( __name__ ) + +test_utils = imp.load_source( 'test_utils', + os.path.join( os.path.dirname( __file__), '../../unittest_utils/utility.py' ) ) +import galaxy_mock from galaxy.web.base.pluginframework import PageServingPluginManager -import mock # ----------------------------------------------------------------------------- globals contents1 = """${what} ${you} ${say}""" + # ----------------------------------------------------------------------------- class PageServingPluginManager_TestCase( unittest.TestCase ): def test_plugin_load( self ): """should attempt load if criteria met""" - mock_app_dir = mock.MockDir({ + mock_app_dir = galaxy_mock.MockDir({ 'plugins' : { 'plugin1' : { 'templates' : {}, @@ -36,7 +39,7 @@ class PageServingPluginManager_TestCase( unittest.TestCase ): 'not_a_plugin2' : {}, } }) - mock_app = mock.MockApp( mock_app_dir.root_path ) + mock_app = galaxy_mock.MockApp( root=mock_app_dir.root_path ) plugin_mgr = PageServingPluginManager( mock_app, 'test', directories_setting='plugins' ) app_path = mock_app_dir.root_path @@ -79,7 +82,7 @@ class PageServingPluginManager_TestCase( unittest.TestCase ): def test_plugin_static_map( self ): """""" - mock_app_dir = mock.MockDir({ + mock_app_dir = galaxy_mock.MockDir({ 'plugins' : { 'plugin1' : { 'templates' : {}, @@ -87,11 +90,9 @@ class PageServingPluginManager_TestCase( unittest.TestCase ): } } }) - mock_app = mock.MockApp( mock_app_dir.root_path ) + mock_app = galaxy_mock.MockApp( root=mock_app_dir.root_path ) plugin_mgr = PageServingPluginManager( mock_app, 'test', directories_setting='plugins' ) - app_path = mock_app_dir.root_path - expected_plugins_path = os.path.join( app_path, 'plugins' ) self.assertItemsEqual( plugin_mgr.plugins.keys(), [ 'plugin1' ] ) plugin = plugin_mgr.plugins[ 'plugin1' ] self.assertEqual( plugin_mgr.get_static_urls_and_paths(), [( plugin.static_url, plugin.static_path )] ) @@ -100,7 +101,7 @@ class PageServingPluginManager_TestCase( unittest.TestCase ): def test_plugin_templates( self ): """""" - mock_app_dir = mock.MockDir({ + mock_app_dir = galaxy_mock.MockDir({ 'plugins' : { 'plugin1' : { 'templates' : { @@ -109,15 +110,12 @@ class PageServingPluginManager_TestCase( unittest.TestCase ): } } }) - mock_app = mock.MockApp( mock_app_dir.root_path ) + mock_app = galaxy_mock.MockApp( root=mock_app_dir.root_path ) plugin_mgr = PageServingPluginManager( mock_app, 'test', directories_setting='plugins' ) - app_path = mock_app_dir.root_path - expected_plugins_path = os.path.join( app_path, 'plugins' ) self.assertItemsEqual( plugin_mgr.plugins.keys(), [ 'plugin1' ] ) - plugin = plugin_mgr.plugins[ 'plugin1' ] - rendered = plugin_mgr.fill_template( mock.MockTrans(), plugin, 'test.mako', + rendered = plugin_mgr.fill_template( galaxy_mock.MockTrans(), plugin, 'test.mako', what='Hey', you='Ho', say='HeyHey HoHo' ) self.assertEqual( rendered, 'Hey Ho HeyHey HoHo' ) diff --git a/test/unit/web/base/test_PluginManager.py b/test/unit/web/base/test_PluginManager.py index 3edb1bf773b..b0cf929792e 100644 --- a/test/unit/web/base/test_PluginManager.py +++ b/test/unit/web/base/test_PluginManager.py @@ -5,26 +5,28 @@ import os import imp import unittest -utility = imp.load_source( 'utility', os.path.join( os.path.dirname( __file__ ), '../../util/utility.py' ) ) -log = utility.set_up_filelogger( __name__ + '.log' ) -utility.add_galaxy_lib_to_path( 'test/unit/web/base' ) +import logging +log = logging.getLogger( __name__ ) + +test_utils = imp.load_source( 'test_utils', + os.path.join( os.path.dirname( __file__), '../../unittest_utils/utility.py' ) ) +import galaxy_mock from galaxy.web.base.pluginframework import PluginManager -import mock class PluginManager_TestCase( unittest.TestCase ): def test_rel_path_search( self ): """should be able to search given rel. path""" - mock_app_dir = mock.MockDir({ + mock_app_dir = galaxy_mock.MockDir({ 'plugins' : { 'plugin1' : {}, 'plugin2' : {}, 'file1' : 'blerbler' } }) - mock_app = mock.MockApp( mock_app_dir.root_path ) + mock_app = galaxy_mock.MockApp( root=mock_app_dir.root_path ) plugin_mgr = PluginManager( mock_app, directories_setting='plugins' ) app_path = mock_app_dir.root_path @@ -41,16 +43,14 @@ class PluginManager_TestCase( unittest.TestCase ): def test_abs_path_search( self ): """should be able to search given abs. path""" - mock_app_dir = mock.MockDir({}) - mock_plugin_dir = mock.MockDir({ + mock_app_dir = galaxy_mock.MockDir({}) + mock_plugin_dir = galaxy_mock.MockDir({ 'plugin1' : {}, 'plugin2' : {}, 'file1' : 'blerbler' }) - mock_app = mock.MockApp( mock_app_dir.root_path ) + mock_app = galaxy_mock.MockApp( root=mock_app_dir.root_path ) plugin_mgr = PluginManager( mock_app, directories_setting=mock_plugin_dir.root_path ) - - app_path = mock_app_dir.root_path expected_plugins_path = mock_plugin_dir.root_path self.assertItemsEqual( plugin_mgr.directories, [ expected_plugins_path ] ) @@ -62,20 +62,20 @@ class PluginManager_TestCase( unittest.TestCase ): def test_multiple_dirs( self ): """should search in multiple directories""" - mock_app_dir = mock.MockDir({ + mock_app_dir = galaxy_mock.MockDir({ 'plugins' : { 'plugin1' : {}, 'plugin2' : {}, 'file1' : 'blerbler' } }) - mock_abs_plugin_dir = mock.MockDir({ + mock_abs_plugin_dir = galaxy_mock.MockDir({ 'plugin3' : {}, 'plugin4' : {}, 'file2' : 'blerbler' }) - mock_app = mock.MockApp( mock_app_dir.root_path ) - directories_setting=','.join([ 'plugins', mock_abs_plugin_dir.root_path ]) + mock_app = galaxy_mock.MockApp( root=mock_app_dir.root_path ) + directories_setting = ','.join([ 'plugins', mock_abs_plugin_dir.root_path ]) plugin_mgr = PluginManager( mock_app, directories_setting=directories_setting ) app_path = mock_app_dir.root_path @@ -96,4 +96,3 @@ class PluginManager_TestCase( unittest.TestCase ): if __name__ == '__main__': unittest.main() -