Skip to content

Commit

Permalink
workflow: merge updates, closes inspirehep#2294
Browse files Browse the repository at this point in the history
Signed-off-by: Antonio Cesarano <[email protected]>
Signed-off-by: Riccardo Candido <[email protected]>
  • Loading branch information
ammirate committed Oct 23, 2017
1 parent dcf02e0 commit 441f6ca
Show file tree
Hide file tree
Showing 15 changed files with 1,177 additions and 163 deletions.
1 change: 0 additions & 1 deletion inspirehep/modules/workflows/actions/hep_approval.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def resolve(obj, *args, **kwargs):

obj.extra_data["approved"] = approved
obj.remove_action()

obj.extra_data["user_action"] = value
obj.extra_data["upload_pdf"] = upload_pdf
obj.extra_data["core"] = value == "accept_core"
Expand Down
7 changes: 6 additions & 1 deletion inspirehep/modules/workflows/actions/merge_approval.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,9 @@ class MergeApproval(object):
@staticmethod
def resolve(obj, *args, **kwargs):
"""Resolve the action taken in the approval action."""
pass
obj.extra_data["approved"] = True
obj.extra_data["conflicts_solved_by_curator"] = True
obj.remove_action()
obj.save()
obj.continue_workflow(delayed=True)
return True
115 changes: 71 additions & 44 deletions inspirehep/modules/workflows/workflows/article.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from workflow.patterns.controlflow import (
IF,
IF_ELSE,
IF_NOT,
)

from inspire_dojson.hep import hep2marc
Expand All @@ -43,7 +42,6 @@
add_core,
halt_record,
is_record_relevant,
in_production_mode,
is_record_accepted,
reject_record,
is_experimental_paper,
Expand All @@ -54,6 +52,12 @@
refextract,
submission_fulltext_download,
)
from inspirehep.modules.workflows.tasks.merging import (
merge_articles,
put_root_in_extra_data,
update_record,
store_root,
)
from inspirehep.modules.workflows.tasks.classifier import (
classify_paper,
filter_core_keywords,
Expand Down Expand Up @@ -200,21 +204,6 @@
]


CHECK_IF_SUBMISSION_AND_ASK_FOR_APPROVAL = [
IF_ELSE(
is_record_relevant,
[halt_record(
action="hep_approval",
message="Submission halted for curator approval.",
)],
[
reject_record("Article automatically rejected"),
stop_processing
]
),
]


NOTIFY_NOT_ACCEPTED = [
IF(
is_submission,
Expand All @@ -234,6 +223,7 @@
context_factory=reply_ticket_context
),
close_ticket(ticket_id_key="ticket_id"),
mark('stop', True)
]


Expand Down Expand Up @@ -287,22 +277,6 @@
),
]

CHECK_IF_MERGE_AND_STOP_IF_SO = [
IF(
is_marked('is-update'),
[
IF_ELSE(
is_submission,
NOTIFY_ALREADY_EXISTING,
[
# halt_record(action="merge_approval"),
delete_self_and_stop_processing,
]
),
]
)
]


ADD_MARKS = [
IF(
Expand All @@ -327,6 +301,65 @@
]


MERGE_IF_UPDATE = [
put_root_in_extra_data,
IF(
is_marked('is-update'),
[
merge_articles,
mark('merged', True)
# TODO: save record with new non-conflicting merged fields
],
),
]


STOP_IF_EXISTING_SUBMISSION = [
IF(
is_submission,
IF(
is_marked('is-update'),
NOTIFY_ALREADY_EXISTING
)
)
]


HALT_FOR_APPROVAL = [
IF_ELSE(
is_record_relevant,
[
IF_ELSE(
article_exists,
halt_record(
action="merge_approval",
message="Submission halted for curator approval.",
),
halt_record(
action="hep_approval",
message="Submission halted for curator approval.",
),
)
],
# record not relevant
[
reject_record("Article automatically rejected"),
stop_processing
]
)
]


STORE_RECORD_AND_ROOT = [
IF_ELSE(
is_marked('is-update'),
update_record,
store_record
),
store_root,
]


class Article(object):
"""Article ingestion workflow for Literature collection."""
name = "HEP"
Expand All @@ -340,23 +373,17 @@ class Article(object):
ADD_MARKS +
DELETE_AND_STOP_IF_NEEDED +
ENHANCE_RECORD +
# TODO: Once we have a way to resolve merges, we should
# use that instead of stopping
CHECK_IF_MERGE_AND_STOP_IF_SO +
CHECK_IF_SUBMISSION_AND_ASK_FOR_APPROVAL +
STOP_IF_EXISTING_SUBMISSION +
MERGE_IF_UPDATE +
HALT_FOR_APPROVAL +
[
IF_ELSE(
is_record_accepted,
(
POSTENHANCE_RECORD +
STORE_RECORD_AND_ROOT +
SEND_TO_LEGACY_AND_WAIT +
NOTIFY_USER_OR_CURATOR +
[
# TODO: once legacy is out, this should become
# unconditional, and remove the SEND_TO_LEGACY_AND_WAIT
# steps
IF_NOT(in_production_mode, [store_record]),
]
NOTIFY_USER_OR_CURATOR
),
NOTIFY_NOT_ACCEPTED,
),
Expand Down
101 changes: 69 additions & 32 deletions tests/integration/workflows/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,49 +23,23 @@
from __future__ import absolute_import, division, print_function

import os
import sys

import re
import pytest
import requests_mock
import sys

from invenio_db import db
from invenio_workflows import workflow_object_class

from inspirehep.factory import create_app
from inspirehep.modules.workflows.models import (
WorkflowsAudit,
WorkflowsPendingRecord,
)

from inspirehep.modules.fixtures.collections import init_collections
from inspirehep.modules.fixtures.files import init_all_storage_paths
from inspirehep.modules.fixtures.users import init_users_and_permissions

# Use the helpers folder to store test helpers.
# See: http://stackoverflow.com/a/33515264/374865
sys.path.append(os.path.join(os.path.dirname(__file__), 'helpers'))


@pytest.fixture(autouse=True)
def cleanup_workflows_tables(small_app):
"""Delete the contents of the workflow tables after each test.
.. deprecated:: 2017-09-18
Tests that need to clean up should do so explicitly.
"""
with small_app.app_context():
obj_types = (
WorkflowsAudit.query.all(),
WorkflowsPendingRecord.query.all(),
workflow_object_class.query(),
)
for obj_type in obj_types:
for obj in obj_type:
obj.delete()

db.session.commit()

_es = small_app.extensions['invenio-search']
list(_es.delete(ignore=[404]))
list(_es.create(ignore=[404]))


@pytest.fixture
def workflow_app():
"""Flask application with no records and function scope.
Expand All @@ -85,8 +59,71 @@ def workflow_app():
'http://localhost:1234'
),
MAGPIE_API_URL="http://example.com/magpie",
WORKFLOWS_MATCH_REMOTE_SERVER_URL="http://legacy_search.endpoint/",
WTF_CSRF_ENABLED=False,
)

with app.app_context():
yield app


def drop_all(app):
db.drop_all()
_es = app.extensions['invenio-search']
list(_es.delete(ignore=[404]))


def create_all(app):
db.create_all()
_es = app.extensions['invenio-search']
list(_es.create(ignore=[400]))

init_all_storage_paths()
init_users_and_permissions()
init_collections()


@pytest.fixture(autouse=True)
def cleanup_workflows(workflow_app):
db.session.close_all()
drop_all(app=workflow_app)
create_all(app=workflow_app)


@pytest.fixture
def mocked_external_services(workflow_app):
with requests_mock.Mocker() as requests_mocker:
requests_mocker.register_uri(
requests_mock.ANY,
re.compile('.*(indexer|localhost).*'),
real_http=True,
)
requests_mocker.register_uri(
'POST',
re.compile(
'https?://localhost:1234.*',
),
text=u'[INFO]',
status_code=200,
)
requests_mocker.register_uri(
requests_mock.ANY,
re.compile(
'.*' +
workflow_app.config['WORKFLOWS_MATCH_REMOTE_SERVER_URL'] +
'.*'
),
status_code=200,
json=[],
)
requests_mocker.register_uri(
requests_mock.ANY,
re.compile(
'.*' +
workflow_app.config['BEARD_API_URL'] +
'/text/phonetic_blocks.*'
),
status_code=200,
json={'phonetic_blocks': {}},
)
yield
Binary file removed tests/integration/workflows/fixtures/1511.01097
Binary file not shown.
Binary file not shown.
Binary file added tests/integration/workflows/fixtures/1705.02541
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 441f6ca

Please sign in to comment.