def setup(self, test_app): self.test_app = test_app self.db = mg_globals.database self.pman = pluginapi.PluginManager() self.user_password = u'4cc355_70k3N' self.user = fixture_add_user(u'joauth', self.user_password) self.login()
def test_no_plugins(): """Run setup_plugins with no plugins in config""" cfg = build_config([('mediagoblin', {}, [])]) mg_globals.app_config = cfg['mediagoblin'] mg_globals.global_config = cfg pman = pluginapi.PluginManager() setup_plugins() # Make sure we didn't load anything. assert len(pman.plugins) == 0
def test_disabled_plugin(): """Run setup_plugins with a single working plugin twice""" cfg = build_config([('mediagoblin', {}, []), ('plugins', {}, [ ('-mediagoblin.plugins.sampleplugin', {}, []), ])]) mg_globals.app_config = cfg['mediagoblin'] mg_globals.global_config = cfg pman = pluginapi.PluginManager() setup_plugins() # Make sure we didn't load the plugin assert len(pman.plugins) == 0
def test_one_plugin(): """Run setup_plugins with a single working plugin""" cfg = build_config([('mediagoblin', {}, []), ('plugins', {}, [('mediagoblin.plugins.sampleplugin', {}, [])])]) mg_globals.app_config = cfg['mediagoblin'] mg_globals.global_config = cfg pman = pluginapi.PluginManager() setup_plugins() # Make sure we only found one plugin assert len(pman.plugins) == 1 # Make sure the plugin is the one we think it is. assert pman.plugins[0] == 'mediagoblin.plugins.sampleplugin' # Make sure there was one hook registered assert len(pman.hooks) == 1 # Make sure _setup_plugin_called was called once import mediagoblin.plugins.sampleplugin assert mediagoblin.plugins.sampleplugin._setup_plugin_called == 1
def setup_plugins(): """This loads, configures and registers plugins See plugin documentation for more details. """ global_config = mg_globals.global_config plugin_section = global_config.get('plugins', {}) if not plugin_section: _log.info("No plugins to load") return pman = pluginapi.PluginManager() # Go through and import all the modules that are subsections of # the [plugins] section and read in the hooks. for plugin_module, config in plugin_section.items(): # Skip any modules that start with -. This makes it easier for # someone to tweak their configuration so as to not load a # plugin without having to remove swaths of plugin # configuration. if plugin_module.startswith('-'): continue _log.info("Importing plugin module: %s" % plugin_module) pman.register_plugin(plugin_module) # If this throws errors, that's ok--it'll halt mediagoblin # startup. __import__(plugin_module) plugin = sys.modules[plugin_module] if hasattr(plugin, 'hooks'): pman.register_hooks(plugin.hooks) # Execute anything registered to the setup hook. pluginapi.hook_runall('setup')