Пример #1
0
def test_pipe_evaluate_missing_conditions():
    PIPE_CONFIG = {ID: 'test-pipe', ACTIONS: {STEPS: []}}
    from plumber.core import PlumberPipe
    pipe = PlumberPipe()
    pipe.configure(PIPE_CONFIG, None)
    assert pipe.conditions is None
    assert pipe.evaluate() is True
Пример #2
0
def test_pipe_evaluate_false():
    PIPE_CONFIG = {
        ID: 'test-pipe',
        CONDITIONS: [{
            ID: '1'
        }, {
            ID: '2'
        }],
        ACTIONS: {
            STEPS: []
        }
    }
    from plumber.core import LocalDiffConditional
    LocalDiffConditional.configure = MagicMock()
    LocalDiffConditional.configure.return_value = None
    from plumber.core import PlumberPipe
    pipe = PlumberPipe()
    pipe.configure(PIPE_CONFIG, {})
    pipe.conditions[0][CONDITION].evaluate = MagicMock()
    pipe.conditions[0][CONDITION].evaluate.return_value = False
    pipe.conditions[1][CONDITION].evaluate = MagicMock()
    pipe.conditions[1][CONDITION].evaluate.return_value = False
    assert pipe.evaluate() is False
    pipe.conditions[0][CONDITION].evaluate.assert_called_once()
    pipe.conditions[1][CONDITION].evaluate.assert_called_once()
Пример #3
0
def test_pipe_configure_invalid_id():
    from plumber.core import PlumberPipe
    pipe = PlumberPipe()
    try:
        pipe.configure({ID: 123}, None)
    except Exception as e:
        assert type(e) is ConfigError
Пример #4
0
def test_pipe_configure():
    PIPE_CONFIG = {
        ID: 'test-pipe',
        CONDITIONS: [{
            ID: 'c1',
            TYPE: LOCALDIFF
        }, {
            ID: 'c2',
            TYPE: LOCALDIFF
        }],
        ACTIONS: {
            STEPS: []
        }
    }
    CHECKPOINT = {'test-pipe': {'c1': 'checkpoint', 'c2': 'checkpoint'}}
    from plumber.core import LocalDiffConditional
    LocalDiffConditional.configure = MagicMock()
    LocalDiffConditional.configure.return_value = None
    from plumber.core import PlumberPipe
    pipe = PlumberPipe()
    pipe.configure(PIPE_CONFIG, CHECKPOINT)
    LocalDiffConditional.configure.assert_called()
    assert len(pipe.conditions) == 2
    assert pipe.checkpoint is CHECKPOINT
    assert pipe.actions is not None
Пример #5
0
def test_pipe_get_new_checkpoint():
    PIPE_CONFIG = {
        ID: 'test-pipe',
        CONDITIONS: [{
            ID: 'c1',
            TYPE: LOCALDIFF
        }, {
            ID: 'c2',
            TYPE: LOCALDIFF
        }],
        ACTIONS: {
            STEPS: []
        }
    }
    CHECKPOINT = {'test-pipe': {'c1': 'checkpoint1', 'c2': 'checkpoint2'}}
    from plumber.core import LocalDiffConditional
    LocalDiffConditional.configure = MagicMock()
    LocalDiffConditional.configure.return_value = None
    from plumber.core import PlumberPipe
    pipe = PlumberPipe()
    pipe.configure(PIPE_CONFIG, CHECKPOINT)
    pipe.conditions[0][CONDITION].new_checkpoint = 'checkpoint1'
    pipe.conditions[1][CONDITION].new_checkpoint = 'checkpoint2'
    cp = pipe.get_new_checkpoint()
    assert cp['c1']['commit'] == 'checkpoint1'
    assert cp['c2']['commit'] == 'checkpoint2'
Пример #6
0
def test_pipe_configure_invalid_conditions():
    PIPE_CONFIG = {ID: 'test-pipe', CONDITIONS: [[], []], ACTIONS: {STEPS: []}}
    from plumber.core import PlumberPipe
    pipe = PlumberPipe()
    try:
        pipe.configure(PIPE_CONFIG, None)
    except Exception as e:
        assert type(e) is ConfigError
Пример #7
0
def test_pipe_configure_no_actions():
    PIPE_CONFIG = {ID: 'test-pipe', CONDITIONS: [{ID: '1'}, {ID: '2'}]}
    from plumber.core import LocalDiffConditional
    LocalDiffConditional.configure = MagicMock()
    LocalDiffConditional.configure.return_value = None
    from plumber.core import PlumberPipe
    pipe = PlumberPipe()
    try:
        pipe.configure(PIPE_CONFIG, {})
    except Exception as e:
        assert type(e) is ConfigError
Пример #8
0
def test_pipe_configure_invalid_conditions_id_duplicate():
    PIPE_CONFIG = {
        ID: 'test-pipe',
        CONDITIONS: [{
            ID: ID
        }, {
            ID: ID
        }],
        ACTIONS: {
            STEPS: []
        }
    }
    from plumber.core import LocalDiffConditional
    LocalDiffConditional.configure = MagicMock()
    LocalDiffConditional.configure.return_value = None
    from plumber.core import PlumberPipe
    pipe = PlumberPipe()
    try:
        pipe.configure(PIPE_CONFIG, {})
    except Exception as e:
        assert type(e) is ConfigError
Пример #9
0
def test_pipe_run_posthooks():
    PIPE_CONFIG = {
        ID: 'test-pipe',
        POSTHOOK: [{
            STEPS: ['echo "HELLO"']
        }],
        CONDITIONS: [{
            ID: 'c1',
            TYPE: LOCALDIFF
        }, {
            ID: 'c2',
            TYPE: LOCALDIFF
        }],
        ACTIONS: {
            STEPS: []
        }
    }
    from plumber.core import LocalDiffConditional
    LocalDiffConditional.configure = MagicMock()
    LocalDiffConditional.configure.return_value = None
    from plumber.core import PlumberPipe
    pipe = PlumberPipe()
    pipe.configure(PIPE_CONFIG, {})
    pipe.run_posthooks(None)
    assert len(pipe.posthooks) == 1
    assert len(pipe.posthooks[0].results) == 1
    assert pipe.posthooks[0].results[0][RETURN_CODE] == 0
    assert pipe.posthooks[0].results[0][STDOUT].decode(UTF8) == 'HELLO\n'
    assert pipe.posthooks[0].results[0][STDERR].decode(UTF8) == ''
    assert pipe.posthooks[0].results[0][STEP] == PIPE_CONFIG[POSTHOOK][0][
        STEPS][0]
Пример #10
0
def test_pipe_execute():
    PIPE_CONFIG = {
        ID: 'test-pipe',
        CONDITIONS: [],
        ACTIONS: {
            STEPS: ['echo "Hello"']
        }
    }
    from plumber.core import PlumberPipe
    pipe = PlumberPipe()
    pipe.configure(PIPE_CONFIG, {})
    pipe.execute()
    assert len(pipe.actions.results) == 1
    assert pipe.actions.results[0][RETURN_CODE] == 0
    assert pipe.actions.results[0][STDOUT].decode(UTF8) == 'Hello\n'
    assert pipe.actions.results[0][STDERR].decode(UTF8) == ''
    assert pipe.actions.results[0][STEP] == PIPE_CONFIG[ACTIONS][STEPS][0]
Пример #11
0
def test_pipe_configure_no_conditions():
    PIPE_CONFIG = {ID: 'test-pipe', CONDITIONS: [], ACTIONS: {STEPS: []}}
    from plumber.core import PlumberPipe
    pipe = PlumberPipe()
    pipe.configure(PIPE_CONFIG, None)
    assert len(pipe.conditions) == 0