Example #1
1
    def test(self):

        class FooTask(Task):

            @property
            def tag(self):
                return "foo_task1"

            def serialize(self, task_flow):
                task_flow.storage[self.id] = self

            def deserialize(self, task_flow):
                return self.storage[self.id]

        register_task_cls(FooTask)

        with patch.object(FooTask, "__call__") as mock_method1:
            with patch.object(FooTask, "on_approved") as mock_method2:
                with patch.object(FooTask, "after_executed") as mock_method3:
                    task_flow = new_task_flow(FooTask, annotation="foo task flow", a=1, b=2) 
                    task_flow.start()
                    mock_method1.assert_called_once_with() 
                    mock_method2.assert_called_once_with()
                    mock_method3.assert_called_once_with()
                    foo_task = task_flow.root_task.checkout()
                    assert foo_task.approved
                    assert task_flow.status == constants.TASK_FLOW_EXECUTED
                    assert not foo_task.failed
                    assert not task_flow.failed

        with patch.object(FooTask, "__call__") as mock_method1:
            with patch.object(FooTask, "on_approved") as mock_method2:
                with patch.object(FooTask, "after_executed") as mock_method3:
                    with patch.object(FooTask, "on_refused") as mock_method4:
                        task_flow = new_task_flow(FooTask, annotation='foo task flow', a=1, b=2)
                        foo_task = task_flow.root_task.checkout()
                        task_flow.refuse(foo_task)
                        assert mock_method1.call_count == 0
                        assert mock_method2.call_count == 0
                        assert mock_method3.call_count == 0
                        mock_method4.assert_called_once_with(True)
                        assert not task_flow.failed
                        assert not foo_task.failed

        task_flow = new_task_flow(FooTask, annotation='foo task flow')
        task_flow.start()
        foo_task = task_flow.root_task.checkout()
        raises(TaskAlreadyApproved, task_flow.approve, foo_task)
Example #2
0
    def test(self):
        class A(Task):
            @property
            def tag(self):
                return 'A'

            def __call__(self):
                raise RuntimeError()

            @property
            def dependencies(self):
                return [B(self.task_flow)]

        class B(Task):
            @property
            def tag(self):
                return 'B'

        task_flow = new_task_flow(A)
        try:
            task_flow.start()
        except TaskFlowDelayed:
            pass
        raises(RuntimeError, task_flow.approve, B(task_flow))

        assert task_flow.failed
        b_task = B(task_flow).checkout()
        assert not b_task.failed
        a_task = A(task_flow).checkout()
        assert a_task.failed
        assert task_flow.status == constants.TASK_FLOW_APPROVED

        raises(RuntimeError, task_flow.execute)
        assert task_flow.status == constants.TASK_FLOW_APPROVED

        assert task_flow.failed
        b_task = B(task_flow).checkout()
        assert not b_task.failed
        a_task = A(task_flow).checkout()
        assert a_task.failed

        class A_(Task):
            @property
            def tag(self):
                return 'A'

            @property
            def dependencies(self):
                return [B(self.task_flow)]

        task_flow = new_task_flow(A_)
        try:
            task_flow.start()
        except TaskFlowDelayed:
            pass

        task_flow.approve(B(task_flow))
        assert task_flow.status == constants.TASK_FLOW_EXECUTED
Example #3
0
    def test(self):
        class FooTask(Task):
            @property
            def tag(self):
                return "foo_task1"

            def serialize(self, task_flow):
                task_flow.storage[self.id] = self

            def deserialize(self, task_flow):
                return self.storage[self.id]

        register_task_cls(FooTask)

        with patch.object(FooTask, "__call__") as mock_method1:
            with patch.object(FooTask, "on_approved") as mock_method2:
                with patch.object(FooTask, "after_executed") as mock_method3:
                    task_flow = new_task_flow(FooTask,
                                              annotation="foo task flow",
                                              a=1,
                                              b=2)
                    task_flow.start()
                    mock_method1.assert_called_once_with()
                    mock_method2.assert_called_once_with()
                    mock_method3.assert_called_once_with()
                    foo_task = task_flow.root_task.checkout()
                    assert foo_task.approved
                    assert task_flow.status == constants.TASK_FLOW_EXECUTED
                    assert not foo_task.failed
                    assert not task_flow.failed

        with patch.object(FooTask, "__call__") as mock_method1:
            with patch.object(FooTask, "on_approved") as mock_method2:
                with patch.object(FooTask, "after_executed") as mock_method3:
                    with patch.object(FooTask, "on_refused") as mock_method4:
                        task_flow = new_task_flow(FooTask,
                                                  annotation='foo task flow',
                                                  a=1,
                                                  b=2)
                        foo_task = task_flow.root_task.checkout()
                        task_flow.refuse(foo_task)
                        assert mock_method1.call_count == 0
                        assert mock_method2.call_count == 0
                        assert mock_method3.call_count == 0
                        mock_method4.assert_called_once_with(True)
                        assert not task_flow.failed
                        assert not foo_task.failed

        task_flow = new_task_flow(FooTask, annotation='foo task flow')
        task_flow.start()
        foo_task = task_flow.root_task.checkout()
        raises(TaskAlreadyApproved, task_flow.approve, foo_task)
Example #4
0
def task():
    
    class _Form(Form):
        destination = TextField('destination', validators=[DataRequired()])
        contact = TextField('contact', validators=[DataRequired()])

    form = _Form()
    
    if form.validate_on_submit():
        task_flow = new_task_flow(Travel, annotation='travel application', 
                                  username=current_user.username, 
                                  destination=form.destination.data, 
                                  contact=form.contact.data)
        try:
            task_flow.start()
        except exceptions.TaskFlowDelayed:
            flash('You have just submitted an travel application')
            return redirect(url_for('task_list'))
    return render_template('/request.html', form=form)
Example #5
0
def task():
    class _Form(Form):
        destination = TextField('destination', validators=[DataRequired()])
        contact = TextField('contact', validators=[DataRequired()])

    form = _Form()

    if form.validate_on_submit():
        task_flow = new_task_flow(Travel,
                                  annotation='travel application',
                                  username=current_user.username,
                                  destination=form.destination.data,
                                  contact=form.contact.data)
        try:
            task_flow.start()
        except exceptions.TaskFlowDelayed:
            flash('You have just submitted an travel application')
            return redirect(url_for('task_list'))
    return render_template('/request.html', form=form)
Example #6
0
    def test(self):
        class A(Task):
            @property
            def tag(self):
                return self.extra_params['name']

            @property
            def dependencies(self):
                return [
                    B(self.task_flow, name="b"),
                    C(self.task_flow, name="c")
                ]

        register_task_cls(A)

        class B(Task):
            @property
            def tag(self):
                return self.extra_params['name']

        class C(Task):
            @property
            def tag(self):
                return self.extra_params['name']

            @property
            def dependencies(self):
                return [D(self.task_flow, name="d")]

        class D(Task):
            @property
            def tag(self):
                return self.extra_params['name']

        with patch.object(A, "__call__") as call_a:
            with patch.object(B, "__call__") as call_b:
                with patch.object(C, "__call__") as call_c:
                    with patch.object(D, "__call__") as call_d:
                        task_flow = new_task_flow(A,
                                                  annotation="foo task flow",
                                                  name='a')
                        e_info = raises(TaskFlowDelayed, task_flow.start)
                        a_task = task_flow.root_task.checkout()
                        assert a_task.approved
                        delayed_task = e_info.value.task
                        assert delayed_task.tag == 'b'
                        delayed_task.checkout()
                        assert not delayed_task.approved

                        e_info = raises(TaskFlowDelayed, task_flow.approve,
                                        delayed_task)
                        delayed_task.checkout()
                        assert delayed_task.approved
                        delayed_task = e_info.value.task
                        assert delayed_task.tag == 'c'
                        delayed_task.checkout()
                        assert not delayed_task.approved

                        e_info = raises(TaskFlowDelayed, task_flow.approve,
                                        delayed_task)
                        delayed_task.checkout()
                        assert delayed_task.approved
                        delayed_task = e_info.value.task
                        assert delayed_task.tag == 'd'
                        delayed_task.checkout()
                        assert not delayed_task.approved

                        task_flow.approve(delayed_task)
                        call_a.assert_called_once_with()
                        call_b.assert_called_once_with()
                        call_c.assert_called_once_with()
                        call_d.assert_called_once_with()

                        assert not delayed_task.failed
                        assert not task_flow.failed

        ## test refused
        with patch.object(B, "on_refused") as mock_method:
            task_flow = new_task_flow(A, annotation="foo task flow", name='a')
            try:
                task_flow.start()
            except TaskFlowDelayed, e:
                delayed_task = e.task
                pass
            task_flow.refuse(delayed_task)
            task_flow = get_task_flow(task_flow.id_)
            assert task_flow.status == constants.TASK_FLOW_REFUSED
            mock_method.assert_called_once_with(True)
            raises(TaskFlowRefused, task_flow.approve, delayed_task)
Example #7
0
    def test(self):

        class A(Task):
            
            @property
            def tag(self):
                return self.extra_params['name']
            
            @property
            def dependencies(self):
                return [B(self.task_flow, name="b"), C(self.task_flow, name="c")]
        register_task_cls(A)

        class B(Task):

            @property
            def tag(self):
                return self.extra_params['name']

        class C(Task):

            @property
            def tag(self):
                return self.extra_params['name']

            @property
            def dependencies(self):
                return [D(self.task_flow, name="d")]

        class D(Task):

            @property
            def tag(self):
                return self.extra_params['name']

        with patch.object(A, "__call__") as call_a:
            with patch.object(B, "__call__") as call_b:
                with patch.object(C, "__call__") as call_c:
                    with patch.object(D, "__call__") as call_d:
                        task_flow = new_task_flow(A, annotation="foo task flow", name='a')
                        e_info = raises(TaskFlowDelayed, task_flow.start)
                        a_task = task_flow.root_task.checkout()
                        assert a_task.approved
                        delayed_task = e_info.value.task
                        assert delayed_task.tag == 'b'
                        delayed_task.checkout()
                        assert not delayed_task.approved

                        e_info = raises(TaskFlowDelayed, task_flow.approve, delayed_task)
                        delayed_task.checkout()
                        assert delayed_task.approved
                        delayed_task = e_info.value.task
                        assert delayed_task.tag == 'c'
                        delayed_task.checkout()
                        assert not delayed_task.approved

                        e_info = raises(TaskFlowDelayed, task_flow.approve, delayed_task)
                        delayed_task.checkout()
                        assert delayed_task.approved
                        delayed_task = e_info.value.task
                        assert delayed_task.tag == 'd'
                        delayed_task.checkout()
                        assert not delayed_task.approved
            
                        task_flow.approve(delayed_task)
                        call_a.assert_called_once_with()
                        call_b.assert_called_once_with()
                        call_c.assert_called_once_with()
                        call_d.assert_called_once_with()

                        assert not delayed_task.failed
                        assert not task_flow.failed

        ## test refused
        with patch.object(B, "on_refused") as mock_method:
            task_flow = new_task_flow(A, annotation="foo task flow", name='a')
            try:
                task_flow.start()
            except TaskFlowDelayed, e:
                delayed_task = e.task
                pass
            task_flow.refuse(delayed_task)
            task_flow = get_task_flow(task_flow.id_)
            assert task_flow.status == constants.TASK_FLOW_REFUSED
            mock_method.assert_called_once_with(True)
            raises(TaskFlowRefused, task_flow.approve, delayed_task)
Example #8
0
    def test(self):
        class A(Task):

            @property
            def tag(self):
                return 'A'

            def __call__(self):
                raise RuntimeError()

            @property
            def dependencies(self):
                return [B(self.task_flow)]

        class B(Task):

            @property
            def tag(self):
                return 'B'

        task_flow = new_task_flow(A)
        try:
            task_flow.start()
        except TaskFlowDelayed:
            pass
        raises(RuntimeError, task_flow.approve, B(task_flow))

        assert task_flow.failed
        b_task = B(task_flow).checkout()
        assert not b_task.failed
        a_task = A(task_flow).checkout()
        assert a_task.failed
        assert task_flow.status == constants.TASK_FLOW_APPROVED

        raises(RuntimeError, task_flow.execute)
        assert task_flow.status == constants.TASK_FLOW_APPROVED

        assert task_flow.failed
        b_task = B(task_flow).checkout()
        assert not b_task.failed
        a_task = A(task_flow).checkout()
        assert a_task.failed
        
        class A_(Task):

            @property
            def tag(self):
                return 'A'

            @property
            def dependencies(self):
                return [B(self.task_flow)]

        task_flow = new_task_flow(A_)
        try:
            task_flow.start()
        except TaskFlowDelayed:
            pass
        
        task_flow.approve(B(task_flow))
        assert task_flow.status == constants.TASK_FLOW_EXECUTED