Пример #1
0
    def test_token_api(self):
        token = Token('start/1_2/3_4')

        self.assertTrue(token.is_split_token())
        self.assertEqual(token.get_base_split_token(), 'start/1_2')
        self.assertEqual(token.get_common_split_prefix('start/1_2', 0),
                         'start/1_2/3_')
Пример #2
0
    def test_token_field_to_python_succeed(self):
        field = fields.TokenField()

        self.assertEqual(field.to_python(None), None)
        self.assertEqual(field.to_python(''), '')  # TODO Fix it
        self.assertEqual(field.to_python(Token('start/1')), Token('start/1'))
        self.assertEqual(field.to_python('start/1'), Token('start/1'))
Пример #3
0
    def test_split_token_source_generator(self):
        prev_token = Token('start/1_2/3_4')
        source = Token.split_token_source(prev_token, task_pk=5)
        tokens = list(islice(source, 5))

        self.assertEqual(
            set([Token(token).get_common_split_prefix() for token in tokens]),
            set(['start/1_2/3_4/5_']))
Пример #4
0
    def test_token_field_prep_value_succeed(self):
        field = fields.TokenField()

        self.assertEqual(field.get_prep_value(None), None)
        self.assertEqual(field.get_prep_value(''), '')
        self.assertEqual(field.get_prep_value('start/1'), 'start/1')
        self.assertEqual(field.get_prep_value(Token('start/1')), 'start/1')
Пример #5
0
 def activate_next(self):
     if self._split_count:
         token_source = Token.split_token_source(self.task.token,
                                                 self.task.pk)
         for _ in range(self._split_count):
             self.flow_task._next.activate(prev_activation=self,
                                           token=next(token_source))
Пример #6
0
    def test_split_token_source_generator(self):
        prev_token = Token('start/1_2/3_4')
        source = Token.split_token_source(prev_token, task_pk=5)
        tokens = list(islice(source, 5))

        self.assertEqual(set([token.get_common_split_prefix('start/1_2/3_4', 0) for token in tokens]),
                         set(['start/1_2/3_4/5_']))
Пример #7
0
 def __init__(self, *args, **kwargs):
     kwargs.setdefault('max_length', 150)
     if 'default' in kwargs:
         default = kwargs['default']
         if isinstance(default, str):
             kwargs['default'] = Token(default)
     super(TokenField, self).__init__(*args, **kwargs)
Пример #8
0
    def test_if_activation_activate(self):
        flow_task_mock = mock.Mock(spec=flow.If(lambda act: True))
        flow_task_mock._outgoing = mock.Mock(return_value=[])
        prev_activation_mock = mock.Mock(spec=activation.StartActivation())

        act = gates.IfActivation.activate(flow_task_mock, prev_activation_mock,
                                          Token('start'))
        act.task.save.assert_has_calls(())
Пример #9
0
    def test_token_join_connected_to_split(self):
        token = Token('start')
        self.assertEqual(token.get_base_split_token(), 'start')
        self.assertEqual(token.get_common_split_prefix('start', 20),
                         'start/20_')

        token = Token('start/1_2')
        self.assertEqual(token.get_base_split_token(), 'start')
        self.assertEqual(token.get_common_split_prefix('start/1_2', 20),
                         'start/1_2/20_')
Пример #10
0
 def activate_next(self):
     if self._split_count:
         token_source = Token.split_token_source(self.task.token, self.task.pk)
         for _ in range(self._split_count):
             self.flow_task._next.activate(prev_activation=self, token=next(token_source))
     elif self.flow_task._ifnone_next_node is not None:
         self.flow_task._ifnone_next_node.activate(prev_activation=self, token=self.task.token)
     else:
         raise FlowRuntimeError("{} activated with zero and no IfNone nodes specified".format(self.flow_task.name))
Пример #11
0
    def test_job_activation_activate(self):
        flow_task_mock = mock.Mock(spec=flow.Job(lambda *args, **kwargs: None))
        flow_task_mock._outgoing = mock.Mock(return_value=[])
        prev_activation_mock = mock.Mock(spec=activation.StartActivation())

        with mock.patch('viewflow.activation.get_task_ref'):
            act = activation.JobActivation.activate(flow_task_mock,
                                                    prev_activation_mock,
                                                    Token('start'))
            act.task.save.assert_has_calls(())
            self.assertEqual(1, flow_task_mock.job.apply_async.call_count)
Пример #12
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()
Пример #13
0
    def test_switch_activation_activate(self):
        flow_task_mock = mock.Mock(spec=flow.Split())
        flow_task_mock._outgoing = mock.Mock(return_value=[])
        type(flow_task_mock).branches = mock.PropertyMock(
            return_value=[(mock.Mock(), lambda p: True)])
        prev_activation_mock = mock.Mock(spec=activation.StartActivation())

        act = gates.SplitActivation.activate(flow_task_mock,
                                             prev_activation_mock,
                                             Token('start'))
        act.task.save.assert_has_calls(())
Пример #14
0
    def test_view_activation_activate(self):
        flow_task_mock = mock.Mock(
            spec=flow.View(lambda *args, **kwargs: None))
        flow_task_mock._outgoing = mock.Mock(return_value=[])
        prev_activation_mock = mock.Mock(spec=activation.StartActivation())

        act = activation.TaskActivation.activate(flow_task_mock,
                                                 prev_activation_mock,
                                                 Token('start'))

        act.task.save.assert_has_calls(())
Пример #15
0
 def activate_next(self):
     if self._approvers:
         token_source = Token.split_token_source(self.task.token,
                                                 self.task.pk)
         for user in self._approvers:
             next_task = self.flow_task._next.activate(
                 prev_activation=self, token=next(token_source))
             next_task.assign(user)
             self.update_approve_task(next_task.task)
     else:
         raise FlowRuntimeError(
             "{} activated with zero nodes specified".format(
                 self.flow_task.name))
Пример #16
0
    def test_token_join_connected_to_split(self):
        token = Token('start')
        self.assertEqual(token.get_base_split_token(), 'start')
        self.assertEqual(token.get_common_split_prefix('start', 20), 'start/20_')

        token = Token('start/1_2')
        self.assertEqual(token.get_base_split_token(), 'start')
        self.assertEqual(token.get_common_split_prefix('start/1_2', 20), 'start/1_2/20_')
Пример #17
0
 def activate_next(self):
     if self._split_count:
         token_source = Token.split_token_source(self.task.token,
                                                 self.task.pk)
         for _ in range(self._split_count):
             self.flow_task._next.activate(prev_activation=self,
                                           token=next(token_source))
     elif self.flow_task._ifnone_next_node is not None:
         self.flow_task._ifnone_next_node.activate(prev_activation=self,
                                                   token=self.task.token)
     else:
         raise FlowRuntimeError(
             "{} activated with zero and no IfNone nodes specified".format(
                 self.flow_task.name))
Пример #18
0
    def test_end_activation_activate(self):
        active_task_mock = mock.Mock()
        process_mock = mock.Mock(spec=Process())
        process_mock.active_tasks = mock.Mock(return_value=[active_task_mock])

        flow_task_mock = mock.Mock(spec=flow.End())
        flow_task_mock._outgoing = mock.Mock(return_value=[])
        flow_task_mock.flow_cls.process_cls._default_manager.get = mock.Mock(
            return_value=process_mock)
        prev_activation_mock = mock.Mock(spec=activation.StartActivation())

        act = activation.EndActivation.activate(flow_task_mock,
                                                prev_activation_mock,
                                                Token('start'))

        act.task.save.assert_has_calls(())
        act.process.finish.assert_has_calls(())
        active_task_mock.flow_task.deactivate.assert_called_once_with(mock.ANY)
Пример #19
0
    def assign_tasks(self):
        with self.exception_guard():
            self._owner_list = self.flow_task.owner_list(self)

            if self._owner_list:
                token_source = Token.split_token_source(
                    self.task.token, self.task.pk)
                for owner in self._owner_list:
                    task = self.flow_class.task_class(process=self.process,
                                                      flow_task=self.flow_task,
                                                      token=next(token_source),
                                                      owner=owner,
                                                      status=STATUS.ASSIGNED,
                                                      started=timezone.now())
                    task.save()
                    task.previous.add(self.task)

            elif self.flow_task._ifnone_next_node is not None:
                self.flow_task._ifnone_next_node.activate(
                    prev_activation=self, token=self.task.token)
            else:
                raise FlowRuntimeError(
                    "{} activated with zero and no IfNone nodes specified".
                    format(self.flow_task.name))
Пример #20
0
 def activate_next(self):
     if self._split_count:
         token_source = Token.split_token_source(self.task.token, self.task.pk)
         for _ in range(self._split_count):
             self.flow_task._next.activate(prev_activation=self, token=next(token_source))
Пример #21
0
    def activate_next(self):
        token_source = Token.split_token_source(self.task.token, self.task.pk)

        for n, next_task in enumerate(self.next_tasks, 1):
            next_task.activate(prev_activation=self, token=next(token_source))
Пример #22
0
    def test_token_api(self):
        token = Token('start/1_2/3_4')

        self.assertTrue(token.is_split_token())
        self.assertEqual(token.get_base_split_token(), 'start/1_2')
        self.assertEqual(token.get_common_split_prefix('start/1_2', 0), 'start/1_2/3_')
Пример #23
0
    def activate_next(self):
        token_source = Token.split_token_source(self.task.token, self.task.pk)

        for n, next_task in enumerate(self.next_tasks, 1):
            next_task.activate(prev_activation=self, token=next(token_source))
Пример #24
0
 def test_crud_succeed(self):
     instance = TokenModel()
     instance.token = Token('start/1_2')
     instance.save()
Пример #25
0
 def test_token_equals_succeed(self):
     token1 = Token('start/1')
     token2 = Token('start/1')
     self.assertEqual(token1, token2)
Пример #26
0
 def to_python(self, value):
     if isinstance(value, str) and value:
         return Token(value)
     return value