Пример #1
0
    def test_child_process_ready(self):
        from pipeline.django_signal_valve.valve import send
        child_id = uniqid()

        PipelineProcess.objects.child_process_ready(child_id)
        send.assert_called_with(signals,
                                'child_process_ready',
                                sender=PipelineProcess,
                                child_id=child_id)
Пример #2
0
    def test_batch_process_ready(self):
        from pipeline.django_signal_valve.valve import send
        process_id_list = [uniqid(), uniqid(), uniqid()]
        pipeline_id = uniqid()

        PipelineProcess.objects.batch_process_ready(process_id_list,
                                                    pipeline_id)
        send.assert_called_with(signals,
                                'batch_process_ready',
                                sender=PipelineProcess,
                                process_id_list=process_id_list,
                                pipeline_id=pipeline_id)
Пример #3
0
    def test_unfreeze(self):
        from pipeline.django_signal_valve.valve import send
        pipeline = PipelineObject()
        process = PipelineProcess.objects.prepare_for_pipeline(pipeline)

        process.freeze()
        process.unfreeze()
        self.assertFalse(process.is_frozen)
        process.refresh_from_db()
        self.assertFalse(process.is_frozen)

        send.assert_called_with(signals,
                                'process_unfreeze',
                                sender=PipelineProcess,
                                process_id=process.id)
Пример #4
0
    def test_set_schedule(self):
        from pipeline.django_signal_valve.valve import send
        from pipeline.engine.core.data import set_schedule_data

        service_act = ServiceActObject(interval=None)
        process_id = uniqid()
        version = uniqid()
        parent_data = 'parent_data'
        schedule = ScheduleService.objects.set_schedule(
            activity_id=service_act.id,
            service_act=service_act,
            process_id=process_id,
            version=version,
            parent_data=parent_data)
        self.assertEqual(schedule.id, '{}{}'.format(service_act.id, version))
        self.assertEqual(schedule.activity_id, service_act.id)
        self.assertEqual(schedule.process_id, process_id)
        self.assertEqual(schedule.wait_callback, True)
        self.assertEqual(schedule.version, version)
        set_schedule_data.assert_called_with(schedule.id, parent_data)

        # service need callback
        set_schedule_data.reset_mock()
        interval = StaticIntervalObject(interval=3)
        service_act = ServiceActObject(interval=interval)
        process_id = uniqid()
        version = uniqid()
        parent_data = 'new_parent_data'
        schedule = ScheduleService.objects.set_schedule(
            activity_id=service_act.id,
            service_act=service_act,
            process_id=process_id,
            version=version,
            parent_data=parent_data)
        self.assertEqual(schedule.id, '{}{}'.format(service_act.id, version))
        self.assertEqual(schedule.activity_id, service_act.id)
        self.assertEqual(schedule.process_id, process_id)
        self.assertEqual(schedule.wait_callback, False)
        self.assertEqual(schedule.version, version)
        set_schedule_data.assert_called_with(schedule.id, parent_data)
        send.assert_called_with(signals,
                                'schedule_ready',
                                sender=ScheduleService,
                                process_id=process_id,
                                schedule_id=schedule.id,
                                countdown=interval.interval)
Пример #5
0
    def test_callback(self):
        from pipeline.django_signal_valve.valve import send

        service_act = ServiceActObject(interval=None)
        process_id = uniqid()
        version = uniqid()
        parent_data = 'new_parent_data'
        callback_data = 'callback_data'
        schedule = ScheduleService.objects.set_schedule(
            activity_id=service_act.id,
            service_act=service_act,
            process_id=process_id,
            version=version,
            parent_data=parent_data)
        schedule.callback(callback_data, process_id)

        self.assertEqual(schedule.callback_data, callback_data)
        send.assert_called_with(signals,
                                'schedule_ready',
                                sender=ScheduleService,
                                process_id=process_id,
                                schedule_id=schedule.id,
                                countdown=0)

        # test invalid callback
        service_act = ServiceActObject(interval=StaticIntervalObject(
            interval=1))
        process_id = uniqid()
        version = uniqid()
        parent_data = 'new_parent_data'
        callback_data = 'callback_data'
        schedule = ScheduleService.objects.set_schedule(
            activity_id=service_act.id,
            service_act=service_act,
            process_id=process_id,
            version=version,
            parent_data=parent_data)
        self.assertRaises(InvalidOperationException,
                          schedule.callback,
                          callback_data=callback_data,
                          process_id=process_id)
Пример #6
0
    def test_set_next_schedule(self):
        from pipeline.django_signal_valve.valve import send

        interval = StaticIntervalObject(interval=3)
        service_act = ServiceActObject(interval=interval)
        process_id = uniqid()
        version = uniqid()
        parent_data = 'new_parent_data'
        schedule = ScheduleService.objects.set_schedule(
            activity_id=service_act.id,
            service_act=service_act,
            process_id=process_id,
            version=version,
            parent_data=parent_data)

        schedule.is_scheduling = True
        schedule.save()
        schedule.set_next_schedule()
        schedule.refresh_from_db()
        self.assertFalse(schedule.is_scheduling)
        send.assert_called_with(signals,
                                'schedule_ready',
                                sender=ScheduleService,
                                process_id=process_id,
                                schedule_id=schedule.id,
                                countdown=interval.interval)
        ScheduleCeleryTask.objects.unbind.assert_called_with(schedule.id)

        # test invalid call
        service_act = ServiceActObject(interval=None)
        process_id = uniqid()
        version = uniqid()
        parent_data = 'new_parent_data'
        schedule = ScheduleService.objects.set_schedule(
            activity_id=service_act.id,
            service_act=service_act,
            process_id=process_id,
            version=version,
            parent_data=parent_data)
        self.assertRaises(InvalidOperationException,
                          schedule.set_next_schedule)
Пример #7
0
    def test_process_ready(self):
        from pipeline.django_signal_valve.valve import send
        process_id = uniqid()
        current_node_id = uniqid()

        PipelineProcess.objects.process_ready(process_id)
        send.assert_called_with(signals,
                                'process_ready',
                                sender=PipelineProcess,
                                process_id=process_id,
                                current_node_id=None,
                                call_from_child=False)
        PipelineProcess.objects.process_ready(process_id, current_node_id,
                                              False)
        send.assert_called_with(signals,
                                'process_ready',
                                sender=PipelineProcess,
                                process_id=process_id,
                                current_node_id=current_node_id,
                                call_from_child=False)
        PipelineProcess.objects.process_ready(process_id, current_node_id,
                                              True)
        send.assert_called_with(signals,
                                'process_ready',
                                sender=PipelineProcess,
                                process_id=process_id,
                                current_node_id=current_node_id,
                                call_from_child=True)