Exemplo n.º 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))
Exemplo n.º 2
0
    def test_upgrade_show_applied_cmd(self):
        """ Test `upgrade show applied` command. """
        from invenio_upgrader.manage import main
        out = run_py_func(main, 'upgrader show applied').out

        expected = '>>> Following upgrade(s) have been applied:'
        self.assertTrue(expected in out.split('\n'),
                        "%s was not found in output %s" % (expected, out))
Exemplo n.º 3
0
    def test_upgrade_show_pending_cmd(self):
        """ Test `upgrade show pending` command. """
        from invenio_upgrader.manage import main
        out = run_py_func(main, 'upgrader show pending').out

        lines = out.split('\n')
        expected = ('>>> Following upgrade(s) are ready to be applied:',
                    '>>> All upgrades have been applied.')
        self.assertTrue(expected[0] in lines or expected[1] in lines,
                        "%s was not found in output %s" % (expected, lines))
Exemplo n.º 4
0
def cli_cmd_reset(sender, yes_i_know=False, drop=True, **kwargs):
    """Reset legacy values."""
    cmds = []
    if 'invenio_access' in current_app.config['PACKAGES']:
        from invenio_access.scripts.webaccessadmin import main as \
            webaccessadmin
        cmds.append(
            (webaccessadmin, "webaccessadmin -u admin -c -a -D")
        )

    for cmd in cmds:
        if run_py_func(*cmd, passthrough=True).exit_code:
            print("ERROR: failed execution of", *cmd)
            sys.exit(1)
Exemplo n.º 5
0
def cli_cmd_reset(sender, yes_i_know=False, drop=True, **kwargs):
    """Reset legacy values."""
    cmds = []
    if 'invenio_access' in current_app.config['PACKAGES']:
        from invenio_access.scripts.webaccessadmin import main as \
            webaccessadmin
        cmds.append(
            (webaccessadmin, "webaccessadmin -u admin -c -a -D")
        )

    for cmd in cmds:
        if run_py_func(*cmd, passthrough=True).exit_code:
            print("ERROR: failed execution of", *cmd)
            sys.exit(1)