Ejemplo n.º 1
0
    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')
Ejemplo n.º 2
0
    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), )))
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
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"]