예제 #1
0
    def test_logic_tasks_continue(self):
        """Test that the logic tasks work correctly when continuing."""
        from invenio.modules.workflows.models import (BibWorkflowObject,
                                                      ObjectVersion)
        from invenio.modules.workflows.api import (start,
                                                   continue_oid)
        from invenio.modules.workflows.engine import WorkflowStatus

        test_object = BibWorkflowObject()
        test_object.set_data(0)
        test_object.save()
        workflow = start('test_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)
예제 #2
0
    def test_logic_tasks_continue(self):
        """Test that the logic tasks work correctly when continuing."""
        from invenio.modules.workflows.models import (BibWorkflowObject,
                                                      ObjectVersion)
        from invenio.modules.workflows.api import (start,
                                                   continue_oid)
        from invenio.modules.workflows.engine import WorkflowStatus

        test_object = BibWorkflowObject()
        test_object.set_data(0)
        test_object.save()
        workflow = start('test_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)
예제 #3
0
    def test_workflow_for_halted_object(self):
        """Test workflow with continuing a halted object."""
        from invenio.modules.workflows.models import (BibWorkflowObject,
                                                      ObjectVersion)
        from invenio.modules.workflows.api import start, continue_oid
        from invenio.modules.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)
예제 #4
0
    def test_workflow_for_halted_object(self):
        """Test workflow with continuing a halted object."""
        from invenio.modules.workflows.models import (BibWorkflowObject,
                                                      ObjectVersion)
        from invenio.modules.workflows.api import start, continue_oid
        from invenio.modules.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)
예제 #5
0
    def test_workflow_restarts(self):
        """Check if all is well when restarting a workflow several times."""
        from invenio.modules.workflows.models import (BibWorkflowObject,
                                                      ObjectVersion)
        from invenio.modules.workflows.api import start, continue_oid
        from invenio.modules.workflows.engine import WorkflowStatus

        test_object = BibWorkflowObject()

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

        test_object.set_data(tries)
        test_object.save()

        engine = start('test_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)
예제 #6
0
    def test_workflow_restarts(self):
        """Check if all is well when restarting a workflow several times."""
        from invenio.modules.workflows.models import (BibWorkflowObject,
                                                      ObjectVersion)
        from invenio.modules.workflows.api import start, continue_oid
        from invenio.modules.workflows.engine import WorkflowStatus

        test_object = BibWorkflowObject()

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

        test_object.set_data(tries)
        test_object.save()

        engine = start('test_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)
예제 #7
0
    def test_continue_execution_for_object(self):
        """Test continuing execution of workflow for object given."""
        from invenio.modules.workflows.models import (BibWorkflowObject,
                                                      ObjectVersion)
        from invenio.modules.workflows.api import start, continue_oid

        initial_data = 1

        # testing restarting from previous task
        init_workflow = start("test_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)
예제 #8
0
    def test_continue_execution_for_object(self):
        """Test continuing execution of workflow for object given."""
        from invenio.modules.workflows.models import (BibWorkflowObject,
                                                      ObjectVersion)
        from invenio.modules.workflows.api import start, continue_oid

        initial_data = 1

        # testing restarting from previous task
        init_workflow = start("test_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)
예제 #9
0
    def test_continue_execution_for_object(self):
        """Tests continuing execution of workflow for object
        given object from prev, current and next task"""
        from invenio.modules.workflows.models import BibWorkflowObject
        from invenio.modules.workflows.api import (start, continue_oid)
        initial_data = {'data': 1}
        final_data_prev = {'data': 3}
        final_data_curr = {'data': 2}
        final_data_next = {'data': 9}

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

        obj_halted = BibWorkflowObject.query.filter(
            BibWorkflowObject.id_workflow == init_workflow.uuid,
            BibWorkflowObject.version == CFG_OBJECT_VERSION.HALTED).first()

        workflow = continue_oid(oid=obj_halted.id,
                                start_point="restart_prev",
                                module_name="unit_tests")

        new_object = BibWorkflowObject.query.filter(
            BibWorkflowObject.id == obj_halted.id)
        self.assertEqual(new_object.count(), 1)
        self.assertEqual(new_object[0].get_data(), final_data_prev)

        all_objects = BibWorkflowObject.query.filter(
            BibWorkflowObject.id_workflow == workflow.uuid)
        self.assertEqual(all_objects.count(), 2)

        # testing restarting from current task
        init_workflow2 = start(workflow_name="test_workflow",
                               data=[initial_data],
                               module_name="unit_tests")

        obj_halted2 = BibWorkflowObject.query.filter(
            BibWorkflowObject.id_workflow == init_workflow2.uuid,
            BibWorkflowObject.version == CFG_OBJECT_VERSION.HALTED).first()
        workflow2 = continue_oid(oid=obj_halted.id, start_point="restart_task")
        object2 = BibWorkflowObject.query.filter(
            BibWorkflowObject.id == obj_halted2.id)
        self.assertEqual(object2.count(), 1)
        self.assertEqual(object2[0].get_data(), final_data_curr)

        all_objects2 = BibWorkflowObject.query.filter(
            BibWorkflowObject.id_workflow == workflow2.uuid)
        self.assertEqual(all_objects2.count(), 2)

        # testing continuing from next task
        init_workflow3 = start(workflow_name="test_workflow",
                               data=[initial_data],
                               module_name="unit_tests")

        obj_halted3 = BibWorkflowObject.query.filter(
            BibWorkflowObject.id_workflow == init_workflow3.uuid,
            BibWorkflowObject.version == CFG_OBJECT_VERSION.HALTED).first()
        workflow3 = continue_oid(oid=obj_halted3.id,
                                 start_point="continue_next",
                                 module_name="unit_tests")
        object3 = BibWorkflowObject.query.filter(
            BibWorkflowObject.id == obj_halted3.id)
        self.assertEqual(object3.count(), 1)
        self.assertEqual(object3[0].get_data(), final_data_next)

        all_objects3 = BibWorkflowObject.query.filter(
            BibWorkflowObject.id_workflow == workflow3.uuid)
        self.assertEqual(all_objects3.count(), 2)
예제 #10
0
    def test_continue_execution_for_object(self):
        """Tests continuing execution of workflow for object
        given object from prev, current and next task"""
        from invenio.modules.workflows.models import BibWorkflowObject
        from invenio.modules.workflows.api import (start,
                                                   continue_oid)
        initial_data = {'data': 1}
        final_data_prev = {'data': 3}
        final_data_curr = {'data': 2}
        final_data_next = {'data': 9}

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

        obj_halted = BibWorkflowObject.query.filter(
            BibWorkflowObject.id_workflow == init_workflow.uuid,
            BibWorkflowObject.version == CFG_OBJECT_VERSION.HALTED).first()

        workflow = continue_oid(oid=obj_halted.id,
                                start_point="restart_prev", module_name="unit_tests")

        new_object = BibWorkflowObject.query.filter(
            BibWorkflowObject.id == obj_halted.id)
        self.assertEqual(new_object.count(), 1)
        self.assertEqual(new_object[0].get_data(), final_data_prev)

        all_objects = BibWorkflowObject.query.filter(
            BibWorkflowObject.id_workflow == workflow.uuid)
        self.assertEqual(all_objects.count(), 2)

        # testing restarting from current task
        init_workflow2 = start(workflow_name="test_workflow",
                               data=[initial_data], module_name="unit_tests")

        obj_halted2 = BibWorkflowObject.query.filter(
            BibWorkflowObject.id_workflow == init_workflow2.uuid,
            BibWorkflowObject.version == CFG_OBJECT_VERSION.HALTED).first()
        workflow2 = continue_oid(oid=obj_halted.id,
                                 start_point="restart_task")
        object2 = BibWorkflowObject.query.filter(
            BibWorkflowObject.id == obj_halted2.id)
        self.assertEqual(object2.count(), 1)
        self.assertEqual(object2[0].get_data(), final_data_curr)

        all_objects2 = BibWorkflowObject.query.filter(
            BibWorkflowObject.id_workflow == workflow2.uuid)
        self.assertEqual(all_objects2.count(), 2)

        # testing continuing from next task
        init_workflow3 = start(workflow_name="test_workflow",
                               data=[initial_data], module_name="unit_tests")

        obj_halted3 = BibWorkflowObject.query.filter(
            BibWorkflowObject.id_workflow == init_workflow3.uuid,
            BibWorkflowObject.version == CFG_OBJECT_VERSION.HALTED).first()
        workflow3 = continue_oid(oid=obj_halted3.id,
                                 start_point="continue_next", module_name="unit_tests")
        object3 = BibWorkflowObject.query.filter(
            BibWorkflowObject.id == obj_halted3.id)
        self.assertEqual(object3.count(), 1)
        self.assertEqual(object3[0].get_data(), final_data_next)

        all_objects3 = BibWorkflowObject.query.filter(
            BibWorkflowObject.id_workflow == workflow3.uuid)
        self.assertEqual(all_objects3.count(), 2)