def test_failed_activate_next(self):
        job_task_mock = mock.Mock(spec=Task())
        gate_task_mock = mock.Mock(spec=Task())

        next_flow_task_mock = mock.Mock()
        next_flow_task_mock.flow_cls.task_cls = mock.Mock(
            return_value=gate_task_mock)
        next_flow_task_mock.dst.activate = \
            lambda prev_activation, token: activation.GateActivation().activate(next_flow_task_mock, prev_activation, token)  # NOQA

        flow_task_mock = mock.MagicMock(spec=flow.Job(lambda p: None))
        flow_task_mock.flow_cls.task_cls.objects.get = mock.Mock(
            return_value=job_task_mock)
        flow_task_mock.activation_cls = mock.Mock(
            return_value=activation.JobActivation())
        flow_task_mock._outgoing = mock.Mock(
            return_value=[next_flow_task_mock])

        with mock.patch('viewflow.flow.job.import_task_by_ref',
                        return_value=flow_task_mock):
            successful_job(flow_task_strref='unit/TestFlow.job',
                           process_pk=-1,
                           task_pk=-1)

        job_task_mock.prepare.assert_called_once_with()
        job_task_mock.start.assert_called_once_with()
        job_task_mock.done.assert_called_once_with()
        self.assertFalse(job_task_mock.error.called)

        gate_task_mock.prepare.assert_called_once_with()
        gate_task_mock.error.assert_called_once_with()
        self.assertFalse(gate_task_mock.done.called)
Exemplo n.º 2
0
def user_queue(flow_classes, user):
    queryset = Task.filter_available(
        flow_classes,
        user
    ).filter(
        flow_task_type='HUMAN',
        status=STATUS.NEW
    )

    if not user.is_superuser:
        all_object_perms = set(user.get_all_permissions())
        per_object_perms = {
            '{}.{}'.format(userperm.content_type.app_label, userperm.permission.codename)
            for userperm in UserObjectPermission.objects.filter(user=user)
        } - all_object_perms

        has_permission = (
            Q(owner_permission__in=all_object_perms | per_object_perms) |
            Q(owner_permission__isnull=True) |
            Q(owner=user)
        )

        queryset = queryset.filter(
            has_permission
        ).exclude(
            process__flow_class=BillFlow,
            process__order_department__nq=user.department
        )

    return queryset
Exemplo n.º 3
0
    def test_join_activation_activate(self):
        prev_task_mock = mock.Mock(spec=Task())
        prev_task_mock.token = Token('start/1_2')

        task_mock = mock.Mock(spec=Task())
        task_mock.previous.all = mock.Mock(return_value=[prev_task_mock])

        flow_task_mock = mock.Mock(spec=flow.Join())
        flow_task_mock._outgoing = mock.Mock(return_value=[])
        flow_task_mock.flow_cls.task_cls = mock.Mock(return_value=task_mock)
        flow_task_mock.flow_cls.task_cls._default_manager.filter = mock.Mock(
            return_value=Task.objects.none())

        prev_activation_mock = mock.Mock(spec=activation.StartActivation())

        act = gates.JoinActivation.activate(flow_task_mock,
                                            prev_activation_mock,
                                            Token('start'))
        act.task.save.assert_has_calls(())
        flow_task_mock._outgoing.assert_any_call()
Exemplo n.º 4
0
    def test_job_activation_lifecycle(self):
        flow_task_mock = mock.Mock(spec=flow.Job(lambda *args, **kwargs: None))
        flow_task_mock._outgoing = mock.Mock(return_value=[])
        task_mock = mock.Mock(spec=Task())

        act = activation.JobActivation()
        act.initialize(flow_task_mock, task_mock)
        act.prepare()
        act.start()
        act.done(result=None)

        act.task.done.assert_called_once_with()
        flow_task_mock._outgoing.assert_any_call()
    def test_failed_job(self):
        task_mock = mock.Mock(spec=Task())
        flow_task_mock = mock.MagicMock(spec=flow.Job(lambda p: None))
        flow_task_mock.flow_cls.task_cls.objects.get = mock.Mock(
            return_value=task_mock)
        flow_task_mock.activation_cls = mock.Mock(
            return_value=activation.JobActivation())

        with mock.patch('viewflow.flow.job.import_task_by_ref',
                        return_value=flow_task_mock):
            with self.assertRaises(NotImplementedError):
                failure_job(flow_task_strref='unit/TestFlow.job',
                            process_pk=-1,
                            task_pk=-1)

        task_mock.prepare.assert_called_once_with()
        task_mock.start.assert_called_once_with()
        task_mock.error.assert_called_once_with()
        self.assertFalse(task_mock.done.called)
Exemplo n.º 6
0
def user_queue(flow_classes, user):
    queryset = Task.filter_available(flow_classes,
                                     user).filter(flow_task_type='HUMAN',
                                                  status=STATUS.NEW)

    if not user.is_superuser:
        all_object_perms = set(user.get_all_permissions())
        per_object_perms = {
            '{}.{}'.format(userperm.content_type.app_label,
                           userperm.permission.codename)
            for userperm in UserObjectPermission.objects.filter(user=user)
        } - all_object_perms

        has_permission = (
            Q(owner_permission__in=all_object_perms | per_object_perms)
            | Q(owner_permission__isnull=True) | Q(owner=user))

        queryset = queryset.filter(has_permission).exclude(
            process__flow_class=BillFlow,
            process__order_department__nq=user.department)

    return queryset