def test_register_for_all(self):
        self.initialize_normal_scenario()
        self.test_args = None
        self.test_kwargs = None

        def test_handler(*args, **kwargs):
            self.test_args = args
            self.test_kwargs = kwargs

        ObjectService.register_object(self.objects[0])
        ObjectService.register_object(self.objects[1])

        PostCompletedHandler.register(test_handler)

        self.assertIsNone(self.test_args)
        self.assertIsNone(self.test_kwargs)

        TransitionService.proceed(self.objects[0], self.user1)

        self.assertIsNone(self.test_args)
        self.assertIsNone(self.test_kwargs)

        # Proceeded but no transition
        TransitionService.proceed(self.objects[0], self.user2)

        self.assertIsNone(self.test_args)
        self.assertIsNone(self.test_kwargs)

        TransitionService.proceed(self.objects[0], self.user3)

        self.assertEqual((), self.test_args)
        self.assertDictEqual({"object": self.objects[0]}, self.test_kwargs)
    def test_register_for_an_object(self):
        self.test_args = None
        self.test_kwargs = None

        def test_handler(*args, **kwargs):
            self.test_args = args
            self.test_kwargs = kwargs

        ObjectService.register_object(self.objects[0], self.field)
        ObjectService.register_object(self.objects[1], self.field)

        PostCompletedHandler.register(test_handler, self.objects[0], 'my_field')

        self.assertIsNone(self.test_args)
        self.assertIsNone(self.test_kwargs)

        TransitionService.proceed(self.objects[0], self.field, self.user1)

        self.assertIsNone(self.test_args)
        self.assertIsNone(self.test_kwargs)

        # Proceeded but no transition
        TransitionService.proceed(self.objects[0], self.field, self.user2)

        self.assertIsNone(self.test_args)
        self.assertIsNone(self.test_kwargs)

        TransitionService.proceed(self.objects[0], self.field, self.user3)

        self.assertEqual((self.objects[0], 'my_field'), self.test_args)
    def test_register_for_an_object(self):
        self.test_args = None
        self.test_kwargs = None

        def test_handler(*args, **kwargs):
            self.test_args = args
            self.test_kwargs = kwargs

        ObjectService.register_object(self.objects[0])
        ObjectService.register_object(self.objects[1])

        PostCompletedHandler.register(test_handler, self.objects[0],
                                      'my_field')

        self.assertIsNone(self.test_args)
        self.assertIsNone(self.test_kwargs)

        TransitionService.proceed(self.objects[0], self.user1)

        self.assertIsNone(self.test_args)
        self.assertIsNone(self.test_kwargs)

        # Proceeded but no transition
        TransitionService.proceed(self.objects[0], self.user2)

        self.assertIsNone(self.test_args)
        self.assertIsNone(self.test_kwargs)

        TransitionService.proceed(self.objects[0], self.user3)

        self.assertEqual((self.objects[0], ), self.test_args)
    def test_register_for_all(self):
        self.initialize_normal_scenario()
        self.test_args = None
        self.test_kwargs = None

        def test_handler(*args, **kwargs):
            self.test_args = args
            self.test_kwargs = kwargs

        ObjectService.register_object(self.objects[0])
        ObjectService.register_object(self.objects[1])

        PostCompletedHandler.register(test_handler)

        self.assertIsNone(self.test_args)
        self.assertIsNone(self.test_kwargs)

        TransitionService.proceed(self.objects[0], self.user1)

        self.assertIsNone(self.test_args)
        self.assertIsNone(self.test_kwargs)

        # Proceeded but no transition
        TransitionService.proceed(self.objects[0], self.user2)

        self.assertIsNone(self.test_args)
        self.assertIsNone(self.test_kwargs)

        TransitionService.proceed(self.objects[0], self.user3)

        self.assertEqual((), self.test_args)
        self.assertDictEqual({'object': self.objects[0]}, self.test_kwargs)
    def test_register_for_a_transition(self):
        self.test_args = None
        self.test_kwargs = None

        def test_handler(*args, **kwargs):
            self.test_args = args
            self.test_kwargs = kwargs

        ObjectService.register_object(self.objects[0], self.field)
        ObjectService.register_object(self.objects[1], self.field)

        PostTransitionHandler.register(test_handler, self.objects[0], 'my_field', source_state=State.objects.get(label='s2'), destination_state=State.objects.get(label='s3'))

        self.assertIsNone(self.test_args)
        self.assertIsNone(self.test_kwargs)

        TransitionService.proceed(self.objects[0], self.field, self.user1)

        self.assertIsNone(self.test_args)
        self.assertIsNone(self.test_kwargs)

        TransitionService.proceed(self.objects[0], self.field, self.user2)

        self.assertIsNone(self.test_args)
        self.assertIsNone(self.test_kwargs)

        TransitionService.proceed(self.objects[0], self.field, self.user3)

        self.assertEqual((self.objects[0], 'my_field'), self.test_args)
        self.assertDictEqual(
            {
                'proceeding': Proceeding.objects.filter(meta__transition__source_state=State.objects.get(label='s2'), meta__transition__destination_state=State.objects.get(label='s3'))[2],
                'source_state': State.objects.get(label='s2'),
                'destination_state': State.objects.get(label='s3')
            }, self.test_kwargs)
    def test_register_for_all(self):
        self.test_args = None
        self.test_kwargs = None

        def test_handler(*args, **kwargs):
            self.test_args = args
            self.test_kwargs = kwargs

        ObjectService.register_object(self.objects[0], self.field)
        ObjectService.register_object(self.objects[1], self.field)

        PostCompletedHandler.register(test_handler)

        self.assertIsNone(self.test_args)
        self.assertIsNone(self.test_kwargs)

        TransitionService.proceed(self.objects[0], self.field, self.user1)

        self.assertIsNone(self.test_args)
        self.assertIsNone(self.test_kwargs)

        # Proceeded but no transition
        TransitionService.proceed(self.objects[0], self.field, self.user2)

        self.assertIsNone(self.test_args)
        self.assertIsNone(self.test_kwargs)

        TransitionService.proceed(self.objects[0], self.field, self.user3)

        self.assertEqual((), self.test_args)
        self.assertDictEqual({
            'field': 'my_field',
            'object': self.objects[0]
        }, self.test_kwargs)
Пример #7
0
    def test_register_for_all(self):
        self.initialize_normal_scenario()
        self.test_args = None
        self.test_kwargs = None

        def test_handler(*args, **kwargs):
            self.test_args = args
            self.test_kwargs = kwargs

        ObjectService.register_object(self.objects[0], self.field)
        ObjectService.register_object(self.objects[1], self.field)

        PostTransitionHandler.register(test_handler)

        self.assertIsNone(self.test_args)
        self.assertIsNone(self.test_kwargs)

        TransitionService.proceed(self.objects[0], self.field, self.user1)

        self.assertEqual((), self.test_args)
        self.assertDictEqual(
            {
                'field': 'my_field',
                'object': self.objects[0],
                'proceeding': Proceeding.objects.filter(meta__transition__source_state=State.objects.get(label='s1'), meta__transition__destination_state=State.objects.get(label='s2'))[0],
                'source_state': State.objects.get(label='s1'),
                'destination_state': State.objects.get(label='s2')
            }, self.test_kwargs)


        # Proceeded but no transition
        TransitionService.proceed(self.objects[0], self.field, self.user2)

        self.assertEqual((), self.test_args)
        self.assertDictEqual(
            {
                'field': 'my_field',
                'object': self.objects[0],
                'proceeding': Proceeding.objects.filter(meta__transition__source_state=State.objects.get(label='s1'), meta__transition__destination_state=State.objects.get(label='s2'))[0],
                'source_state': State.objects.get(label='s1'),
                'destination_state': State.objects.get(label='s2')
            }, self.test_kwargs)

        TransitionService.proceed(self.objects[0], self.field, self.user3)

        self.assertEqual((), self.test_args)
        self.assertDictEqual(
            {
                'field': 'my_field',
                'object': self.objects[0],
                'proceeding': Proceeding.objects.filter(meta__transition__source_state=State.objects.get(label='s2'), meta__transition__destination_state=State.objects.get(label='s3'))[2],
                'source_state': State.objects.get(label='s2'),
                'destination_state': State.objects.get(label='s3')
            }, self.test_kwargs)
Пример #8
0
    def test_register_for_a_transition(self):
        self.test_args = None
        self.test_kwargs = None

        def test_handler(*args, **kwargs):
            self.test_args = args
            self.test_kwargs = kwargs

        ObjectService.register_object(self.objects[0], self.field)
        ObjectService.register_object(self.objects[1], self.field)

        PostTransitionHandler.register(
            test_handler,
            self.objects[0],
            'my_field',
            source_state=State.objects.get(label='s2'),
            destination_state=State.objects.get(label='s3'))

        self.assertIsNone(self.test_args)
        self.assertIsNone(self.test_kwargs)

        TransitionService.proceed(self.objects[0], self.field, self.user1)

        self.assertIsNone(self.test_args)
        self.assertIsNone(self.test_kwargs)

        TransitionService.proceed(self.objects[0], self.field, self.user2)

        self.assertIsNone(self.test_args)
        self.assertIsNone(self.test_kwargs)

        TransitionService.proceed(self.objects[0], self.field, self.user3)

        self.assertEqual((self.objects[0], 'my_field'), self.test_args)
        self.assertDictEqual(
            {
                'proceeding':
                Proceeding.objects.filter(
                    meta__transition__source_state=State.objects.get(
                        label='s2'),
                    meta__transition__destination_state=State.objects.get(
                        label='s3'))[2],
                'source_state':
                State.objects.get(label='s2'),
                'destination_state':
                State.objects.get(label='s3')
            }, self.test_kwargs)
    def test_register_for_a_transition(self):
        self.initialize_normal_scenario()
        self.test_args = None
        self.test_kwargs = None

        def test_handler(*args, **kwargs):
            self.test_args = args
            self.test_kwargs = kwargs

        ObjectService.register_object(self.objects[0])
        ObjectService.register_object(self.objects[1])

        PostTransitionHandler.register(
            test_handler,
            self.objects[0],
            source_state=State.objects.get(label="s2"),
            destination_state=State.objects.get(label="s3"),
        )

        self.assertIsNone(self.test_args)
        self.assertIsNone(self.test_kwargs)

        TransitionService.proceed(self.objects[0], self.user1)

        self.assertIsNone(self.test_args)
        self.assertIsNone(self.test_kwargs)

        TransitionService.proceed(self.objects[0], self.user2)

        self.assertIsNone(self.test_args)
        self.assertIsNone(self.test_kwargs)

        TransitionService.proceed(self.objects[0], self.user3)

        self.assertEqual((self.objects[0],), self.test_args)
        self.assertDictEqual(
            {
                "proceeding": Proceeding.objects.filter(
                    meta__transition__source_state=State.objects.get(label="s2"),
                    meta__transition__destination_state=State.objects.get(label="s3"),
                )[2],
                "source_state": State.objects.get(label="s2"),
                "destination_state": State.objects.get(label="s3"),
            },
            self.test_kwargs,
        )
Пример #10
0
 def proceed(self, user, *args, **kwargs):
     TransitionService.proceed(self, name, user, *args, **kwargs)
Пример #11
0
    def test_proceed(self):

        ObjectService.register_object(self.objects[0], self.field)
        ObjectService.register_object(self.objects[1], self.field)
        # ####################
        # STATE 1 - STATE 2
        # Only User1(2001) can proceed and after his proceed state must be changed to STATE 2
        # ###################

        # Proceeded by user has no required permission for this transition

        try:
            TransitionService.proceed(self.objects[0], self.field, self.user2)
            self.fail('Exception was expected')
        except RiverException as e:
            self.assertEqual(
                str(e),
                'There is no available state for destination for the user.')
            self.assertEqual(ErrorCode.NO_AVAILABLE_NEXT_STATE_FOR_USER,
                             e.code)

        try:
            TransitionService.proceed(self.objects[0], self.field, self.user2)
            self.fail('Exception was expected')
        except RiverException as e:
            self.assertEqual(
                str(e),
                'There is no available state for destination for the user.')
            self.assertEqual(ErrorCode.NO_AVAILABLE_NEXT_STATE_FOR_USER,
                             e.code)

        # Proceeded by user has no required permission for this transition

        try:
            TransitionService.proceed(self.objects[0], self.field, self.user3)
            self.fail('Exception was expected')
        except RiverException as e:
            self.assertEqual(
                str(e),
                'There is no available state for destination for the user.')
            self.assertEqual(ErrorCode.NO_AVAILABLE_NEXT_STATE_FOR_USER,
                             e.code)

        try:
            TransitionService.proceed(self.objects[0], self.field, self.user3)
            self.fail('Exception was expected')
        except RiverException as e:
            self.assertEqual(
                str(e),
                'There is no available state for destination for the user.')
            self.assertEqual(ErrorCode.NO_AVAILABLE_NEXT_STATE_FOR_USER,
                             e.code)

        # Proceeded by user has no required permission for this transition

        try:
            TransitionService.proceed(self.objects[0], self.field, self.user4)
            self.fail('Exception was expected')
        except RiverException as e:
            self.assertEqual(
                str(e),
                'There is no available state for destination for the user.')
            self.assertEqual(ErrorCode.NO_AVAILABLE_NEXT_STATE_FOR_USER,
                             e.code)

        try:
            TransitionService.proceed(self.objects[0], self.field, self.user4)
            self.fail('Exception was expected')
        except RiverException as e:
            self.assertEqual(
                str(e),
                'There is no available state for destination for the user.')
            self.assertEqual(ErrorCode.NO_AVAILABLE_NEXT_STATE_FOR_USER,
                             e.code)

        # Proceeded by user has required permission for this transition

        self.assertEqual(State.objects.get(label='s1'),
                         getattr(self.objects[0], self.field))

        TransitionService.proceed(self.objects[0], self.field, self.user1)

        self.assertEqual(State.objects.get(label='s2'),
                         getattr(self.objects[0], self.field))

        proceedings = Proceeding.objects.filter(
            workflow_object=self.objects[0],
            field=self.field,
            status=APPROVED,
            meta__transition__source_state__label='s1',
            meta__transition__destination_state__label='s2')
        self.assertEqual(1, proceedings.count())
        self.assertIsNotNone(proceedings[0].transactioner)
        self.assertEqual(self.user1, proceedings[0].transactioner)
        self.assertIsNotNone(proceedings[0].transaction_date)

        try:
            TransitionService.proceed(self.objects[0], self.field, self.user1)
            self.fail('Exception was expected')
        except RiverException as e:
            self.assertEqual(
                str(e),
                'There is no available state for destination for the user.')
            self.assertEqual(ErrorCode.NO_AVAILABLE_NEXT_STATE_FOR_USER,
                             e.code)

        # ####################
        # STATE 2 - STATE 3
        # User2(2002) is first proceeder and User3(2003) is second proceeder. This must be done with turn. After proceeding is done, state is gonna be changed to STATE 3
        # ####################

        # Proceeded by user has no required permission for this transition
        try:
            TransitionService.proceed(self.objects[0], self.field, self.user1)
            self.fail('Exception was expected')
        except RiverException as e:
            self.assertEqual(
                str(e),
                'There is no available state for destination for the user.')
            self.assertEqual(ErrorCode.NO_AVAILABLE_NEXT_STATE_FOR_USER,
                             e.code)

        # Proceeded by user has no required permission for this transition
        try:
            TransitionService.proceed(self.objects[0], self.field, self.user4)
            self.fail('Exception was expected')
        except RiverException as e:
            self.assertEqual(
                str(e),
                'There is no available state for destination for the user.')
            self.assertEqual(ErrorCode.NO_AVAILABLE_NEXT_STATE_FOR_USER,
                             e.code)

        # Turn is User2(2002)s, not User3(2003)s. After User2(2002) proceeded, User3(2003) can proceed.
        try:
            TransitionService.proceed(self.objects[0], self.field, self.user3)
            self.fail('Exception was expected')
        except RiverException as e:
            self.assertEqual(
                str(e),
                'There is no available state for destination for the user.')
            self.assertEqual(ErrorCode.NO_AVAILABLE_NEXT_STATE_FOR_USER,
                             e.code)

        # Proceeded by two user has required permission for this transition to get next state (order is user2(2002),user3(2003)).

        self.assertEqual(State.objects.get(label='s2'),
                         getattr(self.objects[0], self.field))
        TransitionService.proceed(self.objects[0], self.field, self.user2)

        self.assertEqual(State.objects.get(label='s2'),
                         getattr(self.objects[0], self.field))

        proceedings = Proceeding.objects.filter(
            workflow_object=self.objects[0],
            field=self.field,
            status=APPROVED,
            meta__transition__source_state__label='s2',
            meta__transition__destination_state__label='s3')
        self.assertEqual(1, proceedings.count())
        self.assertIsNotNone(proceedings[0].transactioner)
        self.assertEqual(self.user2, proceedings[0].transactioner)
        self.assertIsNotNone(proceedings[0].transaction_date)

        try:
            TransitionService.proceed(self.objects[0], self.field, self.user2)
            self.fail('Exception was expected')
        except RiverException as e:
            self.assertEqual(
                str(e),
                'There is no available state for destination for the user.')
            self.assertEqual(ErrorCode.NO_AVAILABLE_NEXT_STATE_FOR_USER,
                             e.code)

        self.assertEqual(State.objects.get(label='s2'),
                         getattr(self.objects[0], self.field))

        TransitionService.proceed(self.objects[0], self.field, self.user3)

        self.assertEqual(State.objects.get(label='s3'),
                         getattr(self.objects[0], self.field))

        proceedings = Proceeding.objects.filter(
            workflow_object=self.objects[0],
            field=self.field,
            status=APPROVED,
            meta__transition__source_state__label='s2',
            meta__transition__destination_state__label='s3')
        self.assertEqual(2, proceedings.count())
        self.assertIsNotNone(proceedings[0].transactioner)
        self.assertIsNotNone(proceedings[1].transactioner)
        self.assertEqual(self.user2, proceedings[0].transactioner)
        self.assertEqual(self.user3, proceedings[1].transactioner)
        self.assertIsNotNone(proceedings[0].transaction_date)
        self.assertIsNotNone(proceedings[1].transaction_date)

        try:
            TransitionService.proceed(self.objects[0], self.field, self.user3)
            self.fail('Exception was expected')
        except RiverException as e:
            self.assertEqual(
                str(e),
                'There is no available state for destination for the user.')
            self.assertEqual(ErrorCode.NO_AVAILABLE_NEXT_STATE_FOR_USER,
                             e.code)

        # ####################
        # STATE 3 - STATE 4 or STATE 5
        # Only User4(2004) can proceed by giving the exact next state and after his proceed with his state must be changed to STATE 4 or STATE 5
        # ###################

        # Proceeded by user has no required permission for this transition
        try:
            TransitionService.proceed(self.objects[0], self.field, self.user1)
            self.fail('Exception was expected')
        except RiverException as e:
            self.assertEqual(
                str(e),
                'There is no available state for destination for the user.')
            self.assertEqual(ErrorCode.NO_AVAILABLE_NEXT_STATE_FOR_USER,
                             e.code)

        # Proceeded by user has no required permission for this transition
        try:
            TransitionService.proceed(self.objects[0], self.field, self.user2)
            self.fail('Exception was expected')
        except RiverException as e:
            self.assertEqual(
                str(e),
                'There is no available state for destination for the user.')
            self.assertEqual(ErrorCode.NO_AVAILABLE_NEXT_STATE_FOR_USER,
                             e.code)

        # Proceeded by user has no required permission for this transition
        try:
            TransitionService.proceed(self.objects[0], self.field, self.user3)
            self.fail('Exception was expected')
        except RiverException as e:
            self.assertEqual(
                str(e),
                'There is no available state for destination for the user.')
            self.assertEqual(ErrorCode.NO_AVAILABLE_NEXT_STATE_FOR_USER,
                             e.code)

        # There are STATE 4 and STATE 5 as next. State must be given to switch
        try:
            TransitionService.proceed(self.objects[0], self.field, self.user4)
            self.fail('Exception was expected')
        except RiverException as e:
            self.assertEqual(
                str(e),
                'State must be given when there are multiple states for destination'
            )
            self.assertEqual(ErrorCode.NEXT_STATE_IS_REQUIRED, e.code)

        # There are STATE 4 and STATE 5 as next. State among STATE 4 and STATE 5 must be given to switch, not other state
        try:
            TransitionService.proceed(self.objects[0],
                                      self.field,
                                      self.user4,
                                      next_state=State.objects.get(label='s3'))
            self.fail('Exception was expected')
        except RiverException as e:
            self.assertEqual(
                str(e), "Invalid state is given(%s). Valid states is(are) %s" %
                (State.objects.get(label='s3').__unicode__(), ','.join([
                    ast.__unicode__()
                    for ast in State.objects.filter(label__in=['s4', 's5'])
                ])))
            self.assertEqual(ErrorCode.INVALID_NEXT_STATE_FOR_USER, e.code)

        # There are STATE 4 and STATE 5 as next. After one of them is given to proceeding, the state must be switch to it immediately.
        self.assertEqual(State.objects.get(label='s3'),
                         getattr(self.objects[0], self.field))

        TransitionService.proceed(self.objects[0],
                                  self.field,
                                  self.user4,
                                  next_state=State.objects.get(label='s5'))

        self.assertEqual(State.objects.get(label='s5'),
                         getattr(self.objects[0], self.field))

        proceedings = Proceeding.objects.filter(
            workflow_object=self.objects[0],
            field=self.field,
            status=APPROVED,
            meta__transition__source_state__label='s3',
            meta__transition__destination_state__label='s5')
        self.assertEqual(1, proceedings.count())
        self.assertIsNotNone(proceedings[0].transactioner)
        self.assertEqual(self.user4, proceedings[0].transactioner)
        self.assertIsNotNone(proceedings[0].transaction_date)
Пример #12
0
 def proceed(self, user, *args, **kwargs):
     TransitionService.proceed(self, name, user, *args, **kwargs)
    def test_proceed(self):

        ObjectService.register_object(self.objects[0], self.field)
        ObjectService.register_object(self.objects[1], self.field)
        # ####################
        # STATE 1 - STATE 2
        # Only User1(2001) can proceed and after his proceed state must be changed to STATE 2
        # ###################

        # Proceeded by user has no required permission for this transition

        try:
            TransitionService.proceed(self.objects[0], self.field, self.user2)
            self.fail('Exception was expected')
        except RiverException as e:
            self.assertEqual(str(e), 'There is no available state for destination for the user.')
            self.assertEqual(ErrorCode.NO_AVAILABLE_NEXT_STATE_FOR_USER, e.code)

        try:
            TransitionService.proceed(self.objects[0], self.field, self.user2)
            self.fail('Exception was expected')
        except RiverException as e:
            self.assertEqual(str(e), 'There is no available state for destination for the user.')
            self.assertEqual(ErrorCode.NO_AVAILABLE_NEXT_STATE_FOR_USER, e.code)


        # Proceeded by user has no required permission for this transition

        try:
            TransitionService.proceed(self.objects[0], self.field, self.user3)
            self.fail('Exception was expected')
        except RiverException as e:
            self.assertEqual(str(e), 'There is no available state for destination for the user.')
            self.assertEqual(ErrorCode.NO_AVAILABLE_NEXT_STATE_FOR_USER, e.code)

        try:
            TransitionService.proceed(self.objects[0], self.field, self.user3)
            self.fail('Exception was expected')
        except RiverException as e:
            self.assertEqual(str(e), 'There is no available state for destination for the user.')
            self.assertEqual(ErrorCode.NO_AVAILABLE_NEXT_STATE_FOR_USER, e.code)


        # Proceeded by user has no required permission for this transition

        try:
            TransitionService.proceed(self.objects[0], self.field, self.user4)
            self.fail('Exception was expected')
        except RiverException as e:
            self.assertEqual(str(e), 'There is no available state for destination for the user.')
            self.assertEqual(ErrorCode.NO_AVAILABLE_NEXT_STATE_FOR_USER, e.code)

        try:
            TransitionService.proceed(self.objects[0], self.field, self.user4)
            self.fail('Exception was expected')
        except RiverException as e:
            self.assertEqual(str(e), 'There is no available state for destination for the user.')
            self.assertEqual(ErrorCode.NO_AVAILABLE_NEXT_STATE_FOR_USER, e.code)

        # Proceeded by user has required permission for this transition

        self.assertEqual(State.objects.get(label='s1'), getattr(self.objects[0], self.field))

        TransitionService.proceed(self.objects[0], self.field, self.user1)

        self.assertEqual(State.objects.get(label='s2'), getattr(self.objects[0], self.field))

        proceedings = Proceeding.objects.filter(
            workflow_object=self.objects[0],
            field=self.field,
            status=APPROVED,
            meta__transition__source_state__label='s1',
            meta__transition__destination_state__label='s2'
        )
        self.assertEqual(1, proceedings.count())
        self.assertIsNotNone(proceedings[0].transactioner)
        self.assertEqual(self.user1, proceedings[0].transactioner)
        self.assertIsNotNone(proceedings[0].transaction_date)

        try:
            TransitionService.proceed(self.objects[0], self.field, self.user1)
            self.fail('Exception was expected')
        except RiverException as e:
            self.assertEqual(str(e), 'There is no available state for destination for the user.')
            self.assertEqual(ErrorCode.NO_AVAILABLE_NEXT_STATE_FOR_USER, e.code)


        # ####################
        # STATE 2 - STATE 3
        # User2(2002) is first proceeder and User3(2003) is second proceeder. This must be done with turn. After proceeding is done, state is gonna be changed to STATE 3
        # ####################

        # Proceeded by user has no required permission for this transition
        try:
            TransitionService.proceed(self.objects[0], self.field, self.user1)
            self.fail('Exception was expected')
        except RiverException as e:
            self.assertEqual(str(e), 'There is no available state for destination for the user.')
            self.assertEqual(ErrorCode.NO_AVAILABLE_NEXT_STATE_FOR_USER, e.code)

        # Proceeded by user has no required permission for this transition
        try:
            TransitionService.proceed(self.objects[0], self.field, self.user4)
            self.fail('Exception was expected')
        except RiverException as e:
            self.assertEqual(str(e), 'There is no available state for destination for the user.')
            self.assertEqual(ErrorCode.NO_AVAILABLE_NEXT_STATE_FOR_USER, e.code)

        # Turn is User2(2002)s, not User3(2003)s. After User2(2002) proceeded, User3(2003) can proceed.
        try:
            TransitionService.proceed(self.objects[0], self.field, self.user3)
            self.fail('Exception was expected')
        except RiverException as e:
            self.assertEqual(str(e), 'There is no available state for destination for the user.')
            self.assertEqual(ErrorCode.NO_AVAILABLE_NEXT_STATE_FOR_USER, e.code)


        # Proceeded by two user has required permission for this transition to get next state (order is user2(2002),user3(2003)).

        self.assertEqual(State.objects.get(label='s2'), getattr(self.objects[0], self.field))
        TransitionService.proceed(self.objects[0], self.field, self.user2)

        self.assertEqual(State.objects.get(label='s2'), getattr(self.objects[0], self.field))

        proceedings = Proceeding.objects.filter(
            workflow_object=self.objects[0],
            field=self.field,
            status=APPROVED,
            meta__transition__source_state__label='s2',
            meta__transition__destination_state__label='s3'
        )
        self.assertEqual(1, proceedings.count())
        self.assertIsNotNone(proceedings[0].transactioner)
        self.assertEqual(self.user2, proceedings[0].transactioner)
        self.assertIsNotNone(proceedings[0].transaction_date)

        try:
            TransitionService.proceed(self.objects[0], self.field, self.user2)
            self.fail('Exception was expected')
        except RiverException as e:
            self.assertEqual(str(e), 'There is no available state for destination for the user.')
            self.assertEqual(ErrorCode.NO_AVAILABLE_NEXT_STATE_FOR_USER, e.code)

        self.assertEqual(State.objects.get(label='s2'), getattr(self.objects[0], self.field))

        TransitionService.proceed(self.objects[0], self.field, self.user3)

        self.assertEqual(State.objects.get(label='s3'), getattr(self.objects[0], self.field))

        proceedings = Proceeding.objects.filter(
            workflow_object=self.objects[0],
            field=self.field,
            status=APPROVED,
            meta__transition__source_state__label='s2',
            meta__transition__destination_state__label='s3'
        )
        self.assertEqual(2, proceedings.count())
        self.assertIsNotNone(proceedings[0].transactioner)
        self.assertIsNotNone(proceedings[1].transactioner)
        self.assertEqual(self.user2, proceedings[0].transactioner)
        self.assertEqual(self.user3, proceedings[1].transactioner)
        self.assertIsNotNone(proceedings[0].transaction_date)
        self.assertIsNotNone(proceedings[1].transaction_date)

        try:
            TransitionService.proceed(self.objects[0], self.field, self.user3)
            self.fail('Exception was expected')
        except RiverException as e:
            self.assertEqual(str(e), 'There is no available state for destination for the user.')
            self.assertEqual(ErrorCode.NO_AVAILABLE_NEXT_STATE_FOR_USER, e.code)



        # ####################
        # STATE 3 - STATE 4 or STATE 5
        # Only User4(2004) can proceed by giving the exact next state and after his proceed with his state must be changed to STATE 4 or STATE 5
        # ###################

        # Proceeded by user has no required permission for this transition
        try:
            TransitionService.proceed(self.objects[0], self.field, self.user1)
            self.fail('Exception was expected')
        except RiverException as e:
            self.assertEqual(str(e), 'There is no available state for destination for the user.')
            self.assertEqual(ErrorCode.NO_AVAILABLE_NEXT_STATE_FOR_USER, e.code)

        # Proceeded by user has no required permission for this transition
        try:
            TransitionService.proceed(self.objects[0], self.field, self.user2)
            self.fail('Exception was expected')
        except RiverException as e:
            self.assertEqual(str(e), 'There is no available state for destination for the user.')
            self.assertEqual(ErrorCode.NO_AVAILABLE_NEXT_STATE_FOR_USER, e.code)

        # Proceeded by user has no required permission for this transition
        try:
            TransitionService.proceed(self.objects[0], self.field, self.user3)
            self.fail('Exception was expected')
        except RiverException as e:
            self.assertEqual(str(e), 'There is no available state for destination for the user.')
            self.assertEqual(ErrorCode.NO_AVAILABLE_NEXT_STATE_FOR_USER, e.code)


        # There are STATE 4 and STATE 5 as next. State must be given to switch
        try:
            TransitionService.proceed(self.objects[0], self.field, self.user4)
            self.fail('Exception was expected')
        except RiverException as e:
            self.assertEqual(str(e), 'State must be given when there are multiple states for destination')
            self.assertEqual(ErrorCode.NEXT_STATE_IS_REQUIRED, e.code)


        # There are STATE 4 and STATE 5 as next. State among STATE 4 and STATE 5 must be given to switch, not other state
        try:
            TransitionService.proceed(self.objects[0], self.field, self.user4, next_state=State.objects.get(label='s3'))
            self.fail('Exception was expected')
        except RiverException as e:
            self.assertEqual(str(e),
                             "Invalid state is given(%s). Valid states is(are) %s" % (
                                 State.objects.get(label='s3').__unicode__(), ','.join([ast.__unicode__() for ast in State.objects.filter(label__in=['s4', 's5'])])))
            self.assertEqual(ErrorCode.INVALID_NEXT_STATE_FOR_USER, e.code)




        # There are STATE 4 and STATE 5 as next. After one of them is given to proceeding, the state must be switch to it immediately.
        self.assertEqual(State.objects.get(label='s3'), getattr(self.objects[0], self.field))

        TransitionService.proceed(self.objects[0], self.field, self.user4, next_state=State.objects.get(label='s5'))

        self.assertEqual(State.objects.get(label='s5'), getattr(self.objects[0], self.field))

        proceedings = Proceeding.objects.filter(
            workflow_object=self.objects[0],
            field=self.field,
            status=APPROVED,
            meta__transition__source_state__label='s3',
            meta__transition__destination_state__label='s5'
        )
        self.assertEqual(1, proceedings.count())
        self.assertIsNotNone(proceedings[0].transactioner)
        self.assertEqual(self.user4, proceedings[0].transactioner)
        self.assertIsNotNone(proceedings[0].transaction_date)