def test_create(self): # Creating the Plugin, setting its version to None and then creating it # again should just change the plugin_version to 0 foo = InstalledPlugin.create(self.store, u'foo') foo.plugin_version = None foo = InstalledPlugin.create(self.store, u'foo') self.assertEqual(foo.plugin_version, 0) self.assertRaises(PluginError, InstalledPlugin.create, self.store, u'foo')
def test_create(self): # Creating the Plugin, setting its version to None and then creating it # again should just change the plugin_version to 0 foo = InstalledPlugin.create(self.store, u'foo') foo.plugin_version = None foo = InstalledPlugin.create(self.store, u'foo') self.assertEquals(foo.plugin_version, 0) self.assertRaises(PluginError, InstalledPlugin.create, self.store, u'foo')
def install_plugin(self, store, plugin_name): """Install and enable a plugin @important: Calling this makes a plugin installed, but, it's your responsability to activate it! :param plugin: the :class:`IPlugin` implementation of the plugin """ # Try to get the plugin first. If it was't registered yet, # PluginError will be raised. plugin = self.get_plugin(plugin_name) if plugin_name in self.installed_plugins_names: raise PluginError("Plugin %s is already enabled." % (plugin_name, )) dependencies = self._plugin_descriptions[plugin_name].dependencies for dependency in dependencies: if not self.is_installed(dependency): self.install_plugin(store, dependency) InstalledPlugin.create(store, plugin_name) # FIXME: We should not be doing this commit here, but by not doing so, # ``` # migration = plugin.get_migration() # ``` # Would not find any plugin (as it uses the default store), to allow # `plugin.get_migration()` to accept a custom store, we would have to # change all the plugins `get_migration` method. # # An alternate solution to this would be to manually set the correct # plugin for `migration`: # # migration._plugin = store.find(InstalledPlugin, # plugin_name=plugin_name).one() # # Along with passing the store to `migration.apply_all_patches()` # # But it will be dirty and will probably be removed once the definitive # solution (change `plugin.get_migration()`) is implemented store.commit(close=False) migration = plugin.get_migration() if migration: try: migration.apply_all_patches() except SQLError as e: # This means a lock could not be obtained. Warn user about this # and let stoq restart, that the schema will be upgraded # correctly error('Não foi possível terminar a instalação do plugin. ' 'Por favor reinicie todas as instancias do Stoq que ' 'estiver executando (%s)' % (e, ))
def install_plugin(self, plugin_name): """Install and enable a plugin @important: Calling this makes a plugin installed, but, it's your responsability to activate it! :param plugin: the :class:`IPlugin` implementation of the plugin """ # Try to get the plugin first. If it was't registered yet, # PluginError will be raised. plugin = self.get_plugin(plugin_name) if plugin_name in self.installed_plugins_names: raise PluginError("Plugin %s is already enabled." % (plugin_name, )) store = new_store() InstalledPlugin(store=store, plugin_name=plugin_name, plugin_version=0) store.commit(close=True) migration = plugin.get_migration() if migration: try: migration.apply_all_patches() except SQLError: # This means a lock could not be obtained. Warn user about this # and let stoq restart, that the schema will be upgraded # correctly error('Não foi possível terminar a instalação do plugin. ' 'Por favor reinicie todas as instancias do Stoq que ' 'estiver executando')
def setUp(self): super(TestPluginManager, self).setUp() # Generate 2 instances of plugins that will be used for testing later. # '_dependent_plugin' will require 'independent_plugin' activation prior # to it's own. self._independent_plugin = _TestPlugin() self._dependent_plugin = _TestDependentPlugin() # Since the plugins are commited inside pluginmanager, try to remove # it first, or we will have problems if STOQLIB_TEST_QUICK is set. store = new_store() plugins = set(InstalledPlugin.get_plugin_names(store=self.store)) expected = set([u'ecf', u'nfe', u'optical']) self.assertTrue(expected.issubset(plugins)) ind_name = self._independent_plugin.name dep_name = self._dependent_plugin.name plugin_names = [ind_name, dep_name] test_plugins = store.find(InstalledPlugin, InstalledPlugin.plugin_name.is_in(plugin_names)) for plugin in test_plugins: store.remove(plugin) store.commit() store.close() self._manager = get_plugin_manager() self._register_test_plugin()
def test(self, get_default_store): # FIXME: get_table_types need plugins to be installed to get the # plugin's tables. PluginManager.installed_plugins_names will use the # default store to get the installed plugins, so mock it to the tests' # store, create all the missing InstalledPlugin. Change this to a mock # on installed_plugins_names when we can use newer versions of # python-mock (which suports properly property mocking) get_default_store.return_value = self.store for p_name in self.get_oficial_plugins_names(): if self.store.find(InstalledPlugin, plugin_name=p_name).is_empty(): InstalledPlugin(store=self.store, plugin_name=p_name, plugin_version=1) # Depending on the order this test is runned, the cache will be # already filled. Clear it so it imports again and get plugins too _tables_cache.clear() expected = set(t.__name__ for t in get_table_types()) introspected = set(t.__name__ for t in _introspect_tables()) # Tables in either expected or introspected but not both difference = expected ^ introspected if difference: self.fail("Missing tables: %s\n" "Please add them to stoqlib.database.tables or to the " "plugin's get_tables" % (', '.join(sorted(difference), )))
def pre_install_plugin(self, store, plugin_name): """Pre Install Plugin Registers an intention to activate a plugin, that will require further actions to enable when running stoq later, like downloading the plugin from stoq.link. """ if plugin_name in self.installed_plugins_names: raise PluginError("Plugin %s is already enabled." % (plugin_name, )) InstalledPlugin(store=store, plugin_name=plugin_name, plugin_version=None)
def setUp(self): super(TestPluginManager, self).setUp() # Since the plugins are commited inside pluginmanager, try to remove # it first, or we will have problems if STOQLIB_TEST_QUICK is set. store = new_store() plugins = set(InstalledPlugin.get_plugin_names(store=self.store)) expected = set([u'ecf', u'nfe', u'optical']) self.assertTrue(expected.issubset(plugins)) test_plugin = store.find(InstalledPlugin, plugin_name=_TestPlugin.name).one() if test_plugin: store.remove(test_plugin) store.commit() store.close() self._manager = get_plugin_manager() self._register_test_plugin()
def get_installed_plugins_names(self, store=None): """A list of names of all installed plugins""" return InstalledPlugin.get_plugin_names(store or get_default_store())
def test_plugin_get_pre_plugin_nammes(store): assert InstalledPlugin.get_pre_plugin_names(store) == [] InstalledPlugin(store=store, plugin_name="teste") assert InstalledPlugin.get_pre_plugin_names(store) == ["teste"]