def test_restart_failed_workflow(self): """Test restarting workflow for given workflow id.""" from invenio.modules.workflows.models import (BibWorkflowObject, ObjectVersion) from invenio.modules.workflows.engine import WorkflowStatus from invenio.modules.workflows.api import start, start_by_oids from invenio.modules.workflows.errors import WorkflowError initial_data = BibWorkflowObject.create_object() initial_data.set_data(1) initial_data.save() self.assertRaises( WorkflowError, start, workflow_name="test_workflow_error", data=[initial_data], module_name="unit_tests" ) self.assertEqual(initial_data.version, ObjectVersion.ERROR) restarted_workflow = start_by_oids("test_workflow", oids=[initial_data.id], module_name="unit_tests") self.assertEqual(initial_data.version, ObjectVersion.WAITING) self.assertEqual(restarted_workflow.status, WorkflowStatus.HALTED)
def test_restart_failed_workflow(self): """Test restarting workflow for given workflow id.""" from invenio.modules.workflows.models import (BibWorkflowObject, ObjectVersion) from invenio.modules.workflows.engine import WorkflowStatus from invenio.modules.workflows.api import start, start_by_oids from invenio.modules.workflows.errors import WorkflowError initial_data = BibWorkflowObject.create_object() initial_data.set_data(1) initial_data.save() self.assertRaises( WorkflowError, start, workflow_name="test_workflow_error", data=[initial_data], module_name="unit_tests" ) self.assertEqual(initial_data.version, ObjectVersion.ERROR) restarted_workflow = start_by_oids("test_workflow", oids=[initial_data.id], module_name="unit_tests") self.assertEqual(initial_data.version, ObjectVersion.WAITING) self.assertEqual(restarted_workflow.status, WorkflowStatus.HALTED)
def test_workflow_for_running_object(self): """Test starting workflow with running object given""" from invenio.modules.workflows.models import BibWorkflowObject from invenio.modules.workflows.api import start_by_oids initial_data = {'data': 20} obj_init = BibWorkflowObject(id_workflow=11, version=CFG_OBJECT_VERSION.INITIAL) obj_init.set_data(initial_data) obj_init._update_db() running_data = {'data': 26} obj_running = BibWorkflowObject(id_workflow=11, id_parent=obj_init.id, version=CFG_OBJECT_VERSION.RUNNING) obj_running.set_data(running_data) obj_running._update_db() workflow = start_by_oids('test_workflow', [obj_running.id], module_name="unit_tests") final_data = {u'data': 41} objects = BibWorkflowObject.query.filter( BibWorkflowObject.id_workflow == workflow.uuid, BibWorkflowObject.id_parent == None) # noqa E711 all_objects = BibWorkflowObject.query.filter( BibWorkflowObject.id_workflow == workflow.uuid) self.assertEqual(all_objects.count(), 2) # Check the workflow execution self._check_workflow_execution(objects, initial_data, final_data) # Check copied INITIAL object self.assertEqual(obj_init.get_data(), objects[0].get_data()) # Check if first object were untuched self.assertEqual(obj_init.id_workflow, "11") objects = BibWorkflowObject.query.filter( BibWorkflowObject.id == obj_running.id) self.assertEqual(objects.count(), 0)
def test_workflow_for_halted_object(self): """Test starting workflow with halted object given""" from invenio.modules.workflows.models import BibWorkflowObject from invenio.modules.workflows.api import start_by_oids initial_data = {'data': 1} obj_init = BibWorkflowObject(id_workflow=123, version=CFG_OBJECT_VERSION.INITIAL) obj_init.set_data(initial_data) obj_init._update_db() halted_data = {'data': 1} obj_halted = BibWorkflowObject(id_workflow=123, id_parent=obj_init.id, version=CFG_OBJECT_VERSION.HALTED) obj_halted.set_data(halted_data) obj_halted._update_db() workflow = start_by_oids('test_workflow', [obj_halted.id], module_name="unit_tests") final_data = {'data': 2} objects = BibWorkflowObject.query.filter( BibWorkflowObject.id_workflow == workflow.uuid, BibWorkflowObject.id_parent == None) # noqa E711 all_objects = BibWorkflowObject.query.filter( BibWorkflowObject.id_workflow == workflow.uuid) self.assertEqual(all_objects.count(), 2) # Check the workflow execution self._check_workflow_execution(objects, halted_data, final_data) # Check copied INITIAL object self.assertEqual(obj_halted.get_data(), objects[0].get_data()) # Check if first object were untached self.assertEqual(obj_init.id_workflow, "123") self.assertEqual(obj_halted.id_workflow, "123")
def test_workflow_for_running_object(self): """Test starting workflow with running object given""" from invenio.modules.workflows.models import BibWorkflowObject from invenio.modules.workflows.api import start_by_oids initial_data = {'data': 20} obj_init = BibWorkflowObject(id_workflow=11, version=CFG_OBJECT_VERSION.INITIAL) obj_init.set_data(initial_data) obj_init._update_db() running_data = {'data': 26} obj_running = BibWorkflowObject(id_workflow=11, id_parent=obj_init.id, version=CFG_OBJECT_VERSION.RUNNING) obj_running.set_data(running_data) obj_running._update_db() workflow = start_by_oids('test_workflow', [obj_running.id], module_name="unit_tests") final_data = {u'data': 41} objects = BibWorkflowObject.query.filter( BibWorkflowObject.id_workflow == workflow.uuid, BibWorkflowObject.id_parent == None) # noqa E711 all_objects = BibWorkflowObject.query.filter( BibWorkflowObject.id_workflow == workflow.uuid) self.assertEqual(all_objects.count(), 2) # Check the workflow execution self._check_workflow_execution(objects, initial_data, final_data) # Check copied INITIAL object self.assertEqual(obj_init.get_data(), objects[0].get_data()) # Check if first object were untuched self.assertEqual(obj_init.id_workflow, "11") objects = BibWorkflowObject.query.filter( BibWorkflowObject.id == obj_running.id) self.assertEqual(objects.count(), 0)
def test_workflow_for_halted_object(self): """Test starting workflow with halted object given""" from invenio.modules.workflows.models import BibWorkflowObject from invenio.modules.workflows.api import start_by_oids initial_data = {'data': 1} obj_init = BibWorkflowObject(id_workflow=123, version=CFG_OBJECT_VERSION.INITIAL) obj_init.set_data(initial_data) obj_init._update_db() halted_data = {'data': 1} obj_halted = BibWorkflowObject(id_workflow=123, id_parent=obj_init.id, version=CFG_OBJECT_VERSION.HALTED) obj_halted.set_data(halted_data) obj_halted._update_db() workflow = start_by_oids('test_workflow', [obj_halted.id], module_name="unit_tests") final_data = {'data': 2} objects = BibWorkflowObject.query.filter( BibWorkflowObject.id_workflow == workflow.uuid, BibWorkflowObject.id_parent == None) # noqa E711 all_objects = BibWorkflowObject.query.filter( BibWorkflowObject.id_workflow == workflow.uuid) self.assertEqual(all_objects.count(), 2) # Check the workflow execution self._check_workflow_execution(objects, halted_data, final_data) # Check copied INITIAL object self.assertEqual(obj_halted.get_data(), objects[0].get_data()) # Check if first object were untached self.assertEqual(obj_init.id_workflow, "123") self.assertEqual(obj_halted.id_workflow, "123")
def test_workflow_for_running_object(self): """Test workflow with running object given and watch it fail.""" from invenio.modules.workflows.models import (BibWorkflowObject, ObjectVersion) from invenio.modules.workflows.api import start_by_oids from invenio.modules.workflows.errors import WorkflowObjectVersionError obj_running = BibWorkflowObject() obj_running.set_data(1234) obj_running.save(version=ObjectVersion.RUNNING) try: start_by_oids('test_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('test_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('test_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)
def test_workflow_for_running_object(self): """Test workflow with running object given and watch it fail.""" from invenio.modules.workflows.models import (BibWorkflowObject, ObjectVersion) from invenio.modules.workflows.api import start_by_oids from invenio.modules.workflows.errors import WorkflowObjectVersionError obj_running = BibWorkflowObject() obj_running.set_data(1234) obj_running.save(version=ObjectVersion.RUNNING) try: start_by_oids('test_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('test_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('test_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)