Skip to content

Commit

Permalink
workflows: add core requirement to uk and ger queue
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalEgn committed Dec 20, 2024
1 parent b3c29cc commit 50f3640
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 66 deletions.
4 changes: 2 additions & 2 deletions inspirehep/modules/workflows/tasks/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1151,9 +1151,9 @@ def check_if_germany_in_raw_affiliations(obj, eng):
return True


def check_if_core_and_uk_in_fulltext(obj, eng):
def check_if_uk_in_fulltext(obj, eng):
fulltext = get_fulltext(obj)
if not fulltext or not is_core(obj, eng):
if not fulltext:
return
regex = re.compile(
r"\b(UK|United\s+Kingdom|England|Scotland|Northern\s+Ireland)\b", re.UNICODE | re.IGNORECASE)
Expand Down
56 changes: 32 additions & 24 deletions inspirehep/modules/workflows/workflows/article.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
check_if_germany_in_fulltext,
check_if_germany_in_raw_affiliations,
link_institutions_with_affiliations,
check_if_core_and_uk_in_fulltext,
check_if_uk_in_fulltext,
check_if_uk_in_raw_affiliations,
)

Expand Down Expand Up @@ -291,14 +291,17 @@
),
),
IF(
check_if_core_and_uk_in_fulltext,
create_ticket(
template='literaturesuggest/tickets/curation_core.html',
queue='UK_curation',
context_factory=curation_ticket_context,
ticket_id_key='curation_ticket_id',
is_core,
IF(
check_if_uk_in_fulltext,
create_ticket(
template='literaturesuggest/tickets/curation_core.html',
queue='UK_curation',
context_factory=curation_ticket_context,
ticket_id_key='curation_ticket_id',
),
),
)
),
],
[
IF(
Expand All @@ -311,23 +314,28 @@
),
),
IF(
check_if_germany_in_raw_affiliations,
create_ticket(
template='literaturesuggest/tickets/curation_core.html',
queue='GER_curation',
context_factory=curation_ticket_context,
ticket_id_key='curation_ticket_id',
),
is_core,
[
IF(
check_if_germany_in_raw_affiliations,
create_ticket(
template='literaturesuggest/tickets/curation_core.html',
queue='GER_curation',
context_factory=curation_ticket_context,
ticket_id_key='curation_ticket_id',
),
),
IF(
check_if_uk_in_raw_affiliations,
create_ticket(
template='literaturesuggest/tickets/curation_core.html',
queue='UK_curation',
context_factory=curation_ticket_context,
ticket_id_key='curation_ticket_id',
),
),
],
),
IF(
check_if_uk_in_raw_affiliations,
create_ticket(
template='literaturesuggest/tickets/curation_core.html',
queue='UK_curation',
context_factory=curation_ticket_context,
ticket_id_key='curation_ticket_id',
),
)
]
)
),
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/workflows/test_article_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def test_create_ticket_when_source_is_not_publishing(
return_value=False,
)
@mock.patch(
"inspirehep.modules.workflows.tasks.actions.check_if_core_and_uk_in_fulltext",
"inspirehep.modules.workflows.tasks.actions.check_if_uk_in_fulltext",
return_value=False,
)
@mock.patch("inspirehep.modules.workflows.tasks.submission.send_robotupload")
Expand All @@ -166,7 +166,7 @@ def test_set_fermilab_collection_from_report_number(
mocked_api_request_classifier,
mocked_robotupload,
mocked_check_if_germany_in_fulltext,
mocked_check_if_core_and_uk_in_fulltext,
mocked_check_if_uk_in_fulltext,
mocked_external_services,
workflow_app,
):
Expand Down
44 changes: 6 additions & 38 deletions tests/unit/workflows/test_workflows_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from inspirehep.modules.workflows.tasks.actions import check_if_uk_in_raw_affiliations, jlab_ticket_needed, load_from_source_data, \
extract_authors_from_pdf, is_suitable_for_pdf_authors_extraction, is_fermilab_report, add_collection, \
check_if_france_in_fulltext, check_if_france_in_raw_affiliations, check_if_germany_in_fulltext, \
check_if_germany_in_raw_affiliations, check_if_core_and_uk_in_fulltext
check_if_germany_in_raw_affiliations, check_if_uk_in_fulltext


def test_match_approval_gets_match_recid():
Expand Down Expand Up @@ -671,38 +671,9 @@ def test_check_if_germany_in_fulltext_when_deutschland_in_text_body(mocked_get_d


@patch("inspirehep.modules.workflows.tasks.actions.get_document_in_workflow")
def test_check_if_uk_in_fulltext_not_core(mocked_get_document, app):
def test_check_if_uk_in_fulltext(mocked_get_document, app):
fake_grobid_response = "<country key=\"UK\">England</country>"
obj = MagicMock()
obj.data = {
'core': False
}
obj.extra_data = {}
eng = None
new_config = {"GROBID_URL": "http://grobid_url.local"}
with patch.dict(current_app.config, new_config):
with requests_mock.Mocker() as requests_mocker:
requests_mocker.register_uri(
'POST', 'http://grobid_url.local/api/processFulltextDocument',
text=fake_grobid_response,
headers={'content-type': 'application/xml'},
status_code=200,
)
with tempfile.NamedTemporaryFile() as tmp_file:
mocked_get_document.return_value.__enter__.return_value = tmp_file.name
uk_in_fulltext_and_core = check_if_core_and_uk_in_fulltext(
obj, eng)

assert not uk_in_fulltext_and_core


@patch("inspirehep.modules.workflows.tasks.actions.get_document_in_workflow")
def test_check_if_uk_in_fulltext_core(mocked_get_document, app):
fake_grobid_response = "<country key=\"UK\">England</country>"
obj = MagicMock()
obj.data = {
'core': True
}
obj.extra_data = {}
eng = None
new_config = {"GROBID_URL": "http://grobid_url.local"}
Expand All @@ -716,19 +687,16 @@ def test_check_if_uk_in_fulltext_core(mocked_get_document, app):
)
with tempfile.NamedTemporaryFile() as tmp_file:
mocked_get_document.return_value.__enter__.return_value = tmp_file.name
uk_in_fulltext_and_core = check_if_core_and_uk_in_fulltext(
uk_in_fulltext = check_if_uk_in_fulltext(
obj, eng)

assert uk_in_fulltext_and_core
assert uk_in_fulltext


@patch("inspirehep.modules.workflows.tasks.actions.get_document_in_workflow")
def test_check_if_uk_in_fulltext_core_case_insensitive(mocked_get_document, app):
def test_check_if_uk_in_fulltext_case_insensitive(mocked_get_document, app):
fake_grobid_response = "<country>unitEd KiNgdOm</country>"
obj = MagicMock()
obj.data = {
'core': True
}
obj.extra_data = {}
eng = None
new_config = {"GROBID_URL": "http://grobid_url.local"}
Expand All @@ -742,7 +710,7 @@ def test_check_if_uk_in_fulltext_core_case_insensitive(mocked_get_document, app)
)
with tempfile.NamedTemporaryFile() as tmp_file:
mocked_get_document.return_value.__enter__.return_value = tmp_file.name
uk_in_fulltext_and_core = check_if_core_and_uk_in_fulltext(
uk_in_fulltext_and_core = check_if_uk_in_fulltext(
obj, eng)

assert uk_in_fulltext_and_core
Expand Down

0 comments on commit 50f3640

Please sign in to comment.