def test_logic_tasks_continue(self):
        """Test that the logic tasks work correctly when continuing."""
        from invenio_workflows.models import (BibWorkflowObject,
                                              ObjectVersion)
        from invenio_workflows.api import (start,
                                           continue_oid)
        from invenio_workflows.engine import WorkflowStatus

        test_object = BibWorkflowObject()
        test_object.set_data(0)
        test_object.save()
        workflow = start('demo_workflow_logic', [test_object],
                         module_name="unit_tests")

        self.assertEqual(5, test_object.get_data())
        self.assertEqual("lt9", test_object.get_extra_data()["test"])

        workflow = continue_oid(test_object.id)
        self.assertEqual(6, test_object.get_data())
        self.assertEqual("lt9", test_object.get_extra_data()["test"])

        workflow = continue_oid(test_object.id)
        self.assertEqual(9, test_object.get_data())
        self.assertEqual("gte9", test_object.get_extra_data()["test"])

        workflow = continue_oid(test_object.id)
        self.assertEqual(15, test_object.get_data())
        self.assertEqual("gte9", test_object.get_extra_data()["test"])

        workflow = continue_oid(test_object.id)
        self.assertEqual(ObjectVersion.COMPLETED, test_object.version)
        self.assertEqual(WorkflowStatus.COMPLETED, workflow.status)
Example #2
0
    def test_logic_tasks_continue(self):
        """Test that the logic tasks work correctly when continuing."""
        from invenio_workflows.models import (BibWorkflowObject, ObjectVersion)
        from invenio_workflows.api import (start, continue_oid)
        from invenio_workflows.engine import WorkflowStatus

        test_object = BibWorkflowObject()
        test_object.set_data(0)
        test_object.save()
        workflow = start('demo_workflow_logic', [test_object],
                         module_name="unit_tests")

        self.assertEqual(5, test_object.get_data())
        self.assertEqual("lt9", test_object.get_extra_data()["test"])

        workflow = continue_oid(test_object.id)
        self.assertEqual(6, test_object.get_data())
        self.assertEqual("lt9", test_object.get_extra_data()["test"])

        workflow = continue_oid(test_object.id)
        self.assertEqual(9, test_object.get_data())
        self.assertEqual("gte9", test_object.get_extra_data()["test"])

        workflow = continue_oid(test_object.id)
        self.assertEqual(15, test_object.get_data())
        self.assertEqual("gte9", test_object.get_extra_data()["test"])

        workflow = continue_oid(test_object.id)
        self.assertEqual(ObjectVersion.COMPLETED, test_object.version)
        self.assertEqual(WorkflowStatus.COMPLETED, workflow.status)
Example #3
0
    def test_workflow_for_halted_object(self):
        """Test workflow with continuing a halted object."""
        from invenio_workflows.models import (BibWorkflowObject, ObjectVersion)
        from invenio_workflows.api import start, continue_oid
        from invenio_workflows.engine import WorkflowStatus

        current = BibWorkflowObject()
        current.set_data(self.recxml)
        current.save()

        workflow = start(workflow_name="marcxml_workflow",
                         data=[current],
                         module_name="unit_tests")

        self.assertEqual(WorkflowStatus.HALTED, workflow.status)
        self.assertEqual(ObjectVersion.HALTED, current.version)

        workflow = continue_oid(current.id, module_name="unit_tests")
        self.assertEqual(WorkflowStatus.COMPLETED, workflow.status)
        self.assertEqual(ObjectVersion.COMPLETED, current.version)
    def test_workflow_for_halted_object(self):
        """Test workflow with continuing a halted object."""
        from invenio_workflows.models import (BibWorkflowObject,
                                              ObjectVersion)
        from invenio_workflows.api import start, continue_oid
        from invenio_workflows.engine import WorkflowStatus

        current = BibWorkflowObject()
        current.set_data(self.recxml)
        current.save()

        workflow = start(workflow_name="marcxml_workflow",
                         data=[current],
                         module_name="unit_tests")

        self.assertEqual(WorkflowStatus.HALTED, workflow.status)
        self.assertEqual(ObjectVersion.HALTED, current.version)

        workflow = continue_oid(current.id,
                                module_name="unit_tests")
        self.assertEqual(WorkflowStatus.COMPLETED, workflow.status)
        self.assertEqual(ObjectVersion.COMPLETED, current.version)
Example #5
0
    def test_workflow_restarts(self):
        """Check if all is well when restarting a workflow several times."""
        from invenio_workflows.models import (BibWorkflowObject, ObjectVersion)
        from invenio_workflows.api import start, continue_oid
        from invenio_workflows.engine import WorkflowStatus

        test_object = BibWorkflowObject()

        random.seed(time.time())
        tries = 15

        test_object.set_data(tries)
        test_object.save()

        engine = start('demo_workflow_hardcore', [test_object],
                       module_name="unit_tests")
        for i in range(0, tries):
            self.assertEqual(engine.status, WorkflowStatus.HALTED)
            for my_object_b in engine.getObjects():
                engine = continue_oid(my_object_b[1].id, "restart_task")
        self.assertEqual(0, test_object.get_data())
        self.assertEqual(ObjectVersion.COMPLETED, test_object.version)
        self.assertEqual(WorkflowStatus.COMPLETED, engine.status)
    def test_workflow_restarts(self):
        """Check if all is well when restarting a workflow several times."""
        from invenio_workflows.models import (BibWorkflowObject,
                                              ObjectVersion)
        from invenio_workflows.api import start, continue_oid
        from invenio_workflows.engine import WorkflowStatus

        test_object = BibWorkflowObject()

        random.seed(time.time())
        tries = 15

        test_object.set_data(tries)
        test_object.save()

        engine = start('demo_workflow_hardcore', [test_object],
                       module_name="unit_tests")
        for i in range(0, tries):
            self.assertEqual(engine.status, WorkflowStatus.HALTED)
            for my_object_b in engine.getObjects():
                engine = continue_oid(my_object_b[1].id, "restart_task")
        self.assertEqual(0, test_object.get_data())
        self.assertEqual(ObjectVersion.COMPLETED, test_object.version)
        self.assertEqual(WorkflowStatus.COMPLETED, engine.status)
Example #7
0
    def test_continue_execution_for_object(self):
        """Test continuing execution of workflow for object given."""
        from invenio_workflows.models import (BibWorkflowObject,
                                              ObjectVersion)
        from invenio_workflows.api import start, continue_oid

        initial_data = 1

        # testing restarting from previous task
        init_workflow = start("demo_workflow",
                              data=[initial_data],
                              module_name="unit_tests")

        obj_halted = BibWorkflowObject.query.filter(
            BibWorkflowObject.id_workflow == init_workflow.uuid,
            BibWorkflowObject.version == ObjectVersion.WAITING
        ).first()

        self.assertTrue(obj_halted)
        self.assertEqual(1, obj_halted.get_data())

        # Try to restart, we should halt again actually.
        continue_oid(oid=obj_halted.id, start_point="restart_task",
                     module_name="unit_tests")

        self.assertEqual(1, obj_halted.get_data())
        self.assertEqual(ObjectVersion.WAITING, obj_halted.version)

        # We skip to next part, this should work
        continue_oid(oid=obj_halted.id, module_name="unit_tests")

        self.assertEqual(19, obj_halted.get_data())
        self.assertEqual(ObjectVersion.COMPLETED, obj_halted.version)

        # Let's do that last task again, shall we?
        continue_oid(oid=obj_halted.id, start_point="restart_prev",
                     module_name="unit_tests")

        self.assertEqual(37, obj_halted.get_data())
        self.assertEqual(ObjectVersion.COMPLETED, obj_halted.version)
Example #8
0
    def test_continue_execution_for_object(self):
        """Test continuing execution of workflow for object given."""
        from invenio_workflows.models import (BibWorkflowObject, ObjectVersion)
        from invenio_workflows.api import start, continue_oid

        initial_data = 1

        # testing restarting from previous task
        init_workflow = start("demo_workflow",
                              data=[initial_data],
                              module_name="unit_tests")

        obj_halted = BibWorkflowObject.query.filter(
            BibWorkflowObject.id_workflow == init_workflow.uuid,
            BibWorkflowObject.version == ObjectVersion.WAITING).first()

        self.assertTrue(obj_halted)
        self.assertEqual(1, obj_halted.get_data())

        # Try to restart, we should halt again actually.
        continue_oid(oid=obj_halted.id,
                     start_point="restart_task",
                     module_name="unit_tests")

        self.assertEqual(1, obj_halted.get_data())
        self.assertEqual(ObjectVersion.WAITING, obj_halted.version)

        # We skip to next part, this should work
        continue_oid(oid=obj_halted.id, module_name="unit_tests")

        self.assertEqual(19, obj_halted.get_data())
        self.assertEqual(ObjectVersion.COMPLETED, obj_halted.version)

        # Let's do that last task again, shall we?
        continue_oid(oid=obj_halted.id,
                     start_point="restart_prev",
                     module_name="unit_tests")
        self.assertEqual(37, obj_halted.get_data())
        self.assertEqual(ObjectVersion.COMPLETED, obj_halted.version)