示例#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_dirty_worker(self):
        """Deep test of celery worker."""
        from ..workers.worker_celery import celery_run, celery_restart, celery_continue
        from invenio.modules.workflows.utils import BibWorkflowObjectIdContainer
        from invenio.modules.workflows.models import BibWorkflowObject, get_default_extra_data

        test_objectb = BibWorkflowObject()
        test_objectb.set_data(22)
        test_objectb.save()
        data = BibWorkflowObjectIdContainer(test_objectb).to_dict()
        celery_run("test_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("test_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.modules.workflows.worker_result import uuid_to_workflow

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

        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"))
        from invenio.modules.workflows.engine import WorkflowStatus

        self.assertEqual(WorkflowStatus.COMPLETED, engine.status)
示例#4
0
    def test_filtering(self):
        """Test filtering functionality."""
        from ..tasks.harvesting import filtering_oai_pmh_identifier
        from invenio.modules.workflows.api import start
        from invenio.modules.workflows.models import BibWorkflowObject

        my_test_obj = BibWorkflowObject()
        my_test_obj.set_data("<record><test></test>"
                             "<identifier>identifier1</identifier></record>")
        my_test_obj.save()

        my_test_obj_b = BibWorkflowObject()
        my_test_obj_b.set_data([
            "<record><test></test><identifier>identifier2"
            "</identifier></record>"
        ])
        my_test_obj_b.save()
        engine = start("test_workflow_dummy",
                       my_test_obj,
                       module_name="unit_tests")

        # Initialize these attributes to simulate task running in workflows
        my_test_obj.data = my_test_obj.get_data()
        my_test_obj.extra_data = my_test_obj.get_extra_data()
        my_test_obj_b.data = my_test_obj_b.get_data()
        my_test_obj_b.extra_data = my_test_obj_b.get_extra_data()
        engine.extra_data = engine.get_extra_data()

        # Try to add an identifier
        self.assertTrue(filtering_oai_pmh_identifier(my_test_obj, engine))

        # Update engine with the added identifier
        engine.set_extra_data(engine.extra_data)
        engine.extra_data = engine.get_extra_data()

        # False because it is already added
        self.assertFalse(filtering_oai_pmh_identifier(my_test_obj, engine))
        engine.set_extra_data(engine.extra_data)
        engine.extra_data = engine.get_extra_data()

        self.assertTrue(filtering_oai_pmh_identifier(my_test_obj_b, engine))
        engine.set_extra_data(engine.extra_data)
        engine.extra_data = engine.get_extra_data()

        # False because it is already added
        self.assertFalse(filtering_oai_pmh_identifier(my_test_obj_b, engine))
        engine.set_extra_data(engine.extra_data)
        engine.extra_data = engine.get_extra_data()
示例#5
0
    def test_filtering(self):
        """Test filtering functionality."""
        from ..tasks.harvesting import filtering_oai_pmh_identifier
        from invenio.modules.workflows.api import start
        from invenio.modules.workflows.models import BibWorkflowObject

        my_test_obj = BibWorkflowObject()
        my_test_obj.set_data("<record><test></test>"
                             "<identifier>identifier1</identifier></record>")
        my_test_obj.save()

        my_test_obj_b = BibWorkflowObject()
        my_test_obj_b.set_data(["<record><test></test><identifier>identifier2"
                                "</identifier></record>"])
        my_test_obj_b.save()
        engine = start("test_workflow_dummy",
                       my_test_obj,
                       module_name="unit_tests")

        # Initialize these attributes to simulate task running in workflows
        my_test_obj.data = my_test_obj.get_data()
        my_test_obj.extra_data = my_test_obj.get_extra_data()
        my_test_obj_b.data = my_test_obj_b.get_data()
        my_test_obj_b.extra_data = my_test_obj_b.get_extra_data()
        engine.extra_data = engine.get_extra_data()

        # Try to add an identifier
        self.assertTrue(filtering_oai_pmh_identifier(my_test_obj, engine))

        # Update engine with the added identifier
        engine.set_extra_data(engine.extra_data)
        engine.extra_data = engine.get_extra_data()

        # False because it is already added
        self.assertFalse(filtering_oai_pmh_identifier(my_test_obj, engine))
        engine.set_extra_data(engine.extra_data)
        engine.extra_data = engine.get_extra_data()

        self.assertTrue(filtering_oai_pmh_identifier(my_test_obj_b, engine))
        engine.set_extra_data(engine.extra_data)
        engine.extra_data = engine.get_extra_data()

        # False because it is already added
        self.assertFalse(filtering_oai_pmh_identifier(my_test_obj_b, engine))
        engine.set_extra_data(engine.extra_data)
        engine.extra_data = engine.get_extra_data()
示例#6
0
    def test_logic_tasks_restart(self):
        """Test that the logic tasks work correctly when restarted."""
        from invenio.modules.workflows.models import BibWorkflowObject
        from invenio.modules.workflows.api import (start,
                                                   start_by_wid)

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

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

        # 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"])
示例#7
0
    def test_logic_tasks_restart(self):
        """Test that the logic tasks work correctly when restarted."""
        from invenio.modules.workflows.models import BibWorkflowObject
        from invenio.modules.workflows.api import (start,
                                                   start_by_wid)

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

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

        # 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"])
示例#8
0
    def test_workflow_without_workflow_object_saved(self):
        """Test that the logic tasks work correctly."""
        from invenio.modules.workflows.models import BibWorkflowObject
        from invenio.modules.workflows.api import start, start_by_wid

        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"])
        start_by_wid(workflow.uuid)
        test_object.delete(test_object.id)
示例#9
0
    def test_workflow_without_workflow_object_saved(self):
        """Test that the logic tasks work correctly."""
        from invenio.modules.workflows.models import BibWorkflowObject
        from invenio.modules.workflows.api import start, start_by_wid

        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"])
        start_by_wid(workflow.uuid)
        test_object.delete(test_object.id)
示例#10
0
    def test_workflows_tasks(self):
        """Test delayed workflows in non delayed one."""
        from invenio.modules.workflows.models import BibWorkflowObject
        from invenio.modules.workflows.api import start

        test_object = BibWorkflowObject()
        test_object.save()
        test_object.set_data(22)
        engine = start("test_workflow_workflows", [test_object], module_name="unit_tests")
        from invenio.modules.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"])
示例#11
0
    def test_init_harvesting(self):
        """Test harvesting."""
        from ..tasks.harvesting import init_harvesting
        from invenio.modules.workflows.api import start
        from invenio.modules.workflows.models import BibWorkflowObject

        my_test_obj = BibWorkflowObject()
        my_test_obj.set_data([2])
        my_test_obj.save()
        engine = start("test_workflow_dummy", my_test_obj, module_name="unit_tests")
        my_test_obj.data = my_test_obj.get_data()
        my_test_obj.extra_data = my_test_obj.get_extra_data()
        engine.set_extra_data_params(options={"test": True})
        engine.extra_data = engine.get_extra_data()
        init_harvesting(my_test_obj, engine)
        self.assertTrue(engine.get_extra_data()["options"]["test"])
示例#12
0
    def test_init_harvesting(self):
        """Test harvesting."""
        from ..tasks.harvesting import init_harvesting
        from invenio.modules.workflows.api import start
        from invenio.modules.workflows.models import BibWorkflowObject

        my_test_obj = BibWorkflowObject()
        my_test_obj.set_data([2])
        my_test_obj.save()
        engine = start("test_workflow_dummy",
                       my_test_obj,
                       module_name="unit_tests")
        my_test_obj.data = my_test_obj.get_data()
        my_test_obj.extra_data = my_test_obj.get_extra_data()
        engine.set_extra_data_params(options={'test': True})
        engine.extra_data = engine.get_extra_data()
        init_harvesting(my_test_obj, engine)
        self.assertTrue(engine.get_extra_data()["options"]["test"])
示例#13
0
    def test_workflows_tasks(self):
        """Test delayed workflows in non delayed one."""
        from invenio.modules.workflows.models import BibWorkflowObject
        from invenio.modules.workflows.api import start

        test_object = BibWorkflowObject()
        test_object.save()
        test_object.set_data(22)
        engine = start("test_workflow_workflows", [test_object],
                       module_name="unit_tests")
        from invenio.modules.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"])
示例#14
0
    def test_dirty_worker(self):
        """Deep test of celery worker."""
        from ..workers.worker_celery import (celery_run, celery_restart,
                                             celery_continue)
        from invenio.modules.workflows.utils import \
            BibWorkflowObjectIdContainer
        from invenio.modules.workflows.models import (BibWorkflowObject,
                                                      get_default_extra_data)

        test_objectb = BibWorkflowObject()
        test_objectb.set_data(22)
        test_objectb.save()
        data = BibWorkflowObjectIdContainer(test_objectb).to_dict()
        celery_run('test_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('test_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.modules.workflows.worker_result import uuid_to_workflow

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

        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"))
        from invenio.modules.workflows.engine import WorkflowStatus

        self.assertEqual(WorkflowStatus.COMPLETED, engine.status)