def test_callback_action_from_dict_with_children(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_with_children(self, some_attribute=None): self.called = True self.verify_kwargs['some_attribute'] = some_attribute @action(called=False) def test_task_errback_with_children(self): self.called = True @action(called=False) def test_task_callback_with_children(self): self.called = True dct = { "task": "test_task_false_with_children", "kwargs": { 'some_attribute': 42, }, "children": [ { "task": "test_task_errback_with_children", "predicate": "not parent" }, { "task": "test_task_callback_with_children", } ] } task_action = TaskAction.from_dict(dct) source = 12345 task_action.prepare(BuildContext(source)) ret = task_action.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 failure handler was called assert task_action.children[0][0].task.called # assert that the success handler was not called assert not task_action.children[1][0].task.called # assert that the initial action's return value was preserved # (i.e. the failure handler's return value is not used) assert not ret.last
def test_prepare(): @action(name='task_test_prepare', called=False) def task_test_prepare(self, context, some_arg=None): """Task returns what was passed in positional arg 1""" self.called = True return some_arg dct = { "name": "task_test_from_dict_action", "task": "task_test_prepare", } task_action = TaskAction.from_dict(dct) assert not task_action.partial task_action.prepare(build_context=None) assert task_action.partial assert not task_test_prepare.called ret = task_action.delay(some_arg=42).get() assert task_test_prepare.called assert ret == 42