def test_form_functions(self): from invenio_deposit.loader import \ deposition_metadata from invenio_deposit import forms from invenio.webdeposit_workflow import DepositionWorkflow from invenio.webdeposit_utils import get_form, \ get_form_status, set_form_status, CFG_DRAFT_STATUS from invenio.modules.workflows.models import Workflow for metadata in deposition_metadata.values(): for wf_function in metadata['workflow']: if 'render_form' == wf_function.func_name: break user_id = self.login_user() deposition_workflow = DepositionWorkflow(deposition_type='Article', user_id=user_id) uuid = deposition_workflow.get_uuid() # Run the workflow to insert a form in the db deposition_workflow.run() # There is only one form in the db workflows = Workflow.get(module_name='webdeposit') assert len(workflows.all()) == 1 assert len(workflows[0].extra_data['drafts']) == 1 # Test that guest user doesn't have access to the form form = get_form(0, uuid=uuid) assert form is None # Test that the current form has the right type form = get_form(user_id, uuid=deposition_workflow.get_uuid()) assert isinstance(form, forms['ArticleForm']) assert str(uuid) == str(deposition_workflow.get_uuid()) # Test that form is returned with get_form function form = get_form(user_id, deposition_workflow.get_uuid()) assert form is not None form = get_form(user_id, deposition_workflow.get_uuid(), step=0) assert form is not None # Second step doesn't have a form form = get_form(user_id, deposition_workflow.get_uuid(), step=1) assert form is None form_status = get_form_status(user_id, deposition_workflow.get_uuid()) assert form_status == CFG_DRAFT_STATUS['unfinished'] form_status = get_form_status(user_id, deposition_workflow.get_uuid(), step=2) assert form_status is None set_form_status(user_id, uuid, CFG_DRAFT_STATUS['finished']) form_status = get_form_status(user_id, deposition_workflow.get_uuid()) assert form_status == CFG_DRAFT_STATUS['finished']
def wait(obj, eng): user_id = obj.data['user_id'] uuid = eng.uuid from invenio.webdeposit_utils import CFG_DRAFT_STATUS, get_form_status status = get_form_status(user_id, uuid) if status == CFG_DRAFT_STATUS['unfinished']: # If form is unfinished stop the workflow eng.halt('Waiting for form submission.') else: # If form is completed, continue with next step eng.jumpCallForward(1)
def check_status(uuid): form_status = get_form_status(current_user.get_id(), uuid) return jsonify({"status": form_status})
def test_form_functions(self): from invenio.webdeposit_load_deposition_types import \ deposition_metadata from invenio.webdeposit_load_forms import forms from invenio.webdeposit_model import WebDepositDraft from invenio.webdeposit_workflow import DepositionWorkflow from invenio.webdeposit_utils import get_current_form, get_form, \ get_form_status, CFG_DRAFT_STATUS from invenio.sqlalchemyutils import db from invenio.webdeposit_workflow_utils import render_form, \ wait_for_submission from invenio.cache import cache for metadata in deposition_metadata.values(): for wf_function in metadata['workflow']: if 'render_form' == wf_function.func_name: break from invenio.webuser_flask import login_user login_user(1) wf = [render_form(forms.values()[0]), wait_for_submission()] deposition_workflow = DepositionWorkflow( deposition_type='TestWorkflow', workflow=wf, user_id=1) uuid = deposition_workflow.get_uuid() cache.delete_many("1:current_deposition_type", "1:current_uuid") cache.add("1:current_deposition_type", 'TestWorkflow') cache.add("1:current_uuid", uuid) # Run the workflow to insert a form to the db deposition_workflow.run() # There is only one form in the db drafts = db.session.query(WebDepositDraft) assert len(drafts.all()) == 1 # Test that guest user doesn't have access to the form uuid, form = get_current_form(0, deposition_type='TestWorkflow', uuid=uuid) assert form is None # Test that the current form has the right type uuid, form = get_current_form(1, deposition_type='TestWorkflow', uuid=deposition_workflow.get_uuid()) assert isinstance(form, forms.values()[0]) assert str(uuid) == str(deposition_workflow.get_uuid()) # Test that form is returned with get_form function form = get_form(1, deposition_workflow.get_uuid()) assert form is not None form = get_form(1, deposition_workflow.get_uuid(), step=0) assert form is not None # Second step doesn't have a form form = get_form(1, deposition_workflow.get_uuid(), step=1) assert form is None form_status = get_form_status(1, deposition_workflow.get_uuid()) assert form_status == CFG_DRAFT_STATUS['unfinished'] form_status = get_form_status(1, deposition_workflow.get_uuid(), step=2) assert form_status is None db.session.query(WebDepositDraft).\ update({'status': CFG_DRAFT_STATUS['finished']}) form_status = get_form_status(1, deposition_workflow.get_uuid()) assert form_status == CFG_DRAFT_STATUS['finished']