Skip to content

Commit

Permalink
Merge branch 'main' into SCRUM-4802
Browse files Browse the repository at this point in the history
  • Loading branch information
ianlongden authored Jan 31, 2025
2 parents 326a8fa + 31d6034 commit 9e47e66
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 9 deletions.
9 changes: 5 additions & 4 deletions agr_literature_service/api/crud/workflow_tag_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from agr_literature_service.api.crud.workflow_transition_requirements import (
ADMISSIBLE_WORKFLOW_TRANSITION_REQUIREMENT_FUNCTIONS)
from agr_literature_service.api.crud.workflow_transition_actions.process_action import (process_action)
from agr_literature_service.api.crud.ateam_db_helpers import get_name_to_atp_and_children
from agr_literature_service.api.crud.ateam_db_helpers import get_name_to_atp_and_children, search_ancestors_or_descendants
process_atp_multiple_allowed = [
'ATP:ont1', # used in testing
'ATP:0000165', 'ATP:0000169', 'ATP:0000189', 'ATP:0000178', 'ATP:0000166' # classifications and subtasks
Expand Down Expand Up @@ -53,12 +53,13 @@ def load_workflow_parent_children(root_node='ATP:0000177'):


def get_parent_or_children(atp_name: str, parent_or_children: str = "parent"):
if parent_or_children == "parent":
return search_ancestors_or_descendants(atp_name, 'parent')[0]
workflow_children, workflow_parent = load_workflow_parent_children(root_node=atp_name)
workflow_to_check = workflow_children if parent_or_children == "children" else workflow_parent
if atp_name not in workflow_to_check:
if atp_name not in workflow_children:
logger.error(f"Could not find {parent_or_children} for {atp_name}")
return None
return workflow_to_check[atp_name]
return workflow_children[atp_name]


def get_workflow_process_from_tag(workflow_tag_atp_id: str):
Expand Down
6 changes: 5 additions & 1 deletion tests/api/test_mod_corpus_association.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from agr_literature_service.api.main import app
from agr_literature_service.api.models import ReferenceModel, CrossReferenceModel
from agr_literature_service.lit_processing.tests.mod_populate_load import populate_test_mods
from ..fixtures import load_workflow_parent_children_mock
from ..fixtures import load_workflow_parent_children_mock, search_ancestors_or_descendants_mock
from ..fixtures import db # noqa
from .fixtures import auth_headers # noqa
from .test_reference import test_reference # noqa
Expand Down Expand Up @@ -117,6 +117,8 @@ def test_destroy_mca(self, test_mca, auth_headers): # noqa

@patch("agr_literature_service.api.crud.workflow_tag_crud.load_workflow_parent_children",
load_workflow_parent_children_mock)
@patch("agr_literature_service.api.crud.workflow_tag_crud.search_ancestors_or_descendants",
search_ancestors_or_descendants_mock)
def test_mca_modid_wb(self, db, test_reference, auth_headers): # noqa
with TestClient(app) as client:
populate_test_mods()
Expand Down Expand Up @@ -146,6 +148,8 @@ def test_mca_modid_wb(self, db, test_reference, auth_headers): # noqa

@patch("agr_literature_service.api.crud.workflow_tag_crud.load_workflow_parent_children",
load_workflow_parent_children_mock)
@patch("agr_literature_service.api.crud.workflow_tag_crud.search_ancestors_or_descendants",
search_ancestors_or_descendants_mock)
def test_mca_modid_wb_obsolete_xref(self, db, test_reference, auth_headers): # noqa
# allow creating of xref via mca if xref already has mod + reference but is_obsolete
with TestClient(app) as client:
Expand Down
8 changes: 7 additions & 1 deletion tests/api/test_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from agr_literature_service.api.models import ReferenceModel, AuthorModel, CrossReferenceModel
from agr_literature_service.api.schemas import ReferencefileSchemaPost
from agr_literature_service.lit_processing.tests.mod_populate_load import populate_test_mods
from ..fixtures import load_workflow_parent_children_mock
from ..fixtures import load_workflow_parent_children_mock, search_ancestors_or_descendants_mock
from ..fixtures import db, populate_test_mod_reference_types # noqa
from .fixtures import auth_headers # noqa
from .test_resource import test_resource # noqa
Expand Down Expand Up @@ -181,6 +181,8 @@ def test_delete_reference(self, auth_headers, test_reference): # noqa

@patch("agr_literature_service.api.crud.workflow_tag_crud.load_workflow_parent_children",
load_workflow_parent_children_mock)
@patch("agr_literature_service.api.crud.workflow_tag_crud.search_ancestors_or_descendants",
search_ancestors_or_descendants_mock)
def test_reference_mca_wb(self, db, auth_headers): # noqa
with TestClient(app) as client:
populate_test_mods()
Expand All @@ -206,6 +208,8 @@ def test_reference_mca_wb(self, db, auth_headers): # noqa

@patch("agr_literature_service.api.crud.workflow_tag_crud.load_workflow_parent_children",
load_workflow_parent_children_mock)
@patch("agr_literature_service.api.crud.workflow_tag_crud.search_ancestors_or_descendants",
search_ancestors_or_descendants_mock)
def test_reference_large(self, db, auth_headers, populate_test_mod_reference_types, test_mod, # noqa
test_topic_entity_tag_source): # noqa
with TestClient(app) as client, \
Expand Down Expand Up @@ -742,6 +746,8 @@ def test_get_bib_info(self, test_reference, auth_headers, test_mod): # noqa

@patch("agr_literature_service.api.crud.workflow_tag_crud.load_workflow_parent_children",
load_workflow_parent_children_mock)
@patch("agr_literature_service.api.crud.workflow_tag_crud.search_ancestors_or_descendants",
search_ancestors_or_descendants_mock)
def test_get_textpresso_reference_list(self, test_reference, auth_headers, test_mod, test_topic_entity_tag_source, db): # noqa
with TestClient(app) as client:
with patch("agr_literature_service.api.crud.topic_entity_tag_crud.check_atp_ids_validity") as \
Expand Down
6 changes: 5 additions & 1 deletion tests/api/test_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from agr_literature_service.api.main import app
from agr_literature_service.lit_processing.tests.mod_populate_load import populate_test_mods
from .test_mod_corpus_association import test_mca # noqa
from ..fixtures import load_workflow_parent_children_mock
from ..fixtures import load_workflow_parent_children_mock, search_ancestors_or_descendants_mock
from ..fixtures import db # noqa
from .test_reference import test_reference # noqa
from .test_mod import test_mod # noqa
Expand All @@ -23,6 +23,8 @@ def test_sort_need_review(self, test_mca): # noqa

@patch("agr_literature_service.api.crud.workflow_tag_crud.load_workflow_parent_children",
load_workflow_parent_children_mock)
@patch("agr_literature_service.api.crud.workflow_tag_crud.search_ancestors_or_descendants",
search_ancestors_or_descendants_mock)
def test_sort_prepublication_pipeline(self, db, auth_headers): # noqa
with TestClient(app) as client:
populate_test_mods()
Expand Down Expand Up @@ -221,6 +223,8 @@ def test_sort_prepublication_pipeline(self, db, auth_headers): # noqa

@patch("agr_literature_service.api.crud.workflow_tag_crud.load_workflow_parent_children",
load_workflow_parent_children_mock)
@patch("agr_literature_service.api.crud.workflow_tag_crud.search_ancestors_or_descendants",
search_ancestors_or_descendants_mock)
def test_sort_prepublication_pipeline_simple(self, db, auth_headers): # noqa
with TestClient(app) as client:
populate_test_mods()
Expand Down
8 changes: 7 additions & 1 deletion tests/api/test_workflow_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
get_workflow_process_from_tag,
get_workflow_tags_from_process,
load_workflow_parent_children)
from ..fixtures import load_workflow_parent_children_mock
from ..fixtures import load_workflow_parent_children_mock, search_ancestors_or_descendants_mock
from ..fixtures import db # noqa
from .fixtures import auth_headers # noqa
from .test_reference import test_reference # noqa
Expand Down Expand Up @@ -138,6 +138,8 @@ def test_destroy_ref_wt(self, test_workflow_tag, auth_headers): # noqa

@patch("agr_literature_service.api.crud.workflow_tag_crud.load_workflow_parent_children",
load_workflow_parent_children_mock)
@patch("agr_literature_service.api.crud.workflow_tag_crud.search_ancestors_or_descendants",
search_ancestors_or_descendants_mock)
def test_parent_child_dict(self, test_workflow_tag, auth_headers): # noqa
# load_workflow_parent_children()
assert get_workflow_process_from_tag('ATP:0000164') == 'ATP:0000161'
Expand All @@ -149,6 +151,8 @@ def test_parent_child_dict(self, test_workflow_tag, auth_headers): # noqa
@patch("agr_literature_service.api.crud.workflow_tag_crud.load_workflow_parent_children",
load_workflow_parent_children_mock)
@patch("agr_literature_service.api.crud.workflow_tag_crud.get_descendants", get_descendants_mock)
@patch("agr_literature_service.api.crud.workflow_tag_crud.search_ancestors_or_descendants",
search_ancestors_or_descendants_mock)
def test_transition_to_workflow_status_and_get_current_workflow_status(self, db, test_mod, test_reference, # noqa
auth_headers): # noqa
mod = db.query(ModModel).filter(ModModel.abbreviation == test_mod.new_mod_abbreviation).one()
Expand Down Expand Up @@ -206,6 +210,8 @@ def test_transition_to_workflow_status_and_get_current_workflow_status(self, db,

@patch("agr_literature_service.api.crud.workflow_tag_crud.load_workflow_parent_children",
load_workflow_parent_children_mock)
@patch("agr_literature_service.api.crud.workflow_tag_crud.search_ancestors_or_descendants",
search_ancestors_or_descendants_mock)
def test_workflow_tag_counters(self, db, test_workflow_tag, auth_headers): # noqa
with TestClient(app) as client, \
patch("agr_literature_service.api.crud.workflow_tag_crud.get_map_ateam_curies_to_names") as \
Expand Down
27 changes: 27 additions & 0 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,33 @@ def load_sanitized_references(populate_test_mod_reference_types):
yield None


def search_ancestors_or_descendants_mock(ontology_node, ancestors_or_descendants):
workflow_parent = {
'ATP:0000172': 'ATP:0000177',
'ATP:0000140': 'ATP:0000177',
'ATP:0000165': 'ATP:0000177',
'ATP:0000161': 'ATP:0000177',
'ATP:0000175': 'ATP:0000172',
'ATP:0000174': 'ATP:0000172',
'ATP:0000173': 'ATP:0000172',
'ATP:0000178': 'ATP:0000172',
'ATP:0000141': 'ATP:0000140',
'ATP:0000135': 'ATP:0000140',
'ATP:0000139': 'ATP:0000140',
'ATP:0000134': 'ATP:0000140',
'ATP:0000168': 'ATP:0000165',
'ATP:0000167': 'ATP:0000165',
'ATP:0000170': 'ATP:0000165',
'ATP:0000171': 'ATP:0000165',
'ATP:0000169': 'ATP:0000165',
'ATP:0000166': 'ATP:0000165',
'ATP:0000164': 'ATP:0000161',
'ATP:0000163': 'ATP:0000161',
'ATP:0000162': 'ATP:0000161'
}
return [workflow_parent[ontology_node]]


def load_workflow_parent_children_mock(root_node='ATP:0000177'):
workflow_children = {
'ATP:0000177': ['ATP:0000172', 'ATP:0000140', 'ATP:0000165', 'ATP:0000161'],
Expand Down
6 changes: 5 additions & 1 deletion tests/lit_processing/pdf2tei/test_pdf2tei.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from ...api.fixtures import auth_headers # noqa
from ...api.test_mod import test_mod # noqa
from ...api.test_reference import test_reference # noqa
from ...fixtures import load_workflow_parent_children_mock
from ...fixtures import load_workflow_parent_children_mock, search_ancestors_or_descendants_mock
from ...fixtures import db # noqa


Expand Down Expand Up @@ -171,6 +171,8 @@ def upload_initial_main_reference_file(db, client, test_mod, test_reference, aut
load_workflow_parent_children_mock)
@patch("agr_literature_service.lit_processing.pdf2tei.pdf2tei.convert_pdf_with_grobid",
convert_pdf_with_grobid_mock)
@patch("agr_literature_service.api.crud.workflow_tag_crud.search_ancestors_or_descendants",
search_ancestors_or_descendants_mock)
def test_pdf2tei(self, db, auth_headers, test_reference, test_mod): # noqa
with TestClient(app) as client:
mod_abbreviation = self.upload_initial_main_reference_file(db, client, test_mod, test_reference,
Expand All @@ -188,6 +190,8 @@ def test_pdf2tei(self, db, auth_headers, test_reference, test_mod): # noqa
@patch("agr_literature_service.api.crud.workflow_tag_crud.load_workflow_parent_children",
load_workflow_parent_children_mock)
@patch("agr_literature_service.lit_processing.pdf2tei.pdf2tei.convert_pdf_with_grobid")
@patch("agr_literature_service.api.crud.workflow_tag_crud.search_ancestors_or_descendants",
search_ancestors_or_descendants_mock)
def test_pdf2tei_failed_conversion(self, mock_convert_pdf_with_grobid,
db, auth_headers, test_reference, test_mod): # noqa
with TestClient(app) as client:
Expand Down

0 comments on commit 9e47e66

Please sign in to comment.