def test_hook_errs( self ): """should fail gracefully if hook fails (and continue with other plugins)""" mock_app_dir = mock.MockDir({ 'plugins' : { 'plugin1' : { loading_point : contents5 }, 'plugin2' : { loading_point : contents6 }, 'plugin3' : { loading_point : contents7 } } }) mock_app = mock.MockApp( 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' ) self.assertEqual( return_val_dict, { 'plugin1' : 'One Two Check', 'plugin2' : 'ONE TWO CHECK' } ) result = plugin_mgr.filter_hook( 'filter_test', 'check' ) self.assertEqual( result, 'check one two' ) mock_app_dir.remove()
def test_loading_point( self ): """should attempt load on dirs containing loading_point file""" mock_app_dir = mock.MockDir({ 'plugins' : { 'plugin1' : { loading_point : contents1 }, 'not_a_plugin' : 'blerbler' } }) mock_app = mock.MockApp( mock_app_dir.root_path ) plugin_mgr = HookPluginManager( mock_app, directories_setting='plugins' ) app_path = mock_app_dir.root_path expected_plugins_path = os.path.join( app_path, 'plugins' ) self.assertItemsEqual( plugin_mgr.directories, [ expected_plugins_path ] ) self.assertItemsEqual( plugin_mgr.plugins.keys(), [ 'plugin1' ] ) plugin = plugin_mgr.plugins[ 'plugin1' ] self.assertEqual( plugin.name, 'plugin1' ) self.assertEqual( plugin.path, os.path.join( expected_plugins_path, 'plugin1' ) ) self.assertIsInstance( plugin.module, types.ModuleType ) self.assertEqual( plugin.module.bler( 2 ), ( 2, 3 ) ) mock_app_dir.remove()
def test_rel_path_search(self): """should be able to search given rel. path""" mock_app_dir = mock.MockDir( {'plugins': { 'plugin1': {}, 'plugin2': {}, 'file1': 'blerbler' }}) mock_app = mock.MockApp(mock_app_dir.root_path) plugin_mgr = PluginManager(mock_app, directories_setting='plugins') app_path = mock_app_dir.root_path expected_plugins_path = os.path.join(app_path, 'plugins') self.assertItemsEqual(plugin_mgr.directories, [expected_plugins_path]) self.assertItemsEqual(plugin_mgr.plugins.keys(), ['plugin1', 'plugin2']) self.assertEqual(plugin_mgr.plugins['plugin1'].name, 'plugin1') self.assertEqual(plugin_mgr.plugins['plugin1'].path, os.path.join(expected_plugins_path, 'plugin1')) self.assertEqual(plugin_mgr.plugins['plugin2'].name, 'plugin2') self.assertEqual(plugin_mgr.plugins['plugin2'].path, os.path.join(expected_plugins_path, 'plugin2')) mock_app_dir.remove()
def test_import_w_galaxy_import( self ): """should allow loading_point to rel. import GALAXY modules""" mock_app_dir = mock.MockDir({ 'plugins' : { 'plugin1' : { loading_point : contents4 } } }) mock_app = mock.MockApp( 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.directories, [ expected_plugins_path ] ) self.assertItemsEqual( plugin_mgr.plugins.keys(), [ 'plugin1' ] ) plugin = plugin_mgr.plugins[ 'plugin1' ] self.assertEqual( plugin.name, 'plugin1' ) self.assertEqual( plugin.path, os.path.join( expected_plugins_path, 'plugin1' ) ) self.assertIsInstance( plugin.module, types.ModuleType ) self.assertEqual( plugin.module.blah( 'one,two' ), [ 'one', 'two' ] ) mock_app_dir.remove()
def test_plugin_load( self ): """should attempt load if criteria met""" mock_app_dir = mock.MockDir({ 'plugins' : { 'plugin1' : { 'templates' : {}, 'static' : {} }, 'plugin2' : { 'static' : {} }, 'plugin3' : { 'templates' : {} }, 'not_a_plugin1' : 'blerbler', 'not_a_plugin2' : {}, } }) mock_app = mock.MockApp( 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.assertEqual( plugin_mgr.base_url, 'test' ) self.assertItemsEqual( plugin_mgr.directories, [ expected_plugins_path ] ) self.assertItemsEqual( plugin_mgr.plugins.keys(), [ 'plugin1', 'plugin2', 'plugin3' ] ) plugin1 = plugin_mgr.plugins[ 'plugin1' ] self.assertEqual( plugin1.name, 'plugin1' ) self.assertEqual( plugin1.path, os.path.join( expected_plugins_path, 'plugin1' ) ) self.assertEqual( plugin1.base_url, '/'.join([ plugin_mgr.base_url, plugin1.name ]) ) self.assertTrue( plugin1.serves_static ) self.assertEqual( plugin1.static_path, os.path.join( plugin1.path, 'static' ) ) self.assertEqual( plugin1.static_url, '/'.join([ plugin1.base_url, 'static' ]) ) self.assertTrue( plugin1.serves_templates ) self.assertEqual( plugin1.template_path, os.path.join( plugin1.path, 'templates' ) ) self.assertEqual( plugin1.template_lookup.__class__.__name__, 'TemplateLookup' ) plugin2 = plugin_mgr.plugins[ 'plugin2' ] self.assertEqual( plugin2.name, 'plugin2' ) self.assertEqual( plugin2.path, os.path.join( expected_plugins_path, 'plugin2' ) ) self.assertEqual( plugin2.base_url, '/'.join([ plugin_mgr.base_url, plugin2.name ]) ) self.assertTrue( plugin2.serves_static ) self.assertEqual( plugin2.static_path, os.path.join( plugin2.path, 'static' ) ) self.assertEqual( plugin2.static_url, '/'.join([ plugin2.base_url, 'static' ]) ) self.assertFalse( plugin2.serves_templates ) plugin3 = plugin_mgr.plugins[ 'plugin3' ] self.assertEqual( plugin3.name, 'plugin3' ) self.assertEqual( plugin3.path, os.path.join( expected_plugins_path, 'plugin3' ) ) self.assertEqual( plugin3.base_url, '/'.join([ plugin_mgr.base_url, plugin3.name ]) ) self.assertFalse( plugin3.serves_static ) self.assertTrue( plugin3.serves_templates ) self.assertEqual( plugin1.template_path, os.path.join( plugin1.path, 'templates' ) ) self.assertEqual( plugin1.template_lookup.__class__.__name__, 'TemplateLookup' ) mock_app_dir.remove()
def test_bad_import( self ): """should error gracefully (skip) on bad import""" mock_app_dir = mock.MockDir({ 'plugins' : { 'plugin1' : { loading_point : contents2 } } }) mock_app = mock.MockApp( mock_app_dir.root_path ) plugin_mgr = HookPluginManager( mock_app, directories_setting='plugins' ) app_path = mock_app_dir.root_path expected_plugins_path = os.path.join( app_path, 'plugins' ) self.assertItemsEqual( plugin_mgr.directories, [ expected_plugins_path ] ) self.assertEqual( plugin_mgr.plugins.keys(), [] ) mock_app_dir.remove()
def test_bad_loading_points( self ): """should NOT attempt load on dirs NOT containing loading_point file""" mock_app_dir = mock.MockDir({ 'plugins' : { 'plugin1' : {}, 'plugin2' : { 'plogin.py' : 'wot' } } }) mock_app = mock.MockApp( mock_app_dir.root_path ) plugin_mgr = HookPluginManager( mock_app, directories_setting='plugins' ) app_path = mock_app_dir.root_path expected_plugins_path = os.path.join( app_path, 'plugins' ) self.assertItemsEqual( plugin_mgr.directories, [ expected_plugins_path ] ) self.assertEqual( plugin_mgr.plugins.keys(), [] ) mock_app_dir.remove()
def test_plugin_static_map( self ): """""" mock_app_dir = mock.MockDir({ 'plugins' : { 'plugin1' : { 'templates' : {}, 'static' : {} } } }) mock_app = mock.MockApp( 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 )] ) mock_app_dir.remove()
def test_multiple_dirs(self): """should search in multiple directories""" mock_app_dir = mock.MockDir( {'plugins': { 'plugin1': {}, 'plugin2': {}, 'file1': 'blerbler' }}) mock_abs_plugin_dir = 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]) plugin_mgr = PluginManager(mock_app, directories_setting=directories_setting) app_path = mock_app_dir.root_path expected_plugins_rel_path = os.path.join(app_path, 'plugins') expected_plugins_abs_path = mock_abs_plugin_dir.root_path self.assertItemsEqual( plugin_mgr.directories, [expected_plugins_rel_path, expected_plugins_abs_path]) self.assertItemsEqual(plugin_mgr.plugins.keys(), ['plugin1', 'plugin2', 'plugin3', 'plugin4']) self.assertEqual(plugin_mgr.plugins['plugin1'].name, 'plugin1') self.assertEqual(plugin_mgr.plugins['plugin1'].path, os.path.join(expected_plugins_rel_path, 'plugin1')) self.assertEqual(plugin_mgr.plugins['plugin2'].name, 'plugin2') self.assertEqual(plugin_mgr.plugins['plugin2'].path, os.path.join(expected_plugins_rel_path, 'plugin2')) self.assertEqual(plugin_mgr.plugins['plugin3'].name, 'plugin3') self.assertEqual(plugin_mgr.plugins['plugin3'].path, os.path.join(expected_plugins_abs_path, 'plugin3')) self.assertEqual(plugin_mgr.plugins['plugin4'].name, 'plugin4') self.assertEqual(plugin_mgr.plugins['plugin4'].path, os.path.join(expected_plugins_abs_path, 'plugin4'))
def test_plugin_templates( self ): """""" mock_app_dir = mock.MockDir({ 'plugins' : { 'plugin1' : { 'templates' : { 'test.mako' : contents1 }, } } }) mock_app = mock.MockApp( 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', what='Hey', you='Ho', say='HeyHey HoHo' ) self.assertEqual( rendered, 'Hey Ho HeyHey HoHo' ) mock_app_dir.remove()