Ejemplo n.º 1
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)
Ejemplo n.º 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)
    def test_dirty_worker(self):
        """Deep test of celery worker."""
        from invenio_workflows.workers.worker_celery import celery_run, celery_restart, celery_continue
        from invenio_workflows.utils import BibWorkflowObjectIdContainer
        from invenio_workflows.models import BibWorkflowObject, get_default_extra_data
        from invenio_workflows.engine import WorkflowStatus

        test_objectb = BibWorkflowObject()
        test_objectb.set_data(22)
        test_objectb.save()
        data = BibWorkflowObjectIdContainer(test_objectb).to_dict()
        celery_run("demo_workflow", [data], module_name="unit_tests")
        self.assertEqual(40, test_objectb.get_data())
        test_object = BibWorkflowObject()
        test_object.set_data(22)
        test_object.save()
        test_objectc = BibWorkflowObject()
        test_objectc.set_data(22)
        test_objectc.save()
        data = [test_object, test_objectc]
        for i in range(0, len(data)):
            if isinstance(data[i], BibWorkflowObject):
                data[i] = BibWorkflowObjectIdContainer(data[i]).to_dict()
        celery_run("demo_workflow", data, module_name="unit_tests")
        self.assertEqual(40, test_object.get_data())
        self.assertEqual(40, test_objectc.get_data())

        test_object = BibWorkflowObject()
        test_object.save()
        test_object.set_data(0)
        from invenio_workflows.worker_result import uuid_to_workflow

        engine = uuid_to_workflow(celery_run("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"])

        engine._extra_data = get_default_extra_data()  # reset iterators
        celery_restart(engine.uuid)
        self.assertEqual(5, test_object.get_data())
        self.assertEqual("lt9", test_object.get_extra_data()["test"])

        celery_continue(test_object.id, "continue_next")
        self.assertEqual(6, test_object.get_data())
        self.assertEqual("lt9", test_object.get_extra_data()["test"])

        celery_continue(test_object.id, "continue_next")
        self.assertEqual(9, test_object.get_data())
        self.assertEqual("gte9", test_object.get_extra_data()["test"])

        celery_continue(test_object.id, "continue_next")
        self.assertEqual(15, test_object.get_data())
        self.assertEqual("gte9", test_object.get_extra_data()["test"])
        engine = uuid_to_workflow(celery_continue(test_object.id, "continue_next", module_name="unit_tests"))

        self.assertEqual(WorkflowStatus.COMPLETED, engine.status)
Ejemplo n.º 4
0
    def test_logic_tasks_restart(self):
        """Test that the logic tasks work correctly when restarted."""
        from invenio_workflows.models import BibWorkflowObject
        from invenio_workflows.api import (start, start_by_wid)

        test_object = BibWorkflowObject()
        test_object.set_data(0)
        test_object.save()

        # Initial run
        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"])

        # Reset before re-starting (reset Iterator data)
        workflow.reset_extra_data()

        workflow = start_by_wid(workflow.uuid)
        self.assertEqual(5, test_object.get_data())
        self.assertEqual("lt9", test_object.get_extra_data()["test"])
Ejemplo n.º 5
0
    def test_logic_tasks_restart(self):
        """Test that the logic tasks work correctly when restarted."""
        from invenio_workflows.models import BibWorkflowObject
        from invenio_workflows.api import (start,
                                           start_by_wid)

        test_object = BibWorkflowObject()
        test_object.set_data(0)
        test_object.save()

        # Initial run
        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"])

        # Reset before re-starting (reset Iterator data)
        workflow.reset_extra_data()

        workflow = start_by_wid(workflow.uuid)
        self.assertEqual(5, test_object.get_data())
        self.assertEqual("lt9", test_object.get_extra_data()["test"])
    def test_workflows_tasks(self):
        """Test delayed workflows in non delayed one."""
        from invenio_workflows.models import BibWorkflowObject
        from invenio_workflows.api import start

        test_object = BibWorkflowObject()
        test_object.save()
        test_object.set_data(22)
        engine = start("demo_workflow_workflows", [test_object], module_name="unit_tests")
        from invenio_workflows.engine import WorkflowStatus

        self.assertEqual(0, engine.get_extra_data()["_nb_workflow_failed"])
        self.assertEqual(WorkflowStatus.COMPLETED, engine.status)
        self.assertEqual(0, test_object.get_tasks_results()["review_workflow"][0]["result"]["failed"])
        self.assertEqual(4, test_object.get_extra_data()["nbworkflowrunning"])
        self.assertEqual(21, engine.get_extra_data()["_nb_workflow_finish"])
Ejemplo n.º 7
0
    def test_workflow_without_workflow_object_saved(self):
        """Test that the logic tasks work correctly."""
        from invenio_workflows.models import BibWorkflowObject
        from invenio_workflows.api import start, start_by_wid

        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"])
        start_by_wid(workflow.uuid)
        test_object.delete(test_object.id)
Ejemplo n.º 8
0
    def test_workflow_without_workflow_object_saved(self):
        """Test that the logic tasks work correctly."""
        from invenio_workflows.models import BibWorkflowObject
        from invenio_workflows.api import start, start_by_wid

        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"])
        start_by_wid(workflow.uuid)
        test_object.delete(test_object.id)