def test_sync_related_task_performs_a_request_to_the_target_sync_view_name(
            self):
        predecessor = create(Builder('task').in_state('task-state-resolved'))
        create(Builder('task').successor_from(predecessor))

        sender = BaseResponseSyncerSender(predecessor, self.request)
        sender.TARGET_SYNC_VIEW_NAME = "SYNC_TASK"
        mock_request = self._mock_dispatch_request(sender, 'OK')

        task = sender.get_related_tasks_to_sync()[0]
        sender.sync_related_task(task,
                                 'test-transition',
                                 u't\xe4st',
                                 firstname='james')

        self.assertItemsEqual([
            {
                'data': {
                    'text': 't\xc3\xa4st',
                    'transition': 'test-transition',
                    'firstname': 'james'
                },
                'path': u'task-2',
                'target_admin_unit_id': u'client1',
                'viewname': 'SYNC_TASK'
            },
        ], mock_request.requests)
    def test_sync_related_task_raises_an_exception_if_syncing_failed(self):
        predecessor = create(Builder('task').in_state('task-state-resolved'))
        create(Builder('task').successor_from(predecessor))

        sender = BaseResponseSyncerSender(predecessor, self.request)
        sender.TARGET_SYNC_VIEW_NAME = "NOT_EXISTING_VIEW"

        self._mock_dispatch_request(sender, 'NOT_FOUND')

        task = sender.get_related_tasks_to_sync()[0]
        with self.assertRaises(ResponseSyncerSenderException):
            sender.sync_related_task(task, '', '')
    def test_sync_related_task_raises_an_exception_if_syncing_failed(self):
        predecessor = create(Builder('task').in_state('task-state-resolved'))
        create(Builder('task').successor_from(predecessor))

        sender = BaseResponseSyncerSender(predecessor, self.request)
        sender.TARGET_SYNC_VIEW_NAME = "NOT_EXISTING_VIEW"

        self._mock_dispatch_request(sender, 'NOT_FOUND')

        task = sender.get_related_tasks_to_sync()[0]
        with self.assertRaises(ResponseSyncerSenderException):
            sender.sync_related_task(task, '', '')
    def test_sync_related_task_performs_a_request_to_the_target_sync_view_name(self):
        predecessor = create(Builder('task').in_state('task-state-resolved'))
        create(Builder('task').successor_from(predecessor))

        sender = BaseResponseSyncerSender(predecessor, self.request)
        sender.TARGET_SYNC_VIEW_NAME = "SYNC_TASK"
        mock_request = self._mock_dispatch_request(sender, 'OK')

        task = sender.get_related_tasks_to_sync()[0]
        sender.sync_related_task(task, 'test-transition', u't\xe4st', firstname='james')

        self.assertItemsEqual(
            [
                {'data': {'text': 't\xc3\xa4st',
                          'transition': 'test-transition',
                          'firstname': 'james'},
                 'path': u'task-2',
                 'target_admin_unit_id': u'admin-unit-1',
                 'viewname': 'SYNC_TASK'},
            ],
            mock_request.requests
        )