示例#1
0
    def test_payload_file_creation(self):
        """Can add a file to a Payload."""
        from invenio_workflows.models import BibWorkflowObject
        from inspire.modules.workflows.models import Payload
        from inspire.utils.helpers import (
            get_file_by_name,
            add_file_by_name,
        )

        obj = BibWorkflowObject.create_object()
        obj.save()
        obj.data = obj.get_data()  # FIXME hack until workflow 2.0

        payload = Payload.create(workflow_object=obj, type="payload_fixture")
        payload.save()

        fd, filename = tempfile.mkstemp()
        os.close(fd)

        newpath = add_file_by_name(payload, filename)
        self.assertTrue(newpath)

        self.assertTrue(get_file_by_name(payload,
                                         os.path.basename(filename)))
        BibWorkflowObject.delete(obj)
示例#2
0
def delete_self_and_stop_processing(obj, eng):
    """Delete both versions of itself and stops the workflow."""
    from invenio_workflows.models import BibWorkflowObject
    # delete snapshot created with original data
    initial_obj = BibWorkflowObject.query.filter(
        BibWorkflowObject.id_parent == obj.id
    ).one()
    BibWorkflowObject.delete(initial_obj.id)
    # delete self
    BibWorkflowObject.delete(obj.id)
    eng.skipToken()
class TestWorkflowModels(InvenioTestCase):

    """Test meant for testing the models available."""

    def setUp(self):
        """Setup tests."""
        from invenio_workflows.models import BibWorkflowObject, \
            Workflow
        from uuid import uuid1 as new_uuid

        self.workflow = Workflow(name='demo_workflow', uuid=new_uuid(),
                                 id_user=0, module_name="Unknown")
        self.bibworkflowobject = BibWorkflowObject(workflow=self.workflow)

        self.create_objects([self.workflow, self.bibworkflowobject])

    def tearDown(self):
        """Clean up tests."""
        self.delete_objects([self.workflow, self.bibworkflowobject])

    def test_deleting_workflow(self):
        """Test deleting workflow."""
        from invenio_workflows.models import BibWorkflowObject, \
            Workflow
        bwo_id = self.bibworkflowobject.id

        # delete workflow
        Workflow.delete(self.workflow.uuid)

        # assert bibworkflowobject is deleted
        self.assertFalse(
            db.session.query(
                BibWorkflowObject.query.filter(
                    BibWorkflowObject.id == bwo_id).exists()).scalar())

    def test_deleting_bibworkflowobject(self):
        """Test deleting workflowobject."""
        from invenio_workflows.models import Workflow
        w_uuid = self.workflow.uuid

        # delete bibworkflowobject
        self.bibworkflowobject.delete(self.bibworkflowobject.id)

        # assert workflow is not deleted
        self.assertTrue(
            db.session.query(
                Workflow.query.filter(
                    Workflow.uuid == w_uuid).exists()).scalar())
示例#4
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)
    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)
    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)
示例#7
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)