def test_restart_failed_workflow(self):
        """Test restarting workflow for given workflow id."""
        from invenio_workflows.models import (BibWorkflowObject,
                                              ObjectVersion)
        from invenio_workflows.engine import WorkflowStatus
        from invenio_workflows.api import start, start_by_oids
        from invenio_workflows.errors import WorkflowError

        initial_data = BibWorkflowObject.create_object()
        initial_data.set_data(1)
        initial_data.save()

        self.assertRaises(
            WorkflowError,
            start,
            workflow_name="demo_workflow_error",
            data=[initial_data],
            module_name="unit_tests"
        )
        self.assertEqual(initial_data.version, ObjectVersion.ERROR)

        restarted_workflow = start_by_oids("demo_workflow",
                                           oids=[initial_data.id],
                                           module_name="unit_tests")
        self.assertEqual(initial_data.version, ObjectVersion.WAITING)
        self.assertEqual(restarted_workflow.status, WorkflowStatus.HALTED)
Exemplo n.º 2
0
    def test_restart_failed_workflow(self):
        """Test restarting workflow for given workflow id."""
        from invenio_workflows.models import (BibWorkflowObject, ObjectVersion)
        from invenio_workflows.engine import WorkflowStatus
        from invenio_workflows.api import start, start_by_oids
        from invenio_workflows.errors import WorkflowError

        initial_data = BibWorkflowObject.create_object()
        initial_data.set_data(1)
        initial_data.save()

        self.assertRaises(WorkflowError,
                          start,
                          workflow_name="demo_workflow_error",
                          data=[initial_data],
                          module_name="unit_tests")
        self.assertEqual(initial_data.version, ObjectVersion.ERROR)

        restarted_workflow = start_by_oids("demo_workflow",
                                           oids=[initial_data.id],
                                           module_name="unit_tests")
        self.assertEqual(initial_data.version, ObjectVersion.WAITING)
        self.assertEqual(restarted_workflow.status, WorkflowStatus.HALTED)
    def test_workflow_for_running_object(self):
        """Test workflow with running object given and watch it fail."""
        from invenio_workflows.models import (BibWorkflowObject,
                                              ObjectVersion)
        from invenio_workflows.api import start_by_oids
        from invenio_workflows.errors import WorkflowObjectVersionError

        obj_running = BibWorkflowObject()
        obj_running.set_data(1234)
        obj_running.save(version=ObjectVersion.RUNNING)

        try:
            start_by_oids(
                'demo_workflow', [
                    obj_running.id], module_name="unit_tests")
        except Exception as e:
            self.assertTrue(isinstance(e, WorkflowObjectVersionError))
            obj_running.delete(e.id_object)
        obj_running.delete(obj_running)
        obj_running = BibWorkflowObject()
        obj_running.set_data(1234)
        obj_running.save(version=ObjectVersion.RUNNING)
        try:
            start_by_oids(
                'demo_workflow', [
                    obj_running.id], module_name="unit_tests")
        except Exception as e:
            self.assertTrue(isinstance(e, WorkflowObjectVersionError))
            obj_running.delete(e.id_object)
        obj_running.delete(obj_running)

        obj_running = BibWorkflowObject()
        obj_running.set_data(1234)
        obj_running.save(version=5)
        try:
            start_by_oids('demo_workflow', [obj_running.id],
                          module_name="unit_tests")
        except Exception as e:
            self.assertTrue(isinstance(e, WorkflowObjectVersionError))
            obj_running.delete(e.id_object)
        obj_running.delete(obj_running)
Exemplo n.º 4
0
    def test_workflow_for_running_object(self):
        """Test workflow with running object given and watch it fail."""
        from invenio_workflows.models import (BibWorkflowObject, ObjectVersion)
        from invenio_workflows.api import start_by_oids
        from invenio_workflows.errors import WorkflowObjectVersionError

        obj_running = BibWorkflowObject()
        obj_running.set_data(1234)
        obj_running.save(version=ObjectVersion.RUNNING)

        try:
            start_by_oids('demo_workflow', [obj_running.id],
                          module_name="unit_tests")
        except Exception as e:
            self.assertTrue(isinstance(e, WorkflowObjectVersionError))
            obj_running.delete(e.id_object)
        obj_running.delete(obj_running)
        obj_running = BibWorkflowObject()
        obj_running.set_data(1234)
        obj_running.save(version=ObjectVersion.RUNNING)
        try:
            start_by_oids('demo_workflow', [obj_running.id],
                          module_name="unit_tests")
        except Exception as e:
            self.assertTrue(isinstance(e, WorkflowObjectVersionError))
            obj_running.delete(e.id_object)
        obj_running.delete(obj_running)

        obj_running = BibWorkflowObject()
        obj_running.set_data(1234)
        obj_running.save(version=5)
        try:
            start_by_oids('demo_workflow', [obj_running.id],
                          module_name="unit_tests")
        except Exception as e:
            self.assertTrue(isinstance(e, WorkflowObjectVersionError))
            obj_running.delete(e.id_object)
        obj_running.delete(obj_running)