class PhenotipsAPITest(TestCase): fixtures = ['users', '1kg_project'] @mock.patch('seqr.views.apis.phenotips_api.proxy_request', create_proxy_request_stub()) def test_phenotips_edit(self): url = reverse(phenotips_edit_handler, args=['R0001_1kg', 'I000001_na19675']) _check_login(self, url) response = self.client.post(url, content_type='application/json', data=json.dumps({'some_json': 'test'})) self.assertEqual(response.status_code, 200) @mock.patch('seqr.views.apis.phenotips_api.proxy_request', create_proxy_request_stub()) def test_phenotips_pdf(self): url = reverse(phenotips_pdf_handler, args=['R0001_1kg', 'I000001_na19675']) _check_login(self, url) response = self.client.post(url, content_type='application/json', data=json.dumps({'some_json': 'test'})) self.assertEqual(response.status_code, 200)
class ProjectAPITest(TestCase): fixtures = ['users', '1kg_project'] @mock.patch('seqr.views.apis.phenotips_api.proxy_request', create_proxy_request_stub(201)) def test_create_update_and_delete_project(self): create_project_url = reverse(create_project_handler) _check_login(self, create_project_url) # check validation of bad requests response = self.client.post(create_project_url, content_type='application/json', data=json.dumps({'bad_json': None})) self.assertEqual(response.status_code, 400) response = self.client.post(create_project_url, content_type='application/json', data=json.dumps( {'form': { 'missing_name': True }})) self.assertEqual(response.status_code, 400) # send valid request to create project response = self.client.post(create_project_url, content_type='application/json', data=json.dumps({ 'name': 'new_project', 'description': 'new project description' })) self.assertEqual(response.status_code, 200) # check that project was created new_project = Project.objects.filter(name='new_project') self.assertEqual(len(new_project), 1) self.assertEqual(new_project[0].description, 'new project description') # delete the project delete_project_url = reverse(delete_project_handler, args=[new_project[0].guid]) response = self.client.post(delete_project_url, content_type='application/json') self.assertEqual(response.status_code, 200) # check that project was deleted new_project = Project.objects.filter(name='new_project') self.assertEqual(len(new_project), 0)
class PhenotipsAPITest(TestCase): fixtures = ['users', '1kg_project', 'reference_data'] multi_db = True @mock.patch('seqr.views.apis.phenotips_api.proxy_request', create_proxy_request_stub()) def test_phenotips_edit(self): url = reverse(phenotips_edit_handler, args=['R0001_1kg', 'I000001_na19675']) _check_login(self, url) response = self.client.post(url, content_type='application/json', data=json.dumps({'some_json': 'test'})) self.assertEqual(response.status_code, 200) @mock.patch('seqr.views.apis.phenotips_api.proxy_request', create_proxy_request_stub()) def test_phenotips_pdf(self): url = reverse(phenotips_pdf_handler, args=['R0001_1kg', 'I000001_na19675']) _check_login(self, url) response = self.client.post(url, content_type='application/json', data=json.dumps({'some_json': 'test'})) self.assertEqual(response.status_code, 200) def test_receive_hpo_table_handler(self): url = reverse(receive_hpo_table_handler, args=['R0001_1kg']) _check_login(self, url) # Send invalid requests header = 'family_id,indiv_id,hpo_term_yes,hpo_term_no' rows = [ '1,NA19678,,', '1,NA19679,HP:0001631 (Defect in the atrial septum),', '1,HG00731,HP:0002017,HP:0012469 (Infantile spasms);HP:0011675 (Arrhythmia)', ] f = SimpleUploadedFile('updates.csv', b"{}\n{}".format(header, '\n'.join(rows))) response = self.client.post(url, data={'f': f}) self.assertEqual(response.status_code, 400) self.assertDictEqual( response.json(), { 'errors': ['Invalid header, missing individual id column'], 'warnings': [] }) header = 'family_id,individual_id,hpo_term_yes,hpo_term_no' f = SimpleUploadedFile('updates.csv', b"{}\n{}".format(header, '\n'.join(rows))) response = self.client.post(url, data={'f': f}) self.assertEqual(response.status_code, 400) self.assertDictEqual( response.json(), { 'errors': ['Invalid header, missing hpo terms columns'], 'warnings': [] }) header = 'family_id,individual_id,hpo_term_present,hpo_term_absent' f = SimpleUploadedFile('updates.csv', b"{}\n{}".format(header, '\n'.join(rows))) response = self.client.post(url, data={'f': f}) self.assertEqual(response.status_code, 400) self.assertDictEqual( response.json(), { 'errors': [ 'Unable to find individuals to update for any of the 3 parsed individuals. No matching ids found for 1 individuals. No changes detected for 2 individuals.' ], 'warnings': [] }) # send valid request rows.append( '1,NA19675_1,HP:0002017,HP:0012469 (Infantile spasms);HP:0011675 (Arrhythmia)' ) f = SimpleUploadedFile('updates.csv', b"{}\n{}".format(header, '\n'.join(rows))) response = self.client.post(url, data={'f': f}) self.assertEqual(response.status_code, 200) self.assertDictEqual( response.json(), { 'updatesByIndividualGuid': { 'I000001_na19675': [ { 'id': 'HP:0002017', 'observed': 'yes', 'category': 'HP:0025031', 'label': 'Nausea and vomiting', 'type': 'phenotype' }, { 'id': 'HP:0012469', 'observed': 'no', 'category': 'HP:0025031', 'label': 'Infantile spasms', 'type': 'phenotype' }, ] }, 'uploadedFileId': mock.ANY, 'errors': [], 'warnings': [ "The following HPO terms were not found in seqr's HPO data and will not be added: HP:0001631 (NA19679); HP:0011675 (NA19675_1)", 'Unable to find matching ids for 1 individuals. The following entries will not be updated: HG00731', 'No changes detected for 2 individuals. The following entries will not be updated: NA19678, NA19679', ], 'info': ['1 individuals will be updated'], })
class ProjectAPITest(TestCase): fixtures = ['users', '1kg_project', 'reference_data'] multi_db = True @mock.patch('seqr.views.utils.phenotips_utils.proxy_request', create_proxy_request_stub(201)) def test_create_update_and_delete_project(self): create_project_url = reverse(create_project_handler) _check_login(self, create_project_url) # check validation of bad requests response = self.client.post(create_project_url, content_type='application/json', data=json.dumps({'bad_json': None})) self.assertEqual(response.status_code, 400) response = self.client.post(create_project_url, content_type='application/json', data=json.dumps({'form': {'missing_name': True}})) self.assertEqual(response.status_code, 400) # send valid request to create project response = self.client.post(create_project_url, content_type='application/json', data=json.dumps( {'name': 'new_project', 'description': 'new project description', 'genomeVersion': '38'} )) self.assertEqual(response.status_code, 200) # check that project was created new_project = Project.objects.filter(name='new_project') self.assertEqual(len(new_project), 1) self.assertEqual(new_project[0].description, 'new project description') self.assertEqual(new_project[0].genome_version, '38') project_guid = new_project[0].guid self.assertSetEqual(set(response.json()['projectsByGuid'].keys()), {project_guid}) # update the project update_project_url = reverse(update_project_handler, args=[project_guid]) response = self.client.post(update_project_url, content_type='application/json', data=json.dumps( {'description': 'updated project description'} )) self.assertEqual(response.status_code, 200) self.assertEqual(response.json()['projectsByGuid'][project_guid]['description'], 'updated project description') self.assertEqual(Project.objects.get(guid=project_guid).description, 'updated project description') # genome version should not update response = self.client.post(update_project_url, content_type='application/json', data=json.dumps( {'genomeVersion': '37'} )) self.assertEqual(response.json()['projectsByGuid'][project_guid]['genomeVersion'], '38') self.assertEqual(Project.objects.get(guid=project_guid).genome_version, '38') # delete the project delete_project_url = reverse(delete_project_handler, args=[project_guid]) response = self.client.post(delete_project_url, content_type='application/json') self.assertEqual(response.status_code, 200) # check that project was deleted new_project = Project.objects.filter(name='new_project') self.assertEqual(len(new_project), 0) @mock.patch('seqr.views.utils.orm_to_json_utils.get_objects_for_group', get_objects_for_group) def test_project_page_data(self): url = reverse(project_page_data, args=[PROJECT_GUID]) _check_login(self, url) response = self.client.get(url) self.assertEqual(response.status_code, 200) response_json = response.json() self.assertSetEqual( set(response_json.keys()), {'projectsByGuid', 'familiesByGuid', 'individualsByGuid', 'samplesByGuid', 'locusListsByGuid', 'analysisGroupsByGuid', 'genesById'} ) self.assertSetEqual( set(response_json['projectsByGuid'][PROJECT_GUID]['variantTagTypes'][0].keys()), {'variantTagTypeGuid', 'name', 'category', 'description', 'color', 'order', 'numTags', 'numTagsPerFamily'} ) self.assertSetEqual( set(response_json['projectsByGuid'][PROJECT_GUID].keys()), {'collaborators', 'locusListGuids', 'variantTagTypes', 'variantFunctionalTagTypes', 'detailsLoaded', 'projectGuid', 'projectCategoryGuids', 'canEdit', 'name', 'description', 'createdDate', 'lastModifiedDate', 'isPhenotipsEnabled', 'phenotipsUserId', 'genomeVersion', 'discoveryTags', 'lastAccessedDate', 'isMmeEnabled', 'mmePrimaryDataOwner', 'mmeContactInstitution', 'mmeContactUrl'} ) self.assertEqual( response_json['projectsByGuid'][PROJECT_GUID]['lastAccessedDate'][:10], datetime.today().strftime('%Y-%m-%d') ) discovery_tags = response_json['projectsByGuid'][PROJECT_GUID]['discoveryTags'] self.assertEqual(len(discovery_tags), 1) self.assertEqual(discovery_tags[0]['variantGuid'], 'SV0000001_2103343353_r0390_100') self.assertListEqual(response_json['genesById'].keys(), ['ENSG00000135953']) self.assertSetEqual( set(response_json['familiesByGuid'].values()[0].keys()), {'projectGuid', 'familyGuid', 'individualGuids', 'analysedBy', 'pedigreeImage', 'familyId', 'displayName', 'description', 'analysisNotes', 'analysisSummary', 'causalInheritanceMode', 'analysisStatus', 'pedigreeImage', 'internalAnalysisStatus', 'internalCaseReviewNotes', 'internalCaseReviewSummary', 'createdDate', 'codedPhenotype', 'postDiscoveryOmimNumber', 'pubmedIds', 'assignedAnalyst', 'successStoryTypes', 'successStory'} ) self.assertSetEqual( set(response_json['individualsByGuid'].values()[0].keys()), {'projectGuid', 'familyGuid', 'individualGuid', 'sampleGuids', 'caseReviewStatusLastModifiedBy', 'phenotipsData', 'individualId', 'paternalId', 'maternalId', 'sex', 'affected', 'displayName', 'notes', 'phenotipsPatientId', 'phenotipsData', 'createdDate', 'lastModifiedDate', 'caseReviewStatus', 'caseReviewDiscussion', 'caseReviewStatusLastModifiedDate', 'caseReviewStatusLastModifiedBy', 'paternalGuid', 'maternalGuid', 'mmeSubmittedDate', 'mmeDeletedDate', 'popPlatformFilters', 'filterFlags', 'population'} ) self.assertSetEqual( set(response_json['samplesByGuid'].values()[0].keys()), {'projectGuid', 'individualGuid', 'sampleGuid', 'createdDate', 'sampleType', 'datasetType', 'sampleId', 'isActive', 'loadedDate', 'datasetFilePath', 'elasticsearchIndex'} ) self.assertSetEqual( set(response_json['locusListsByGuid'].values()[0].keys()), {'locusListGuid', 'description', 'lastModifiedDate', 'numEntries', 'isPublic', 'createdBy', 'createdDate', 'canEdit', 'name'} ) self.assertSetEqual( set(response_json['analysisGroupsByGuid'].values()[0].keys()), {'analysisGroupGuid', 'description', 'name', 'projectGuid', 'familyGuids'} ) @mock.patch('seqr.views.utils.orm_to_json_utils.get_objects_for_group', get_objects_for_group) def test_empty_project_page_data(self): url = reverse(project_page_data, args=[EMPTY_PROJECT_GUID]) _check_login(self, url) response = self.client.get(url) self.assertEqual(response.status_code, 200) response_json = response.json() self.assertSetEqual( set(response_json.keys()), {'projectsByGuid', 'familiesByGuid', 'individualsByGuid', 'samplesByGuid', 'locusListsByGuid', 'analysisGroupsByGuid', 'genesById'} ) self.assertListEqual(response_json['projectsByGuid'].keys(), [EMPTY_PROJECT_GUID]) self.assertDictEqual(response_json['familiesByGuid'], {}) self.assertDictEqual(response_json['individualsByGuid'], {}) self.assertDictEqual(response_json['samplesByGuid'], {}) self.assertDictEqual(response_json['analysisGroupsByGuid'], {}) self.assertDictEqual(response_json['genesById'], {}) def test_export_tables(self): url = reverse(export_project_individuals_handler, args=['R0001_1kg']) _check_login(self, url) response = self.client.get(url + "?file_format=tsv") self.assertEqual(response.status_code, 200) response = self.client.get(url + "?file_format=xls") self.assertEqual(response.status_code, 200)
class ProjectAPITest(TestCase): fixtures = ['users', '1kg_project', 'reference_data'] multi_db = True @mock.patch('seqr.views.utils.phenotips_utils.proxy_request', create_proxy_request_stub(201)) def test_create_update_and_delete_project(self): create_project_url = reverse(create_project_handler) _check_login(self, create_project_url) # check validation of bad requests response = self.client.post(create_project_url, content_type='application/json', data=json.dumps({'bad_json': None})) self.assertEqual(response.status_code, 400) response = self.client.post(create_project_url, content_type='application/json', data=json.dumps( {'form': { 'missing_name': True }})) self.assertEqual(response.status_code, 400) # send valid request to create project response = self.client.post(create_project_url, content_type='application/json', data=json.dumps({ 'name': 'new_project', 'description': 'new project description', 'genomeVersion': '38' })) self.assertEqual(response.status_code, 200) # check that project was created new_project = Project.objects.filter(name='new_project') self.assertEqual(len(new_project), 1) self.assertEqual(new_project[0].description, 'new project description') self.assertEqual(new_project[0].genome_version, '38') project_guid = new_project[0].guid self.assertSetEqual(set(response.json()['projectsByGuid'].keys()), {project_guid}) # update the project update_project_url = reverse(update_project_handler, args=[project_guid]) response = self.client.post( update_project_url, content_type='application/json', data=json.dumps({'description': 'updated project description'})) self.assertEqual(response.status_code, 200) self.assertEqual( response.json()['projectsByGuid'][project_guid]['description'], 'updated project description') self.assertEqual( Project.objects.get(guid=project_guid).description, 'updated project description') # genome version should not update response = self.client.post(update_project_url, content_type='application/json', data=json.dumps({'genomeVersion': '37'})) self.assertEqual( response.json()['projectsByGuid'][project_guid]['genomeVersion'], '38') self.assertEqual( Project.objects.get(guid=project_guid).genome_version, '38') # delete the project delete_project_url = reverse(delete_project_handler, args=[project_guid]) response = self.client.post(delete_project_url, content_type='application/json') self.assertEqual(response.status_code, 200) # check that project was deleted new_project = Project.objects.filter(name='new_project') self.assertEqual(len(new_project), 0) def test_project_page_data(self): url = reverse(project_page_data, args=[PROJECT_GUID]) _check_login(self, url) response = self.client.get(url) self.assertEqual(response.status_code, 200) response_json = response.json() self.assertSetEqual( set(response_json.keys()), { 'projectsByGuid', 'familiesByGuid', 'individualsByGuid', 'samplesByGuid', 'locusListsByGuid', 'analysisGroupsByGuid', 'genesById', 'mmeSubmissionsByGuid' }) self.assertSetEqual( set(response_json['projectsByGuid'][PROJECT_GUID] ['variantTagTypes'][0].keys()), { 'variantTagTypeGuid', 'name', 'category', 'description', 'color', 'order', 'numTags', 'numTagsPerFamily' }) project_fields = { 'collaborators', 'locusListGuids', 'variantTagTypes', 'variantFunctionalTagTypes', 'detailsLoaded', 'discoveryTags', } project_fields.update(PROJECT_FIELDS) self.assertSetEqual( set(response_json['projectsByGuid'][PROJECT_GUID].keys()), project_fields) self.assertEqual( response_json['projectsByGuid'][PROJECT_GUID]['lastAccessedDate'] [:10], datetime.today().strftime('%Y-%m-%d')) discovery_tags = response_json['projectsByGuid'][PROJECT_GUID][ 'discoveryTags'] self.assertEqual(len(discovery_tags), 1) self.assertEqual(discovery_tags[0]['variantGuid'], 'SV0000001_2103343353_r0390_100') self.assertListEqual(response_json['genesById'].keys(), ['ENSG00000135953']) self.assertSetEqual( set(response_json['familiesByGuid'].values()[0].keys()), INTERNAL_FAMILY_FIELDS) individual_fields = {'sampleGuids', 'mmeSubmissionGuid'} individual_fields.update(INTERNAL_INDIVIDUAL_FIELDS) self.assertSetEqual( set(response_json['individualsByGuid'].values()[0].keys()), individual_fields) self.assertSetEqual( set(response_json['samplesByGuid'].values()[0].keys()), SAMPLE_FIELDS) self.assertSetEqual( set(response_json['locusListsByGuid'].values()[0].keys()), LOCUS_LIST_FIELDS) self.assertSetEqual( set(response_json['analysisGroupsByGuid'].values()[0].keys()), { 'analysisGroupGuid', 'description', 'name', 'projectGuid', 'familyGuids' }) self.assertSetEqual( set(response_json['mmeSubmissionsByGuid'].values()[0].keys()), { 'submissionGuid', 'individualGuid', 'createdDate', 'lastModifiedDate', 'deletedDate' }) def test_empty_project_page_data(self): url = reverse(project_page_data, args=[EMPTY_PROJECT_GUID]) _check_login(self, url) response = self.client.get(url) self.assertEqual(response.status_code, 200) response_json = response.json() self.assertSetEqual( set(response_json.keys()), { 'projectsByGuid', 'familiesByGuid', 'individualsByGuid', 'samplesByGuid', 'locusListsByGuid', 'analysisGroupsByGuid', 'genesById', 'mmeSubmissionsByGuid' }) self.assertListEqual(response_json['projectsByGuid'].keys(), [EMPTY_PROJECT_GUID]) self.assertDictEqual(response_json['familiesByGuid'], {}) self.assertDictEqual(response_json['individualsByGuid'], {}) self.assertDictEqual(response_json['samplesByGuid'], {}) self.assertDictEqual(response_json['analysisGroupsByGuid'], {}) self.assertDictEqual(response_json['genesById'], {}) self.assertDictEqual(response_json['mmeSubmissionsByGuid'], {}) self.assertDictEqual(response_json['locusListsByGuid'], {}) def test_export_tables(self): url = reverse(export_project_individuals_handler, args=['R0001_1kg']) _check_login(self, url) response = self.client.get(url + "?file_format=tsv") self.assertEqual(response.status_code, 200) response = self.client.get(url + "?file_format=xls") self.assertEqual(response.status_code, 200)
class ProjectAPITest(TestCase): fixtures = ['users', '1kg_project'] @mock.patch('seqr.views.apis.phenotips_api.proxy_request', create_proxy_request_stub(201)) def test_create_update_and_delete_project(self): create_project_url = reverse(create_project_handler) _check_login(self, create_project_url) # check validation of bad requests response = self.client.post(create_project_url, content_type='application/json', data=json.dumps({'bad_json': None})) self.assertEqual(response.status_code, 400) response = self.client.post(create_project_url, content_type='application/json', data=json.dumps( {'form': { 'missing_name': True }})) self.assertEqual(response.status_code, 400) # send valid request to create project response = self.client.post(create_project_url, content_type='application/json', data=json.dumps({ 'name': 'new_project', 'description': 'new project description', 'genomeVersion': '38' })) self.assertEqual(response.status_code, 200) # check that project was created new_project = Project.objects.filter(name='new_project') self.assertEqual(len(new_project), 1) self.assertEqual(new_project[0].description, 'new project description') self.assertEqual(new_project[0].genome_version, '38') project_guid = new_project[0].guid self.assertSetEqual(set(response.json()['projectsByGuid'].keys()), {project_guid}) # update the project update_project_url = reverse(update_project_handler, args=[project_guid]) response = self.client.post( update_project_url, content_type='application/json', data=json.dumps({'description': 'updated project description'})) self.assertEqual(response.status_code, 200) self.assertEqual( response.json()['projectsByGuid'][project_guid]['description'], 'updated project description') self.assertEqual( Project.objects.get(guid=project_guid).description, 'updated project description') # genome version should not update response = self.client.post(update_project_url, content_type='application/json', data=json.dumps({'genomeVersion': '37'})) self.assertEqual( response.json()['projectsByGuid'][project_guid]['genomeVersion'], '38') self.assertEqual( Project.objects.get(guid=project_guid).genome_version, '38') # delete the project delete_project_url = reverse(delete_project_handler, args=[project_guid]) response = self.client.post(delete_project_url, content_type='application/json') self.assertEqual(response.status_code, 200) # check that project was deleted new_project = Project.objects.filter(name='new_project') self.assertEqual(len(new_project), 0)