Ejemplo n.º 1
0
    def test_handler_activation_lifecycle(self):
        def handler(activation):
            pass

        flow_task = self.init_node(flow.Handler(handler))

        act = HandlerActivation()
        act.initialize(flow_task, TaskStub())

        # execute
        act.perform()
        self.assertEqual(act.task.status, STATUS.DONE)

        # undo
        act.undo()
        self.assertEqual(act.task.status, STATUS.NEW)
        act.cancel()
        self.assertEqual(act.task.status, STATUS.CANCELED)
Ejemplo n.º 2
0
    def test_handler_from_flow_method(self):
        class Flow(FlowStub):
            handler_task = flow.Handler(this.task_handler)
            method_called = False

            def task_handler(self, activation):
                Flow.method_called = True

        Flow.instance = Flow()
        flow_task = self.init_node(Flow.handler_task, flow_cls=Flow, name='task')

        act = HandlerActivation()
        act.initialize(flow_task, TaskStub())

        # execute
        act.perform()
        self.assertEqual(act.task.status, STATUS.DONE)
        self.assertEqual(act.task.status, STATUS.DONE)
        self.assertTrue(Flow.method_called)
Ejemplo n.º 3
0
    def test_handler_activation_lifecycle(self):
        def handler(activation):
            pass

        flow_task = self.init_node(flow.Handler(handler))

        act = HandlerActivation()
        act.initialize(flow_task, TaskStub())

        # execute
        act.perform()
        self.assertEqual(act.task.status, STATUS.DONE)

        # undo
        act.undo()
        self.assertEqual(act.task.status, STATUS.NEW)
        act.cancel()
        self.assertEqual(act.task.status, STATUS.CANCELED)
Ejemplo n.º 4
0
    def test_handler_from_flow_method(self):
        class Flow(FlowStub):
            handler_task = flow.Handler(this.task_handler)
            method_called = False

            def task_handler(self, activation):
                Flow.method_called = True

        Flow.instance = Flow()
        flow_task = self.init_node(Flow.handler_task,
                                   flow_class=Flow,
                                   name='task')

        act = HandlerActivation()
        act.initialize(flow_task, TaskStub())

        # execute
        act.perform()
        self.assertEqual(act.task.status, STATUS.DONE)
        self.assertEqual(act.task.status, STATUS.DONE)
        self.assertTrue(Flow.method_called)
Ejemplo n.º 5
0
    def test_handler_activation_error_lifecycle(self):
        def handler(activation):
            raise ValueError('expected')

        flow_task = self.init_node(flow.Handler(handler))

        act = HandlerActivation()
        act.initialize(flow_task, TaskStub())

        # by default errors are propogated
        self.assertRaises(ValueError, act.perform)

        # disable gate error propagation
        with Context(propagate_exception=False):
            act.perform()
            self.assertEqual(act.task.status, STATUS.ERROR)

            act.retry()
            self.assertEqual(act.task.status, STATUS.ERROR)

        # undo
        act.undo()
        self.assertEqual(act.task.status, STATUS.NEW)
        act.cancel()
        self.assertEqual(act.task.status, STATUS.CANCELED)
Ejemplo n.º 6
0
    def test_handler_activation_error_lifecycle(self):
        def handler(activation):
            raise ValueError('expected')

        flow_task = self.init_node(flow.Handler(handler))

        act = HandlerActivation()
        act.initialize(flow_task, TaskStub())

        # by default errors are propogated
        self.assertRaises(ValueError, act.perform)

        # disable gate error propogation
        with Context(propagate_exception=False):
            act.perform()
            self.assertEqual(act.task.status, STATUS.ERROR)

            act.retry()
            self.assertEqual(act.task.status, STATUS.ERROR)

        # undo
        act.undo()
        self.assertEqual(act.task.status, STATUS.NEW)
        act.cancel()
        self.assertEqual(act.task.status, STATUS.CANCELED)