def test_data_object_created_outside(self): from invenio.modules.workflows.models import BibWorkflowObject from invenio.modules.workflows.api import start obj = BibWorkflowObject() initial_data = {'data': 20} obj.set_data(initial_data) obj._update_db() final_data = {'data': 41} workflow = start(workflow_name="test_workflow", data=[obj], module_name="unit_tests") # Keep id for cleanup after self.id_workflows.append(workflow.uuid) # Get parent object of the workflow we just ran initial_object = BibWorkflowObject.query.filter( BibWorkflowObject.id_workflow == workflow.uuid, BibWorkflowObject.id_parent == None) # noqa E711 all_objects = BibWorkflowObject.query.filter( BibWorkflowObject.id_workflow == workflow.uuid) # There should only be 2 objects (initial, final) self.assertEqual(all_objects.count(), 2) self.assertEqual(obj.get_data(), final_data) self.assertEqual(obj.version, CFG_OBJECT_VERSION.FINAL) self.assertEqual(obj.id_parent, initial_object[0].id) self.assertEqual(initial_object[0].get_data(), initial_data)
def test_logging_for_workflow_objects_without_workflow(self): """This test run a virtual object out of a workflow for test purpose, this object will log several things""" from invenio.modules.workflows.models import (BibWorkflowObject, BibWorkflowObjectLog) 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() obj_init.save() obj_init.log.info("I am a test object") obj_init.log.error("This is an error message") # FIXME: loglevels are simply overwritten somewhere in Celery # even if Celery is not being "used". # # This means loglevel.DEBUG is NOT working at the moment! obj_init.log.debug("This is a debug message") obj_init._update_db() obj_test = BibWorkflowObjectLog.query.filter( BibWorkflowObjectLog.id_object == obj_init.id).all() messages_found = 0 for current_obj in obj_test: if current_obj.message == "I am a test object" \ and messages_found == 0: messages_found += 1 elif current_obj.message == "This is an error message" \ and messages_found == 1: messages_found += 1 elif current_obj.message == "This is a debug message" \ and messages_found == 2: messages_found += 1 self.assertEqual(messages_found, 2) # FIXME: should be 3 when debug works
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")