Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inprove gregor airtable test coverage #4459

Merged
merged 6 commits into from
Oct 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions seqr/views/apis/report_api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@
},
},
{
"id": "rec2B67GmXpAkQW8z",
"id": "rec2Nkg10N1KssX1c",
"fields": {
'SeqrCollaboratorSampleID': 'NA19679',
'CollaboratorSampleID': 'NA19679',
'CollaboratorParticipantID': 'NA19679',
'SMID': 'SM-N1P91',
'SMID': 'SM-X1P92',
'Recontactable': 'Yes',
},
},
Expand All @@ -97,6 +97,16 @@
},
]}

AIRTABLE_RNA_ONLY_GREGOR_SAMPLE_RECORDS = {
"records": [
{
"id": "rec2B67GmXpAkQW8z",
"fields": {
'SMID': 'SM-N1P91',
},
},
]}

AIRTABLE_GREGOR_RECORDS = {
"records": [
{
Expand Down Expand Up @@ -793,12 +803,25 @@ def _test_gregor_export(self, url, mock_subprocess, mock_temp_dir, mock_open, mo
mock_temp_dir.return_value.__enter__.return_value = '/mock/tmp'
mock_subprocess.return_value.wait.return_value = 1

airtable_sample_url = f'{AIRTABLE_URL}/app3Y97xtbbaOopVR/Samples'
responses.add(
responses.GET, '{}/app3Y97xtbbaOopVR/Samples'.format(AIRTABLE_URL), json=AIRTABLE_GREGOR_SAMPLE_RECORDS,
status=200)
responses.GET, airtable_sample_url, json=AIRTABLE_GREGOR_SAMPLE_RECORDS, status=200, match=[
responses.matchers.query_param_matcher({'fields[]': ['CollaboratorSampleID', 'CollaboratorParticipantID', 'Recontactable', 'SMID']}, strict_match=False),
]
)
responses.add(
responses.GET, airtable_sample_url, json=AIRTABLE_GREGOR_SAMPLE_RECORDS, status=200, match=[
responses.matchers.query_param_matcher({'fields[]': ['SeqrCollaboratorSampleID', 'CollaboratorParticipantID', 'Recontactable', 'SMID']}, strict_match=False),
]
)
responses.add(
responses.GET, airtable_sample_url, json=AIRTABLE_RNA_ONLY_GREGOR_SAMPLE_RECORDS, status=200,
match=[responses.matchers.query_param_matcher({'fields[]': 'SMID'}, strict_match=False)]
)
responses.add(
responses.GET, '{}/app3Y97xtbbaOopVR/GREGoR Data Model'.format(AIRTABLE_URL), json=AIRTABLE_GREGOR_RECORDS,
status=200)

responses.add(responses.GET, MOCK_DATA_MODEL_URL, status=404)

response = self.client.post(url, content_type='application/json', data=json.dumps({}))
Expand Down Expand Up @@ -1110,7 +1133,7 @@ def _assert_expected_file(self, actual_rows, expected_rows, additional_calls=0,

def _test_expected_gregor_airtable_calls(self, additional_samples=None, additional_mondo_ids=None):
mondo_ids = ['0044970'] + (additional_mondo_ids or [])
self.assertEqual(len(responses.calls), len(mondo_ids) + 4)
self.assertEqual(len(responses.calls), len(mondo_ids) + 5)
self.assertSetEqual(
{call.request.url for call in responses.calls[:len(mondo_ids)]},
{f'https://monarchinitiative.org/v3/api/entity/MONDO:{mondo_id}' for mondo_id in mondo_ids}
Expand Down Expand Up @@ -1150,8 +1173,11 @@ def _test_expected_gregor_airtable_calls(self, additional_samples=None, addition
len(mondo_ids) + 2, "OR(CollaboratorParticipantID='NA19675',CollaboratorParticipantID='NA19679',CollaboratorParticipantID='NA20888',CollaboratorParticipantID='VCGS_FAM203_621')",
metadata_fields,
)
self.assert_expected_airtable_call(
len(mondo_ids) + 3,"OR(RECORD_ID()='rec2B67GmXpAkQW8z')",['SMID'],
)

self.assertEqual(responses.calls[len(mondo_ids) + 3].request.url, MOCK_DATA_MODEL_URL)
self.assertEqual(responses.calls[len(mondo_ids) + 4].request.url, MOCK_DATA_MODEL_URL)

def test_family_metadata(self):
url = reverse(family_metadata, args=['R0003_test'])
Expand Down
Loading