Exemplo n.º 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)
    def test_restart_failed_workflow(self):
        """Test restarting workflow for given workflow id."""
        from invenio_workflows.models import (BibWorkflowObject,
                                              ObjectVersion)
        from invenio_workflows.engine import WorkflowStatus
        from invenio_workflows.api import start, start_by_oids
        from invenio_workflows.errors import WorkflowError

        initial_data = BibWorkflowObject.create_object()
        initial_data.set_data(1)
        initial_data.save()

        self.assertRaises(
            WorkflowError,
            start,
            workflow_name="demo_workflow_error",
            data=[initial_data],
            module_name="unit_tests"
        )
        self.assertEqual(initial_data.version, ObjectVersion.ERROR)

        restarted_workflow = start_by_oids("demo_workflow",
                                           oids=[initial_data.id],
                                           module_name="unit_tests")
        self.assertEqual(initial_data.version, ObjectVersion.WAITING)
        self.assertEqual(restarted_workflow.status, WorkflowStatus.HALTED)
Exemplo n.º 3
0
def demoform():
    """View for INSPIRE demo form."""
    # from inspire.modules.forms.utils import DataExporter

    form = DemoForm(data={"nickname": "John Doe"})
    ctx = {
        "action": url_for('.demoform'),
        "name": "inspireForm",
        "id": "inspireForm",
    }
    if form.validate_on_submit():
        # If it is needed to post process the form keys, for example to match
        # the names in the JSONAlchemy, one can use the DataExporter.
        # The keys will then be renamed using `export_key` parameter.
        # visitor = DataExporter()
        # visitor.visit(form)
        # visitor.data
        from invenio_workflows.models import BibWorkflowObject
        from flask.ext.login import current_user
        myobj = BibWorkflowObject.create_object(id_user=current_user.get_id())
        myobj.set_data(form.data)
        # Start workflow. delayed=True will execute the workflow in the
        # background using, for example, Celery.
        myobj.start_workflow("demoworkflow", delayed=True)
        return render_template('forms/form_demo_success.html', form=form)
    return render_template('forms/form_demo.html', form=form, **ctx)
Exemplo n.º 4
0
    def __init__(self, workflow_object, type=None, user_id=None):
        """Init."""
        self.workflow_object = workflow_object
        if not workflow_object:
            self.files = []
            self.drafts = {}
            self.type = self.get_type(type)
            self.title = ""
            self.sips = []

            self.workflow_object = BibWorkflowObject.create_object(id_user=user_id)
            # Ensure default data is set for all objects.
            self.update()
        else:
            self.__setstate__(workflow_object.get_data())
        self.engine = None
    def __init__(self, workflow_object, type=None, user_id=None):
        """Init."""
        self.workflow_object = workflow_object
        if not workflow_object:
            self.files = []
            self.drafts = {}
            self.type = self.get_type(type)
            self.title = ''
            self.sips = []

            self.workflow_object = BibWorkflowObject.create_object(
                id_user=user_id, )
            # Ensure default data is set for all objects.
            self.update()
        else:
            self.__setstate__(workflow_object.get_data())
        self.engine = None
Exemplo n.º 6
0
def run_harvest(workflow, **kwargs):
    """Run given harvesting workflow in Celery."""
    from invenio.base.globals import cfg
    from invenio_workflows.models import BibWorkflowObject

    args = {
        "workflow": workflow
    }
    args.update(**kwargs)

    data = BibWorkflowObject.create_object()
    extra_data = data.get_extra_data()
    extra_data["args"] = args
    extra_data["config"] = cfg["HARVESTER_WORKFLOWS_CONFIG"].get(workflow, {})
    data.set_extra_data(extra_data)
    data.set_data({})
    data.save()
    data.start_workflow(workflow, delayed=True)
Exemplo n.º 7
0
def submitupdate():
    """Form action handler for INSPIRE author update form."""
    from inspirehep.modules.forms.utils import DataExporter
    from invenio_workflows.models import BibWorkflowObject
    from flask.ext.login import current_user
    form = AuthorUpdateForm(formdata=request.form)
    visitor = DataExporter()
    visitor.visit(form)
    myobj = BibWorkflowObject.create_object(id_user=current_user.get_id())
    myobj.set_data(visitor.data)
    # Start workflow. delayed=True will execute the workflow in the
    # background using, for example, Celery.
    myobj.start_workflow("authorupdate", delayed=True)

    ctx = {
        "inspire_url": get_inspire_url(visitor.data)
    }

    return render_template('authors/forms/update_success.html', **ctx)
Exemplo n.º 8
0
    def test_restart_failed_workflow(self):
        """Test restarting workflow for given workflow id."""
        from invenio_workflows.models import (BibWorkflowObject, ObjectVersion)
        from invenio_workflows.engine import WorkflowStatus
        from invenio_workflows.api import start, start_by_oids
        from invenio_workflows.errors import WorkflowError

        initial_data = BibWorkflowObject.create_object()
        initial_data.set_data(1)
        initial_data.save()

        self.assertRaises(WorkflowError,
                          start,
                          workflow_name="demo_workflow_error",
                          data=[initial_data],
                          module_name="unit_tests")
        self.assertEqual(initial_data.version, ObjectVersion.ERROR)

        restarted_workflow = start_by_oids("demo_workflow",
                                           oids=[initial_data.id],
                                           module_name="unit_tests")
        self.assertEqual(initial_data.version, ObjectVersion.WAITING)
        self.assertEqual(restarted_workflow.status, WorkflowStatus.HALTED)