Esempio n. 1
0
def test_single_action():
    """Test a single action is executed."""

    action = TaskAction(
        'increment_call_count',
        name='action1'
    )

    partial = action.prepare(42, build_context=BuildContext())
    partial.delay().get()

    assert increment_call_count.call_count == 1
Esempio n. 2
0
def test_action_with_single_default_pre_hook():
    """Test executing an action having a pre hook."""
    hook = ActionHook(
        'increment_call_count',
    )
    action = TaskAction(
        'increment_call_count',
        name='action1',
        hooks=[hook]
    )

    partial = action.prepare(42, build_context=BuildContext())
    partial.delay().get()

    assert increment_call_count.call_count == 2
Esempio n. 3
0
    def test_simple_action_from_dict(self):
        """Test that TaskAction.from_dict() with a simple action."""
        @action(called=False, name='test_task_simple')
        def test_simple(self, source):
            self.called = True
            return 42

        dct = {
            "name": "some_action",
            "task": "test_task_simple",
        }
        task_action = TaskAction(dct['task'], name=dct['name'])
        partial = task_action.prepare(None, BuildContext())
        ret = partial.delay().get()

        assert task_action.task.called
        assert ret.results['some_action'] == 42
Esempio n. 4
0
def test_action_with_single_default_error_hook():
    """Test executing an action having an error hook."""
    hook = ActionHook(
        'increment_call_count',
        event='error'
    )
    action = TaskAction(
        'err',
        hooks=[hook]
    )

    partial = action.prepare(42, build_context=BuildContext())

    with pytest.raises(ValueError):
        partial.delay().get()

    assert increment_call_count.call_count == 1
Esempio n. 5
0
    def test_callback_action_from_dict(self):
        """Test that TaskAction.from_dict() with a simple action.
        TESTING NOTES: here we are capturing passed args as instance vars,
        so we can make assertions about the behaviro after the fact.
        """
        @action(called=False, verify_kwargs={})
        def test_task_false(self, source, some_attribute=None):
            self.called = True
            self.verify_kwargs['some_attribute'] = some_attribute
            return False

        @action(called=False)
        def test_task_errback(self, source):
            self.called = True
            return 'BLAH'

        @action(called=False)
        def test_task_callback(self, source):
            self.called = True


        task_action = TaskAction('test_task_false', some_attribute=42)

        source = 12345
        partial = task_action.prepare(source, BuildContext())
        ret = partial.delay().get()

        # assert that action was called properly
        assert 'some_attribute' in task_action.task.verify_kwargs
        assert task_action.task.verify_kwargs['some_attribute'] == 42

        # assert that action was called properly;
        # it should not have a parent, and the source should
        # be set.
        assert task_action.task.called

        # assert that the initial action's return value was preserved
        # (i.e. the failure handler's return value is not used)
        assert isinstance(ret, BuildContext)
Esempio n. 6
0
def test_action_with_multiple_default_post_hooks():
    """Test executing an action having a post hook."""
    hooks = [
        ActionHook(
            'increment_call_count',
        ),
        ActionHook(
            'increment_call_count',
        ),
        ActionHook(
            'increment_call_count',
        )
    ]
    action = TaskAction(
        'increment_call_count',
        name='action1',
        hooks=hooks
    )

    partial = action.prepare(42, build_context=BuildContext())
    partial.delay().get()

    assert increment_call_count.call_count == 4