diff --git a/inspirehep/modules/workflows/tasks/actions.py b/inspirehep/modules/workflows/tasks/actions.py index 0145d1abfe..c1ced3e016 100644 --- a/inspirehep/modules/workflows/tasks/actions.py +++ b/inspirehep/modules/workflows/tasks/actions.py @@ -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) diff --git a/inspirehep/modules/workflows/workflows/article.py b/inspirehep/modules/workflows/workflows/article.py index 0f148eefb8..6917bf22a4 100644 --- a/inspirehep/modules/workflows/workflows/article.py +++ b/inspirehep/modules/workflows/workflows/article.py @@ -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, ) @@ -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( @@ -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', - ), - ) ] ) ), diff --git a/tests/integration/workflows/test_article_workflow.py b/tests/integration/workflows/test_article_workflow.py index e5b38cfe13..ea187039eb 100644 --- a/tests/integration/workflows/test_article_workflow.py +++ b/tests/integration/workflows/test_article_workflow.py @@ -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") @@ -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, ): diff --git a/tests/unit/workflows/test_workflows_actions.py b/tests/unit/workflows/test_workflows_actions.py index fe255ee3dc..532f849a20 100644 --- a/tests/unit/workflows/test_workflows_actions.py +++ b/tests/unit/workflows/test_workflows_actions.py @@ -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(): @@ -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 = "England" 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 = "England" - obj = MagicMock() - obj.data = { - 'core': True - } obj.extra_data = {} eng = None new_config = {"GROBID_URL": "http://grobid_url.local"} @@ -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 = "unitEd KiNgdOm" obj = MagicMock() - obj.data = { - 'core': True - } obj.extra_data = {} eng = None new_config = {"GROBID_URL": "http://grobid_url.local"} @@ -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