本文整理汇总了Python中invenio.modules.workflows.models.BibWorkflowObject类的典型用法代码示例。如果您正苦于以下问题:Python BibWorkflowObject类的具体用法?Python BibWorkflowObject怎么用?Python BibWorkflowObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BibWorkflowObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_logging_for_workflow_objects_without_workflow
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
示例2: delete_self_and_stop_processing
def delete_self_and_stop_processing(obj, eng):
"""Delete both versions of itself and stops the workflow."""
from invenio.modules.workflows.models import BibWorkflowObject
# delete snapshot created with original data
initial_obj = BibWorkflowObject.query.filter(
BibWorkflowObject.id_parent == obj.id
).one()
BibWorkflowObject.delete(initial_obj.id)
# delete self
BibWorkflowObject.delete(obj.id)
eng.skipToken()
示例3: TestWorkflowModels
class TestWorkflowModels(InvenioTestCase):
"""Test meant for testing the models available."""
def setUp(self):
"""Setup tests."""
from invenio.modules.workflows.models import BibWorkflowObject, \
Workflow
from uuid import uuid1 as new_uuid
self.workflow = Workflow(name='test_workflow', uuid=new_uuid(),
id_user=0, module_name="Unknown")
self.bibworkflowobject = BibWorkflowObject(workflow=self.workflow)
self.create_objects([self.workflow, self.bibworkflowobject])
def tearDown(self):
"""Clean up tests."""
self.delete_objects([self.workflow, self.bibworkflowobject])
def test_deleting_workflow(self):
"""Test deleting workflow."""
from invenio.modules.workflows.models import BibWorkflowObject, \
Workflow
bwo_id = self.bibworkflowobject.id
# delete workflow
Workflow.delete(self.workflow.uuid)
# assert bibworkflowobject is deleted
self.assertFalse(
db.session.query(
BibWorkflowObject.query.filter(
BibWorkflowObject.id == bwo_id).exists()).scalar())
def test_deleting_bibworkflowobject(self):
"""Test deleting workflowobject."""
from invenio.modules.workflows.models import Workflow
w_uuid = self.workflow.uuid
# delete bibworkflowobject
self.bibworkflowobject.delete(self.bibworkflowobject.id)
# assert workflow is not deleted
self.assertTrue(
db.session.query(
Workflow.query.filter(
Workflow.uuid == w_uuid).exists()).scalar())
示例4: test_restart_failed_workflow
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)
示例5: _start_workflow
def _start_workflow(obj, eng):
myobject = BibWorkflowObject.create_object_revision(obj,
version=ObjectVersion.INITIAL,
data_type="record")
workflow_id = start_delayed(workflow_to_run,
data=[myobject],
stop_on_error=True,
**kwargs)
eng.log.info("Workflow launched")
try:
eng.extra_data["_workflow_ids"].append(workflow_id)
except KeyError:
eng.extra_data["_workflow_ids"] = [workflow_id]
try:
eng.extra_data["_nb_workflow"] += 1
except KeyError:
eng.extra_data["_nb_workflow"] = 1
if "_nb_workflow_failed" not in eng.extra_data:
eng.extra_data["_nb_workflow_failed"] = 0
if "_nb_workflow_finish" not in eng.extra_data:
eng.extra_data["_nb_workflow_finish"] = 0
if "_uuid_workflow_crashed" not in eng.extra_data:
eng.extra_data["_uuid_workflow_crashed"] = []
示例6: test_workflows_tasks_chained
def test_workflows_tasks_chained(self):
"""Test delayed workflows in delayed workflow."""
from invenio.modules.workflows.models import BibWorkflowObject
from invenio.modules.workflows.api import start_delayed
from invenio.modules.workflows.worker_result import uuid_to_workflow
test_object = BibWorkflowObject()
test_object.set_data(22)
test_object.save()
async = start_delayed("test_workflow_workflows", [test_object], module_name="unit_tests")
engine = async.get(uuid_to_workflow)
from invenio.modules.workflows.engine import WorkflowStatus
self.assertEqual(21, engine.get_extra_data()["_nb_workflow_finish"])
self.assertEqual(0, engine.get_extra_data()["_nb_workflow_failed"])
self.assertEqual(WorkflowStatus.COMPLETED, engine.status)
示例7: demoform
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.modules.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)
示例8: test_logging_for_workflow_objects_without_workflow
def test_logging_for_workflow_objects_without_workflow(self):
"""Test run a virtual object out of a workflow for test purpose."""
from invenio.modules.workflows.models import (BibWorkflowObject,
BibWorkflowObjectLog,
ObjectVersion)
initial_data = 20
obj_init = BibWorkflowObject(id_workflow=11,
version=ObjectVersion.INITIAL)
obj_init.set_data(initial_data)
obj_init.save()
err_msg = "This is an error message"
info_msg = "This is an info message"
obj_init.log.info(info_msg)
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!
# debug_msg = "This is a debug message"
# obj_init.log.debug(debug_msg)
obj_init.save()
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 == info_msg and messages_found == 0:
messages_found += 1
elif current_obj.message == err_msg and messages_found == 1:
messages_found += 1
self.assertEqual(2, messages_found)
示例9: test_object_creation_halt
def test_object_creation_halt(self):
"""Test status of object before/after workflow.
When created before calling API, with "low" test-data that will
make the workflow halt.
"""
from invenio.modules.workflows.models import (BibWorkflowObject,
ObjectVersion)
from invenio.modules.workflows.api import start
from invenio.modules.workflows.engine import WorkflowStatus
test_object = BibWorkflowObject()
test_object.set_data(2)
test_object.save()
self.assertEqual(ObjectVersion.INITIAL, test_object.version)
self.assertEqual(None, test_object.id_parent)
self.assertEqual(2, test_object.get_data())
engine = start('test_workflow', [test_object],
module_name="unit_tests")
self.assertEqual(2, test_object.get_data())
self.assertEqual(ObjectVersion.WAITING, test_object.version)
self.assertEqual(WorkflowStatus.HALTED, engine.status)
示例10: test_object_creation_complete
def test_object_creation_complete(self):
"""
Test status of object before/after workflow.
When created before calling API, with "high" test-data that will
make the workflow complete.
"""
from invenio.modules.workflows.models import (BibWorkflowObject,
ObjectVersion)
from invenio.modules.workflows.engine import WorkflowStatus
from invenio.modules.workflows.api import start
test_object = BibWorkflowObject()
test_object.set_data(20)
test_object.save()
self.assertEqual(ObjectVersion.INITIAL, test_object.version)
self.assertEqual(None, test_object.id_parent)
self.assertEqual(20, test_object.get_data())
engine = start('test_workflow', [test_object],
module_name="unit_tests")
self.assertEqual(38, test_object.get_data())
self.assertEqual(None, test_object.id_parent)
self.assertEqual(WorkflowStatus.COMPLETED, engine.status)
self.assertEqual(ObjectVersion.COMPLETED, test_object.version)
示例11: test_workflow_without_workflow_object_saved
def test_workflow_without_workflow_object_saved(self):
"""Test that the logic tasks work correctly."""
from invenio.modules.workflows.models import BibWorkflowObject
from invenio.modules.workflows.api import start, start_by_wid
test_object = BibWorkflowObject()
test_object.set_data(0)
test_object.save()
workflow = start('test_workflow_logic', [test_object], module_name="unit_tests")
self.assertEqual(5, test_object.get_data())
self.assertEqual("lt9", test_object.get_extra_data()["test"])
start_by_wid(workflow.uuid)
test_object.delete(test_object.id)
示例12: test_init_harvesting
def test_init_harvesting(self):
"""Test harvesting."""
from ..tasks.harvesting import init_harvesting
from invenio.modules.workflows.api import start
from invenio.modules.workflows.models import BibWorkflowObject
my_test_obj = BibWorkflowObject()
my_test_obj.set_data([2])
my_test_obj.save()
engine = start("test_workflow_dummy", my_test_obj, module_name="unit_tests")
my_test_obj.data = my_test_obj.get_data()
my_test_obj.extra_data = my_test_obj.get_extra_data()
engine.set_extra_data_params(options={"test": True})
engine.extra_data = engine.get_extra_data()
init_harvesting(my_test_obj, engine)
self.assertTrue(engine.get_extra_data()["options"]["test"])
示例13: setUp
def setUp(self):
"""Setup tests."""
from invenio.modules.workflows.models import BibWorkflowObject, \
Workflow
from uuid import uuid1 as new_uuid
self.workflow = Workflow(name='test_workflow', uuid=new_uuid(),
id_user=0, module_name="Unknown")
self.bibworkflowobject = BibWorkflowObject(workflow=self.workflow)
self.create_objects([self.workflow, self.bibworkflowobject])
示例14: test_workflow_object_creation
def test_workflow_object_creation(self):
"""Test to see if the right snapshots or object versions are created."""
from invenio.modules.workflows.models import (BibWorkflowObject,
ObjectVersion)
from invenio.modules.workflows.api import start
initial_data = 22
final_data = 40
test_object = BibWorkflowObject()
test_object.set_data(initial_data)
test_object.save()
workflow = start(workflow_name="test_workflow",
data=[test_object],
module_name="unit_tests")
# Get parent object of the workflow we just ran
initial_object = BibWorkflowObject.query.filter(BibWorkflowObject.id_parent == test_object.id).one()
all_objects = BibWorkflowObject.query.filter(
BibWorkflowObject.id_workflow == workflow.uuid
).order_by(BibWorkflowObject.id).all()
# There should only be 2 objects (initial, final)
self.assertEqual(2, len(all_objects))
self.assertEqual(test_object.id, initial_object.id_parent)
self.assertEqual(ObjectVersion.INITIAL, initial_object.version)
self.assertEqual(initial_data, initial_object.get_data())
self.assertEqual(final_data, test_object.get_data())
self.assertEqual(ObjectVersion.COMPLETED, test_object.version)
示例15: test_data_object_created_outside
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)