Пример #1
0
def test_hooked_configure_invalid_posthooks():
    hooks_config = {POSTHOOK: 'echo "prehook"'}
    from plumber.core import Hooked
    hooks = Hooked()
    try:
        hooks.configure(hooks_config)
    except Exception as e:
        assert type(e) is ConfigError
Пример #2
0
def test_hooked_run_prehooks():
    from plumber.core import Hooked
    hooks = Hooked()
    hooks.configure(HOOKS_CONFIG)
    hooks.run_prehooks()
    for executor in hooks.prehooks:
        assert len(executor.results) == 1
        assert executor.results[0][RETURN_CODE] == 0
        assert executor.results[0][STDOUT].decode(UTF8) == 'prehook\n'
        assert executor.results[0][STDERR].decode(UTF8) == ''
        assert executor.results[0][STEP] == 'echo "prehook"'
Пример #3
0
def test_hooked_run_posthooks_failure():
    from plumber.core import Hooked
    hooks = Hooked()
    hooks.configure(HOOKS_CONFIG)
    hooks.run_posthooks(FAILURE)
    for executor in hooks.posthooks:
        assert len(executor.results) == 1
        assert executor.results[0][RETURN_CODE] == 0
        assert executor.results[0][STDOUT].decode(UTF8) == 'posthook\n'
        assert executor.results[0][STDERR].decode(UTF8) == ''
        assert executor.results[0][STEP] == 'echo "posthook"'
    for executor in hooks.posthooks_failure:
        assert len(executor.results) == 1
        assert executor.results[0][RETURN_CODE] == 0
        assert executor.results[0][STDOUT].decode(UTF8) == 'posthook-failure\n'
        assert executor.results[0][STDERR].decode(UTF8) == ''
        assert executor.results[0][STEP] == 'echo "posthook-failure"'
    for executor in hooks.posthooks_success:
        assert len(executor.results) == 0
Пример #4
0
def test_hooked_wrap_in_hooks_failure():
    from plumber.core import Hooked
    hooks = Hooked()
    hooks.configure(HOOKS_CONFIG)

    def check_prehook_called():
        for executor in hooks.prehooks:
            assert len(executor.results) == 1
            assert executor.results[0][RETURN_CODE] == 0
            assert executor.results[0][STDOUT].decode(UTF8) == 'prehook\n'
            assert executor.results[0][STDERR].decode(UTF8) == ''
            assert executor.results[0][STEP] == 'echo "prehook"'
        for executor in hooks.posthooks:
            assert len(executor.results) == 0
        for executor in hooks.posthooks_success:
            assert len(executor.results) == 0
        for executor in hooks.posthooks_failure:
            assert len(executor.results) == 0
        raise ExecutionFailure('Just to test')

    def check_posthook_called(status):
        assert status == FAILURE
        for executor in hooks.posthooks:
            assert len(executor.results) == 1
            assert executor.results[0][RETURN_CODE] == 0
            assert executor.results[0][STDOUT].decode(UTF8) == 'posthook\n'
            assert executor.results[0][STDERR].decode(UTF8) == ''
            assert executor.results[0][STEP] == 'echo "posthook"'
        for executor in hooks.posthooks_failure:
            assert len(executor.results) == 1
            assert executor.results[0][RETURN_CODE] == 0
            assert executor.results[0][STDOUT].decode(
                UTF8) == 'posthook-failure\n'
            assert executor.results[0][STDERR].decode(UTF8) == ''
            assert executor.results[0][STEP] == 'echo "posthook-failure"'
        for executor in hooks.posthooks_success:
            assert len(executor.results) == 0

    try:
        hooks.wrap_in_hooks(check_prehook_called, check_posthook_called)()
    except Exception as e:
        assert type(e) is ExecutionFailure
Пример #5
0
def test_hooked_configure():
    from plumber.core import Hooked, Executor
    hooks = Hooked()
    hooks.configure(HOOKS_CONFIG)
    assert hooks.prehooks is not None
    assert len(hooks.prehooks) == 1
    assert type(hooks.prehooks[0]) is Executor
    assert hooks.prehooks[0].steps[0] == 'echo "prehook"'
    assert hooks.posthooks is not None
    assert len(hooks.posthooks) == 1
    assert type(hooks.posthooks[0]) is Executor
    assert hooks.posthooks[0].steps[0] == 'echo "posthook"'
    assert hooks.posthooks_success is not None
    assert len(hooks.posthooks_success) == 1
    assert type(hooks.posthooks_success[0]) is Executor
    assert hooks.posthooks_success[0].steps[0] == 'echo "posthook-success"'
    assert hooks.posthooks_failure is not None
    assert len(hooks.posthooks_failure) == 1
    assert type(hooks.posthooks_failure[0]) is Executor
    assert hooks.posthooks_failure[0].steps[0] == 'echo "posthook-failure"'
Пример #6
0
def test_hooked_wrap_in_hooks_success():
    from plumber.core import Hooked
    hooks = Hooked()
    hooks.configure(HOOKS_CONFIG)

    def check_prehook_called():
        for executor in hooks.prehooks:
            assert len(executor.results) == 1
            assert executor.results[0][RETURN_CODE] == 0
            assert executor.results[0][STDOUT].decode(UTF8) == 'prehook\n'
            assert executor.results[0][STDERR].decode(UTF8) == ''
            assert executor.results[0][STEP] == 'echo "prehook"'
        for executor in hooks.posthooks:
            assert len(executor.results) == 0
        for executor in hooks.posthooks_success:
            assert len(executor.results) == 0
        for executor in hooks.posthooks_failure:
            assert len(executor.results) == 0
        return 'success'

    def check_posthook_called(status):
        assert status == SUCCESS
        for executor in hooks.posthooks:
            assert len(executor.results) == 1
            assert executor.results[0][RETURN_CODE] == 0
            assert executor.results[0][STDOUT].decode(UTF8) == 'posthook\n'
            assert executor.results[0][STDERR].decode(UTF8) == ''
            assert executor.results[0][STEP] == 'echo "posthook"'
        for executor in hooks.posthooks_success:
            assert len(executor.results) == 1
            assert executor.results[0][RETURN_CODE] == 0
            assert executor.results[0][STDOUT].decode(
                UTF8) == 'posthook-success\n'
            assert executor.results[0][STDERR].decode(UTF8) == ''
            assert executor.results[0][STEP] == 'echo "posthook-success"'
        for executor in hooks.posthooks_failure:
            assert len(executor.results) == 0

    assert hooks.wrap_in_hooks(check_prehook_called,
                               check_posthook_called)() == 'success'