Skip to content

Commit

Permalink
fix: inj materials check (#235)
Browse files Browse the repository at this point in the history
* fix: inj materials check

* undo comments

* adds test case
  • Loading branch information
mekhlakapoor authored May 23, 2024
1 parent 587806e commit b1bfe93
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/aind_metadata_service/tars/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ def get_virus_strains(response: ModelResponse) -> List:
if (
isinstance(procedure, Injection)
and hasattr(procedure, "injection_materials")
and isinstance(procedure.injection_materials, list)
and procedure.injection_materials
and hasattr(procedure.injection_materials[0], "name")
):
virus_strain = procedure.injection_materials[0].name
Expand Down
18 changes: 17 additions & 1 deletion tests/tars/test_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ class TestTarsResponseHandler(unittest.TestCase):
status_code=StatusCodes.DB_RESPONDED,
)

surgery2 = Surgery.model_construct(
procedures=[NanojectInjection.model_construct(injection_materials=[])]
)
procedures_response2 = ModelResponse(
aind_models=[
Procedures(subject_id="12345", subject_procedures=[surgery2])
],
status_code=StatusCodes.DB_RESPONDED,
)

def test_map_prep_type_and_protocol(self):
"""Tests that prep_type and protocol are mapped as expected."""
(
Expand Down Expand Up @@ -290,14 +300,20 @@ def test_get_virus_strains(self):
self.procedures_response
)
expected_virus_strains = ["12345", "67890"]

self.assertEqual(virus_strains, expected_virus_strains)

# Tests when injection materials attribute doesn't exist
no_virus_strains = self.handler.get_virus_strains(
self.procedures_response1
)
self.assertEqual(no_virus_strains, [])

# Tests when injection materials exists but is empty
empty_virus_strains = self.handler.get_virus_strains(
self.procedures_response2
)
self.assertEqual(empty_virus_strains, [])

def test_integrate_injection_materials(self):
"""Tests that injection materials are integrated into
procedures response as expected"""
Expand Down

0 comments on commit b1bfe93

Please sign in to comment.