Пример #1
0
    def test_signals_usage(self):
        """ Test signal handling. """
        from invenio_base.scripts.database import main as db_main
        from invenio_base.signals import pre_command, post_command
        from invenio_base.manage import main, version as im_version

        def pre_handler_version(sender, *args, **kwargs):
            print('>>> pre_handler_version')

        def post_handler_version(sender, *args, **kwargs):
            print('>>> post_handler_version')

        # Bind only `inveniomanage version` command to pre/post handler.
        pre_command.connect(pre_handler_version, sender=im_version)
        post_command.connect(post_handler_version, sender=im_version)

        def pre_handler_general_test(sender, *args, **kwargs):
            print('>>> pre_handler_general')

        def post_handler_general_test(sender, *args, **kwargs):
            print('>>> post_handler_general')

        # Bind all commands to pre/post general handler.
        pre_command.connect(pre_handler_general_test)
        pre_command.connect(post_handler_general_test)

        # Expect both version and general handlers.
        out = run_py_func(main, 'inveniomanage version').out

        lines = out.split('\n')
        expected = ('>>> pre_handler_version',
                    '>>> post_handler_version',
                    '>>> pre_handler_general',
                    '>>> post_handler_general')
        for line in expected:
            self.assertTrue(line in lines,
                            "%s was not found in output %s" % (line, lines))

        # Expect only general handlers.
        out = run_py_func(db_main, 'database uri').out

        lines = out.split('\n')
        expected = ('>>> pre_handler_general',
                    '>>> post_handler_general')
        for line in expected:
            self.assertTrue(line in lines,
                            "%s was not found in output %s" % (line, lines))

        notexpected = ('>>> pre_handler_version',
                       '>>> post_handler_version')
        for line in notexpected:
            self.assertFalse(line in lines,
                             "%s was not expected in output %s" % (line, lines))
Пример #2
0
        command.__class__ = SignalingCommand
        return super(Manager, self).add_command(name, command)


def set_serve_static_files(sender, *args, **kwargs):
    """Enable serving of static files for `runserver` command.

    Normally Apache serves static files, but during development and if you are
    using the Werkzeug standalone development server, you can set this flag to
    `True`, to enable static file serving.
    """
    current_app.config.setdefault('CFG_FLASK_SERVE_STATIC_FILES', True)


pre_command.connect(set_serve_static_files, sender=Server)


def create_ssl_context(config):
    """Create :class:`ssl.SSLContext` from application config.

    :param config: Dict-like application configuration.
    :returns: A valid context or in case TLS is not enabled `None`.

    The following configuration variables are processed:

    ============================ ==============================================
    `SERVER_TLS_ENABLE`          If `True`, a SSL context will be created. In
                                 this case, the required configuration
                                 variables must be provided.
    `SERVER_TLS_KEY` (required)  Filepath (string) of private key provided as
Пример #3
0
                return res

        command.__class__ = SignalingCommand
        return super(Manager, self).add_command(name, command)


def set_serve_static_files(sender, *args, **kwargs):
    """Enable serving of static files for `runserver` command.

    Normally Apache serves static files, but during development and if you are
    using the Werkzeug standalone development server, you can set this flag to
    `True`, to enable static file serving.
    """
    current_app.config.setdefault('CFG_FLASK_SERVE_STATIC_FILES', True)

pre_command.connect(set_serve_static_files, sender=Server)


def create_ssl_context(config):
    """Create :class:`ssl.SSLContext` from application config.

    :param config: Dict-like application configuration.
    :returns: A valid context or in case TLS is not enabled `None`.

    The following configuration variables are processed:

    ============================ ==============================================
    `SERVER_TLS_ENABLE`          If `True`, a SSL context will be created. In
                                 this case, the required configuration
                                 variables must be provided.
    `SERVER_TLS_KEY` (required)  Filepath (string) of private key provided as