def test_workflow_creation(self): from invenio_deposit.loader import \ deposition_metadata from invenio.modules.workflows.models import Workflow from invenio.webdeposit_workflow import DepositionWorkflow from invenio.webdeposit_utils import get_latest_or_new_workflow, \ get_workflow, delete_workflow, InvenioWebDepositNoDepositionType user_id = self.login_user() number_of_dep_types = len(deposition_metadata) # Test for every deposition type for deposition_type in deposition_metadata.keys(): # New workflow is created workflow = get_latest_or_new_workflow(deposition_type, user_id=user_id) self.assertTrue(workflow is not None) # The just created workflow is retrieved as latest workflow2 = get_latest_or_new_workflow(deposition_type, user_id=user_id) self.assertTrue(workflow2 is not None) self.assertEqual(str(workflow2.uuid), str(workflow.uuid)) # and also retrieved with its uuid workflow = get_workflow(workflow.uuid, deposition_type) self.assertTrue(workflow is not None) # Test get_workflow function with random arguments deposition_type = deposition_metadata.keys()[-1] workflow = get_workflow('some_uuid_that_doesnt_exist', deposition_type) self.assertTrue(workflow is None) # Create workflow without using webdeposit_utils workflow = DepositionWorkflow(deposition_type=deposition_type, user_id=1) self.assertRaises(InvenioWebDepositNoDepositionType, get_workflow, workflow.get_uuid(), 'deposition_type_that_doesnt_exist') # Test that the retrieved workflow is the same and not None workflow2 = get_workflow(workflow.get_uuid(), deposition_type) self.assertTrue(workflow2 is not None) self.assertEqual(workflow2.get_uuid(), workflow.get_uuid()) # Check the number of created workflows count_workflows = Workflow.get( Workflow.module_name == "webdeposit" ).count() self.assertEqual(count_workflows, number_of_dep_types + 1) uuid = workflow.get_uuid() delete_workflow(1, uuid) workflow = get_workflow(uuid, deposition_type) self.assertTrue(workflow is None)
def test_workflow_creation(self): from invenio_deposit.loader import \ deposition_metadata from invenio.modules.workflows.models import Workflow from invenio.webdeposit_workflow import DepositionWorkflow from invenio.webdeposit_utils import get_latest_or_new_workflow, \ get_workflow, delete_workflow, InvenioWebDepositNoDepositionType user_id = self.login_user() number_of_dep_types = len(deposition_metadata) # Test for every deposition type for deposition_type in deposition_metadata.keys(): # New workflow is created workflow = get_latest_or_new_workflow(deposition_type, user_id=user_id) self.assertTrue(workflow is not None) # The just created workflow is retrieved as latest workflow2 = get_latest_or_new_workflow(deposition_type, user_id=user_id) self.assertTrue(workflow2 is not None) self.assertEqual(str(workflow2.uuid), str(workflow.uuid)) # and also retrieved with its uuid workflow = get_workflow(workflow.uuid, deposition_type) self.assertTrue(workflow is not None) # Test get_workflow function with random arguments deposition_type = deposition_metadata.keys()[-1] workflow = get_workflow('some_uuid_that_doesnt_exist', deposition_type) self.assertTrue(workflow is None) # Create workflow without using webdeposit_utils workflow = DepositionWorkflow(deposition_type=deposition_type, user_id=1) self.assertRaises(InvenioWebDepositNoDepositionType, get_workflow, workflow.get_uuid(), 'deposition_type_that_doesnt_exist') # Test that the retrieved workflow is the same and not None workflow2 = get_workflow(workflow.get_uuid(), deposition_type) self.assertTrue(workflow2 is not None) self.assertEqual(workflow2.get_uuid(), workflow.get_uuid()) # Check the number of created workflows count_workflows = Workflow.get( Workflow.module_name == "webdeposit").count() self.assertEqual(count_workflows, number_of_dep_types + 1) uuid = workflow.get_uuid() delete_workflow(1, uuid) workflow = get_workflow(uuid, deposition_type) self.assertTrue(workflow is None)
def setUp(self): from random import randint from invenio.modules.apikeys import create_new_web_api_key, \ get_available_web_api_keys # FIXME unknown import 'deposition_metadata' from invenio_deposit.loader import deposition_metadata # self.clear_tables() create_new_web_api_key(1, key_description='webdeposit_api_testing') keys = get_available_web_api_keys(1) self.apikey = keys[0].id # Test random deposition self.deposition = deposition_metadata.keys()[ randint(0, len(deposition_metadata.keys()) - 1)] super(TestWebDepositAPI, self).setUp()
def test_deposit_files(self): from flask import current_app, url_for from invenio_deposit.loader import \ deposition_metadata from invenio.modules.workflows.models import Workflow from invenio.webdeposit_utils import create_workflow, deposit_files, \ get_latest_or_new_workflow user_id = self.login_user() # Test for every deposition type for deposition_type in deposition_metadata.keys(): workflow = create_workflow(deposition_type, user_id) uuid = workflow.get_uuid() pdffile = make_pdf_fixture("test.pdf") with current_app.test_request_context( url_for( 'webdeposit.upload_file', deposition_type=deposition_type, uuid=uuid ), method='POST', data={ 'file': pdffile, 'name': 'test.pdf', }): deposit_files(user_id, deposition_type, uuid, preingest=True) workflow = get_latest_or_new_workflow(deposition_type, user_id) workflow.run() draft = Workflow.get( Workflow.id_user == user_id, Workflow.uuid == uuid ).one().extra_data['drafts'][0] assert len(draft['form_values']['files']) == 1 filemeta = draft['form_values']['files'][0] assert filemeta['name'] == 'test.pdf' assert filemeta['content_type'] == 'application/pdf'
def test_deposit_files(self): from flask import current_app, url_for from invenio_deposit.loader import \ deposition_metadata from invenio.modules.workflows.models import Workflow from invenio.webdeposit_utils import create_workflow, deposit_files, \ get_latest_or_new_workflow user_id = self.login_user() # Test for every deposition type for deposition_type in deposition_metadata.keys(): workflow = create_workflow(deposition_type, user_id) uuid = workflow.get_uuid() pdffile = make_pdf_fixture("test.pdf") with current_app.test_request_context(url_for( 'webdeposit.upload_file', deposition_type=deposition_type, uuid=uuid), method='POST', data={ 'file': pdffile, 'name': 'test.pdf', }): deposit_files(user_id, deposition_type, uuid, preingest=True) workflow = get_latest_or_new_workflow(deposition_type, user_id) workflow.run() draft = Workflow.get( Workflow.id_user == user_id, Workflow.uuid == uuid).one().extra_data['drafts'][0] assert len(draft['form_values']['files']) == 1 filemeta = draft['form_values']['files'][0] assert filemeta['name'] == 'test.pdf' assert filemeta['content_type'] == 'application/pdf'
def test_record_creation(self): import os from wtforms import TextAreaField from datetime import datetime from invenio.legacy.search_engine import record_exists from invenio.cache import cache from invenio.config import CFG_PREFIX from invenio.modules.workflows.models import Workflow from invenio.modules.workflows.config import CFG_WORKFLOW_STATUS from invenio.modules.scheduler.models import SchTASK from invenio.webdeposit_utils import get_form, create_workflow, \ set_form_status, CFG_DRAFT_STATUS from invenio_deposit.loader import \ deposition_metadata from invenio.webdeposit_workflow_utils import \ create_record_from_marc from invenio.modules.record.api import get_record user_id = self.login_user() for deposition_type in deposition_metadata.keys(): deposition = create_workflow(deposition_type, user_id) assert deposition is not None # Check if deposition creates a record create_rec = create_record_from_marc() function_exists = False for workflow_function in deposition.workflow: if create_rec.func_code == workflow_function .func_code: function_exists = True if not function_exists: # if a record is not created, # continue with the next deposition continue uuid = deposition.get_uuid() cache.delete_many("1:current_deposition_type", "1:current_uuid") cache.add("1:current_deposition_type", deposition_type) cache.add("1:current_uuid", uuid) # Run the workflow deposition.run() # Create form's json based on the field name form = get_form(user_id, uuid=uuid) webdeposit_json = {} # Fill the json with dummy data for field in form: if isinstance(field, TextAreaField): # If the field is associated with a marc field if field.has_recjson_key() or field.has_cook_function(): webdeposit_json[field.name] = "test " + field.name draft = dict(form_type=form.__class__.__name__, form_values=webdeposit_json, step=0, # dummy step status=CFG_DRAFT_STATUS['finished'], timestamp=str(datetime.now())) # Add a draft for the first step Workflow.set_extra_data(user_id=user_id, uuid=uuid, key='drafts', value={0: draft}) workflow_status = CFG_WORKFLOW_STATUS.RUNNING while workflow_status != CFG_WORKFLOW_STATUS.COMPLETED: # Continue workflow deposition.run() set_form_status(user_id, uuid, CFG_DRAFT_STATUS['finished']) workflow_status = deposition.get_status() # Workflow is finished. Test if record is created recid = deposition.get_data('recid') assert recid is not None # Test that record id exists assert record_exists(recid) == 1 # Test that the task exists task_id = deposition.get_data('task_id') assert task_id is not None bibtask = SchTASK.query.filter(SchTASK.id == task_id).first() assert bibtask is not None # Run bibupload, bibindex, webcoll manually cmd = "%s/bin/bibupload %s" % (CFG_PREFIX, task_id) assert not os.system(cmd) rec = get_record(recid) marc = rec.legacy_export_as_marc() for field in form: if isinstance(field, TextAreaField): # If the field is associated with a marc field if field.has_recjson_key() or field.has_cook_function(): assert "test " + field.name in marc
def test_record_creation(self): import os from wtforms import TextAreaField from datetime import datetime from invenio.legacy.search_engine import record_exists from invenio.cache import cache from invenio.config import CFG_PREFIX from invenio.modules.workflows.models import Workflow from invenio.modules.workflows.config import CFG_WORKFLOW_STATUS from invenio.modules.scheduler.models import SchTASK from invenio.webdeposit_utils import get_form, create_workflow, \ set_form_status, CFG_DRAFT_STATUS from invenio_deposit.loader import \ deposition_metadata from invenio.webdeposit_workflow_utils import \ create_record_from_marc from invenio.modules.record.api import get_record user_id = self.login_user() for deposition_type in deposition_metadata.keys(): deposition = create_workflow(deposition_type, user_id) assert deposition is not None # Check if deposition creates a record create_rec = create_record_from_marc() function_exists = False for workflow_function in deposition.workflow: if create_rec.func_code == workflow_function.func_code: function_exists = True if not function_exists: # if a record is not created, # continue with the next deposition continue uuid = deposition.get_uuid() cache.delete_many("1:current_deposition_type", "1:current_uuid") cache.add("1:current_deposition_type", deposition_type) cache.add("1:current_uuid", uuid) # Run the workflow deposition.run() # Create form's json based on the field name form = get_form(user_id, uuid=uuid) webdeposit_json = {} # Fill the json with dummy data for field in form: if isinstance(field, TextAreaField): # If the field is associated with a marc field if field.has_recjson_key() or field.has_cook_function(): webdeposit_json[field.name] = "test " + field.name draft = dict( form_type=form.__class__.__name__, form_values=webdeposit_json, step=0, # dummy step status=CFG_DRAFT_STATUS['finished'], timestamp=str(datetime.now())) # Add a draft for the first step Workflow.set_extra_data(user_id=user_id, uuid=uuid, key='drafts', value={0: draft}) workflow_status = CFG_WORKFLOW_STATUS.RUNNING while workflow_status != CFG_WORKFLOW_STATUS.COMPLETED: # Continue workflow deposition.run() set_form_status(user_id, uuid, CFG_DRAFT_STATUS['finished']) workflow_status = deposition.get_status() # Workflow is finished. Test if record is created recid = deposition.get_data('recid') assert recid is not None # Test that record id exists assert record_exists(recid) == 1 # Test that the task exists task_id = deposition.get_data('task_id') assert task_id is not None bibtask = SchTASK.query.filter(SchTASK.id == task_id).first() assert bibtask is not None # Run bibupload, bibindex, webcoll manually cmd = "%s/bin/bibupload %s" % (CFG_PREFIX, task_id) assert not os.system(cmd) rec = get_record(recid) marc = rec.legacy_export_as_marc() for field in form: if isinstance(field, TextAreaField): # If the field is associated with a marc field if field.has_recjson_key() or field.has_cook_function(): assert "test " + field.name in marc