Skip to content

Commit

Permalink
Merge pull request #267 from AllenNeuralDynamics/release-v0.14.18
Browse files Browse the repository at this point in the history
fix: updates bug with funding
  • Loading branch information
jtyoung84 authored Sep 25, 2024
2 parents 19a0230 + c153c3d commit 76e3047
Show file tree
Hide file tree
Showing 4 changed files with 227 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/aind_metadata_service/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""REST service to retrieve metadata from databases."""

__version__ = "0.14.17"
__version__ = "0.14.18"
2 changes: 2 additions & 0 deletions src/aind_metadata_service/smartsheet/funding/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def _parse_institution(input_name: str) -> Union[Organization, str]:
"""
if Organization().name_map.get(input_name) is not None:
return Organization().name_map.get(input_name)
elif Organization().abbreviation_map.get(input_name) is not None:
return Organization().abbreviation_map.get(input_name)
else:
return input_name

Expand Down
194 changes: 194 additions & 0 deletions tests/resources/smartsheet/test_funding_sheet2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
{
"accessLevel": "EDITOR_SHARE",
"columns": [
{
"id": 3981351074090884,
"index": 0,
"title": "Project Name",
"type": "TEXT_NUMBER",
"validation": false,
"version": 0,
"width": 371
},
{
"id": 1729551260405636,
"index": 1,
"primary": true,
"title": "Project Code",
"type": "TEXT_NUMBER",
"validation": false,
"version": 0,
"width": 150
},
{
"id": 2990791841501060,
"index": 2,
"options": [
"Allen Institute",
"Allen Institute For Brain Science",
"Allen Institute For Neural Dynamics",
"Columbia University",
"Jackson Laboratory",
"Huazhong University Of Science And Technology",
"National Institute Of Neurological Disorders And Stroke",
"New York University",
"Simons Foundation",
"National Institutes of Health"
],
"title": "Funding Institution",
"type": "PICKLIST",
"validation": false,
"version": 0,
"width": 150
},
{
"id": 3446515788894084,
"index": 3,
"title": "Grant Number",
"type": "PICKLIST",
"validation": false,
"version": 0,
"width": 150
},
{
"id": 4825776004222852,
"index": 4,
"title": "Investigators",
"type": "TEXT_NUMBER",
"validation": false,
"version": 1,
"width": 150
}
],
"createdAt": "2023-07-31T20:52:39+00:00Z",
"dependenciesEnabled": false,
"effectiveAttachmentOptions": [
"EVERNOTE",
"FILE",
"EGNYTE",
"ONEDRIVE",
"GOOGLE_DRIVE",
"BOX_COM",
"DROPBOX",
"LINK"
],
"ganttEnabled": false,
"hasSummaryFields": false,
"id": 2802362280267652,
"modifiedAt": "2023-12-20T18:36:26+00:00Z",
"name": "Project Name and Funding Source",
"permalink": "https://app.smartsheet.com/sheets/IJ5WvApEFriNhoReXpDWhQRhNOAWXmSoxsenGVAH",
"readOnly": true,
"resourceManagementEnabled": false,
"rows": [
{
"cells": [
{
"columnId": 3981351074090884,
"displayValue": "AIND Scientific Activities",
"value": "AIND Scientific Activities"
},
{
"columnId": 1729551260405636,
"displayValue": "122-01-001-10",
"value": "122-01-001-10"
},
{
"columnId": 2990791841501060,
"displayValue": "NINDS",
"value": "NINDS"
},
{
"columnId": 3446515788894084
},
{
"columnId": 4825776004222852,
"displayValue": "[email protected], J Smith, Mary Smith",
"value": "[email protected], J Smith, John Doe II"
}
],
"createdAt": "2023-07-31T20:57:28+00:00Z",
"expanded": true,
"id": 2014892103339908,
"modifiedAt": "2023-12-20T18:32:10+00:00Z",
"rowNumber": 1
},
{
"cells": [
{
"columnId": 3981351074090884
},
{
"columnId": 1729551260405636,
"displayValue": "122-01-001-10",
"value": "122-01-001-10"
},
{
"columnId": 2990791841501060,
"displayValue": "NINDS",
"value": "NINDS"
},
{
"columnId": 3446515788894084
},
{
"columnId": 4825776004222852,
"displayValue": "John Doe, [email protected]",
"value": "John Doe, [email protected]"
}
],
"createdAt": "2023-08-07T23:39:14+00:00Z",
"expanded": true,
"id": 3850275791343492,
"modifiedAt": "2023-12-20T18:32:10+00:00Z",
"rowNumber": 2,
"siblingId": 2014892103339908
},
{
"cells": [
{
"columnId": 3981351074090884,
"displayValue": "v1omFISH",
"value": "v1omFISH"
},
{
"columnId": 1729551260405636,
"displayValue": "121-01-010-10",
"value": "121-01-010-10"
},
{
"columnId": 2990791841501060,
"displayValue": "NINDS",
"value": "NINDS"
},
{
"columnId": 3446515788894084
},
{
"columnId": 4825776004222852,
"displayValue": "[email protected], Jane Doe",
"value": "[email protected], Jane Doe"
}
],
"createdAt": "2023-08-02T19:28:24+00:00Z",
"expanded": true,
"id": 8831127549939588,
"modifiedAt": "2023-12-20T18:33:23+00:00Z",
"rowNumber": 3,
"siblingId": 4327527922569092
}
],
"totalRowCount": 3,
"userPermissions": {
"summaryPermissions": "READ_WRITE"
},
"userSettings": {
"criticalPathEnabled": false,
"displaySummaryTasks": true
},
"version": 40,
"workspace": {
"id": 8949276219860868,
"name": "AIND Projects Workspace"
}
}
30 changes: 30 additions & 0 deletions tests/smartsheet/test_funding.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
EXAMPLE_PATH = (
TEST_DIR / "resources" / "smartsheet" / "test_funding_sheet.json"
)
EXAMPLE_PATH_2 = (
TEST_DIR / "resources" / "smartsheet" / "test_funding_sheet2.json"
)


class TestSmartsheetFundingClient(unittest.TestCase):
Expand All @@ -35,7 +38,10 @@ def setUpClass(cls):
"""Load json files before running tests."""
with open(EXAMPLE_PATH, "r") as f:
contents = json.load(f)
with open(EXAMPLE_PATH_2, "r") as f:
contents2 = json.load(f)
cls.example_sheet = json.dumps(contents)
cls.example_sheet2 = json.dumps(contents2)

@patch("smartsheet.sheets.Sheets.get_sheet")
def test_mapping(self, mock_get_sheet: MagicMock):
Expand All @@ -61,6 +67,30 @@ def test_mapping(self, mock_get_sheet: MagicMock):
self.assertEqual(expected_models, model_response.aind_models)
self.assertEqual(StatusCodes.DB_RESPONDED, model_response.status_code)

@patch("smartsheet.sheets.Sheets.get_sheet")
def test_mapping_abbreviation(self, mock_get_sheet: MagicMock):
"""Tests successful sheet return response when org abbreviation used"""
mock_get_sheet.return_value.to_json.return_value = self.example_sheet2
settings = SmartsheetSettings(
access_token="abc-123", sheet_id=7478444220698500
)
client = SmartSheetClient(smartsheet_settings=settings)
smart_sheet_response = client.get_sheet()
mapper = FundingMapper(
smart_sheet_response=smart_sheet_response,
input_id="AIND Scientific Activities",
)
model_response = mapper.get_model_response()
expected_models = [
Funding(
funder=Organization.NINDS,
grant_number=None,
fundee=("[email protected], J Smith, John Doe II"),
)
]
self.assertEqual(expected_models, model_response.aind_models)
self.assertEqual(StatusCodes.DB_RESPONDED, model_response.status_code)

@patch("smartsheet.sheets.Sheets.get_sheet")
def test_mapping_empty_response(self, mock_get_sheet: MagicMock):
"""Tests successful sheet return response"""
Expand Down

0 comments on commit 76e3047

Please sign in to comment.