<s> """<STR_LIT>""" <EOL> from __future__ import division <EOL> from __future__ import print_function <EOL> from __future__ import unicode_literals <EOL> import unittest <EOL> import logging <EOL> import random <EOL> import ga4gh . datamodel . reads as reads <EOL> import ga4gh . datamodel . references as references <EOL> import ga4gh . datamodel . variants as variants <EOL> import ga4gh . datamodel . sequenceAnnotations as features <EOL> import ga4gh . frontend as frontend <EOL> import ga4gh . protocol as protocol <EOL> class TestSimulatedStack ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> logging . getLogger ( '<STR_LIT>' ) . setLevel ( logging . CRITICAL ) <EOL> random . seed ( <NUM_LIT:1> ) <EOL> config = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT:5> , <EOL> "<STR_LIT>" : <NUM_LIT:1.0> , <EOL> "<STR_LIT>" : <NUM_LIT:4> , <EOL> "<STR_LIT>" : <NUM_LIT:3> , <EOL> "<STR_LIT>" : <NUM_LIT:4> , <EOL> "<STR_LIT>" : <NUM_LIT:5> <EOL> } <EOL> frontend . reset ( ) <EOL> frontend . configure ( <EOL> baseConfig = "<STR_LIT>" , extraConfig = config ) <EOL> cls . app = frontend . app . test_client ( ) <EOL> @ classmethod <EOL> def tearDownClass ( cls ) : <EOL> cls . app = None <EOL> def setUp ( self ) : <EOL> self . backend = frontend . app . backend <EOL> self . dataRepo = self . backend . getDataRepository ( ) <EOL> self . dataset = self . dataRepo . getDatasets ( ) [ <NUM_LIT:0> ] <EOL> self . readGroupSet = self . dataset . getReadGroupSets ( ) [ <NUM_LIT:0> ] <EOL> self . readGroup = self . readGroupSet . getReadGroups ( ) [ <NUM_LIT:0> ] <EOL> self . reference = self . readGroupSet . getReferenceSet ( ) . getReferences ( ) [ <NUM_LIT:0> ] <EOL> self . variantSet = self . dataset . getVariantSets ( ) [ <NUM_LIT:0> ] <EOL> self . variantAnnotationSet = self . dataset . getVariantAnnotationSets ( ) [ <NUM_LIT:0> ] <EOL> self . backend . setMaxResponseLength ( <NUM_LIT> ) <EOL> def getBadIds ( self ) : <EOL> """<STR_LIT>""" <EOL> return [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:x>" * <NUM_LIT:100> , "<STR_LIT::>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> def sendJsonPostRequest ( self , path , data ) : <EOL> """<STR_LIT>""" <EOL> return self . app . post ( <EOL> path , headers = { '<STR_LIT>' : '<STR_LIT:application/json>' } , <EOL> data = data ) <EOL> def sendSearchRequest ( self , path , request , responseClass ) : <EOL> """<STR_LIT>""" <EOL> response = self . sendJsonPostRequest ( path , request . toJsonString ( ) ) <EOL> self . assertEqual ( <NUM_LIT:200> , response . status_code ) <EOL> responseData = responseClass . fromJsonString ( response . data ) <EOL> self . assertTrue ( responseData . validate ( responseData . toJsonDict ( ) ) ) <EOL> return responseData <EOL> def sendObjectGetRequest ( self , path , id_ ) : <EOL> """<STR_LIT>""" <EOL> return self . app . get ( "<STR_LIT>" . format ( path , id_ ) ) <EOL> def sendGetObject ( self , path , id_ , responseClass ) : <EOL> """<STR_LIT>""" <EOL> response = self . sendObjectGetRequest ( path , id_ ) <EOL> self . assertEqual ( <NUM_LIT:200> , response . status_code ) <EOL> obj = responseClass . fromJsonString ( response . data ) <EOL> self . assertTrue ( responseClass . validate ( obj . toJsonDict ( ) ) ) <EOL> return obj <EOL> def sendListReferenceBasesRequest ( self , id_ , request ) : <EOL> """<STR_LIT>""" <EOL> path = '<STR_LIT>' . format ( id_ ) <EOL> response = self . app . get ( path , query_string = request . toJsonDict ( ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> obj = protocol . ListReferenceBasesResponse . fromJsonString ( <EOL> response . data ) <EOL> self . assertTrue ( obj . validate ( obj . toJsonDict ( ) ) ) <EOL> return obj <EOL> def verifyVariantSetsEqual ( self , gaVariantSet , variantSet ) : <EOL> dataset = variantSet . getParentContainer ( ) <EOL> self . assertEqual ( gaVariantSet . id , variantSet . getId ( ) ) <EOL> self . assertEqual ( gaVariantSet . datasetId , dataset . getId ( ) ) <EOL> self . assertEqual ( gaVariantSet . name , variantSet . getLocalId ( ) ) <EOL> def verifyCallSetsEqual ( self , gaCallSet , callSet ) : <EOL> variantSet = callSet . getParentContainer ( ) <EOL> self . assertEqual ( gaCallSet . id , callSet . getId ( ) ) <EOL> self . assertEqual ( gaCallSet . name , callSet . getLocalId ( ) ) <EOL> self . assertEqual ( gaCallSet . variantSetIds , [ variantSet . getId ( ) ] ) <EOL> def verifyReadGroupSetsEqual ( self , gaReadGroupSet , readGroupSet ) : <EOL> dataset = readGroupSet . getParentContainer ( ) <EOL> self . assertEqual ( gaReadGroupSet . id , readGroupSet . getId ( ) ) <EOL> self . assertEqual ( gaReadGroupSet . datasetId , dataset . getId ( ) ) <EOL> self . assertEqual ( gaReadGroupSet . name , readGroupSet . getLocalId ( ) ) <EOL> self . assertEqual ( <EOL> len ( gaReadGroupSet . readGroups ) , len ( readGroupSet . getReadGroups ( ) ) ) <EOL> for gaReadGroup , readGroup in zip ( <EOL> gaReadGroupSet . readGroups , readGroupSet . getReadGroups ( ) ) : <EOL> self . verifyReadGroupsEqual ( gaReadGroup , readGroup ) <EOL> def verifyReadGroupsEqual ( self , gaReadGroup , readGroup ) : <EOL> self . assertEqual ( gaReadGroup . id , readGroup . getId ( ) ) <EOL> def verifyDatasetsEqual ( self , gaDataset , dataset ) : <EOL> self . assertEqual ( gaDataset . id , dataset . getId ( ) ) <EOL> self . assertEqual ( gaDataset . name , dataset . getLocalId ( ) ) <EOL> self . assertEqual ( gaDataset . description , dataset . getDescription ( ) ) <EOL> def verifyReferenceSetsEqual ( self , gaReferenceSet , referenceSet ) : <EOL> self . assertEqual ( gaReferenceSet . id , referenceSet . getId ( ) ) <EOL> self . assertEqual ( <EOL> gaReferenceSet . md5checksum , referenceSet . getMd5Checksum ( ) ) <EOL> self . assertEqual ( <EOL> gaReferenceSet . ncbiTaxonId , referenceSet . getNcbiTaxonId ( ) ) <EOL> self . assertEqual ( <EOL> gaReferenceSet . assemblyId , referenceSet . getAssemblyId ( ) ) <EOL> self . assertEqual ( <EOL> gaReferenceSet . sourceURI , referenceSet . getSourceUri ( ) ) <EOL> self . assertEqual ( <EOL> gaReferenceSet . sourceAccessions , <EOL> referenceSet . getSourceAccessions ( ) ) <EOL> self . assertEqual ( <EOL> gaReferenceSet . isDerived , referenceSet . getIsDerived ( ) ) <EOL> self . assertEqual ( <EOL> gaReferenceSet . name , referenceSet . getLocalId ( ) ) <EOL> def verifyFeatureSetsEqual ( self , gaFeatureSet , featureSet ) : <EOL> dataset = featureSet . getParentContainer ( ) <EOL> self . assertEqual ( gaFeatureSet . id , featureSet . getId ( ) ) <EOL> self . assertEqual ( gaFeatureSet . datasetId , dataset . getId ( ) ) <EOL> self . assertEqual ( gaFeatureSet . name , featureSet . getLocalId ( ) ) <EOL> def verifyFeaturesEquivalent ( self , f1 , f2 ) : <EOL> self . assertEqual ( f1 . id , f2 . id ) <EOL> self . assertEqual ( f1 . parentId , f2 . parentId ) <EOL> self . assertEqual ( f1 . featureSetId , f2 . featureSetId ) <EOL> def verifyReferencesEqual ( self , gaReference , reference ) : <EOL> self . assertEqual ( gaReference . id , reference . getId ( ) ) <EOL> self . assertEqual ( gaReference . name , reference . getName ( ) ) <EOL> self . assertEqual ( gaReference . length , reference . getLength ( ) ) <EOL> self . assertEqual ( gaReference . md5checksum , reference . getMd5Checksum ( ) ) <EOL> self . assertEqual ( gaReference . ncbiTaxonId , reference . getNcbiTaxonId ( ) ) <EOL> self . assertEqual ( gaReference . sourceURI , reference . getSourceUri ( ) ) <EOL> self . assertEqual ( <EOL> gaReference . sourceAccessions , reference . getSourceAccessions ( ) ) <EOL> self . assertEqual ( gaReference . isDerived , reference . getIsDerived ( ) ) <EOL> self . assertEqual ( <EOL> gaReference . sourceDivergence , reference . getSourceDivergence ( ) ) <EOL> def verifySearchMethod ( <EOL> self , request , path , responseClass , objects , objectVerifier ) : <EOL> """<STR_LIT>""" <EOL> request . pageSize = len ( objects ) <EOL> self . assertGreater ( request . pageSize , <NUM_LIT:0> ) <EOL> responseData = self . sendSearchRequest ( path , request , responseClass ) <EOL> self . assertIsNone ( responseData . nextPageToken ) <EOL> responseList = getattr ( responseData , responseClass . getValueListName ( ) ) <EOL> self . assertEqual ( len ( objects ) , len ( responseList ) ) <EOL> for gaObject , datamodelObject in zip ( responseList , objects ) : <EOL> objectVerifier ( gaObject , datamodelObject ) <EOL> def verifySearchResultsEmpty ( self , request , path , responseClass ) : <EOL> """<STR_LIT>""" <EOL> responseData = self . sendSearchRequest ( path , request , responseClass ) <EOL> self . assertIsNone ( responseData . nextPageToken ) <EOL> responseList = getattr ( responseData , responseClass . getValueListName ( ) ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( responseList ) ) <EOL> def assertObjectNotFound ( self , response ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( <NUM_LIT> , response . status_code ) <EOL> error = protocol . GAException . fromJsonString ( response . data ) <EOL> self . assertTrue ( error . validate ( error . toJsonDict ( ) ) ) <EOL> self . assertGreater ( error . errorCode , <NUM_LIT:0> ) <EOL> self . assertGreater ( len ( error . message ) , <NUM_LIT:0> ) <EOL> def assertObjectNotSupported ( self , response ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( <NUM_LIT> , response . status_code ) <EOL> error = protocol . GAException . fromJsonString ( response . data ) <EOL> self . assertTrue ( error . validate ( error . toJsonDict ( ) ) ) <EOL> self . assertGreater ( error . errorCode , <NUM_LIT:0> ) <EOL> self . assertGreater ( len ( error . message ) , <NUM_LIT:0> ) <EOL> def verifySearchMethodFails ( self , request , path ) : <EOL> """<STR_LIT>""" <EOL> response = self . sendJsonPostRequest ( path , request . toJsonString ( ) ) <EOL> self . assertObjectNotFound ( response ) <EOL> def verifySearchMethodNotSupported ( self , request , path ) : <EOL> response = self . sendJsonPostRequest ( path , request . toJsonString ( ) ) <EOL> self . assertObjectNotSupported ( response ) <EOL> def verifyGetMethodFails ( self , path , id_ ) : <EOL> """<STR_LIT>""" <EOL> response = self . sendObjectGetRequest ( path , id_ ) <EOL> self . assertObjectNotFound ( response ) <EOL> def testGetDataset ( self ) : <EOL> path = "<STR_LIT>" <EOL> for dataset in self . dataRepo . getDatasets ( ) : <EOL> responseObject = self . sendGetObject ( <EOL> path , dataset . getId ( ) , protocol . Dataset ) <EOL> self . verifyDatasetsEqual ( responseObject , dataset ) <EOL> for badId in self . getBadIds ( ) : <EOL> self . verifyGetMethodFails ( path , badId ) <EOL> def testDatasetsSearch ( self ) : <EOL> request = protocol . SearchDatasetsRequest ( ) <EOL> datasets = self . dataRepo . getDatasets ( ) <EOL> path = '<STR_LIT>' <EOL> self . verifySearchMethod ( <EOL> request , path , protocol . SearchDatasetsResponse , datasets , <EOL> self . verifyDatasetsEqual ) <EOL> def testVariantSetsSearch ( self ) : <EOL> path = '<STR_LIT>' <EOL> for dataset in self . dataRepo . getDatasets ( ) : <EOL> variantSets = dataset . getVariantSets ( ) <EOL> request = protocol . SearchVariantSetsRequest ( ) <EOL> request . datasetId = dataset . getId ( ) <EOL> self . verifySearchMethod ( <EOL> request , path , protocol . SearchVariantSetsResponse , variantSets , <EOL> self . verifyVariantSetsEqual ) <EOL> for badId in self . getBadIds ( ) : <EOL> request = protocol . SearchVariantSetsRequest ( ) <EOL> request . datasetId = badId <EOL> self . verifySearchMethodFails ( request , path ) <EOL> def testCallSetsSearch ( self ) : <EOL> path = '<STR_LIT>' <EOL> for dataset in self . dataRepo . getDatasets ( ) : <EOL> for variantSet in dataset . getVariantSets ( ) : <EOL> callSets = variantSet . getCallSets ( ) <EOL> self . assertGreater ( len ( callSets ) , <NUM_LIT:0> ) <EOL> request = protocol . SearchCallSetsRequest ( ) <EOL> request . variantSetId = variantSet . getId ( ) <EOL> self . verifySearchMethod ( <EOL> request , path , protocol . SearchCallSetsResponse , callSets , <EOL> self . verifyCallSetsEqual ) <EOL> for callSet in callSets : <EOL> request = protocol . SearchCallSetsRequest ( ) <EOL> request . variantSetId = variantSet . getId ( ) <EOL> request . name = callSet . getLocalId ( ) <EOL> self . verifySearchMethod ( <EOL> request , path , protocol . SearchCallSetsResponse , <EOL> [ callSet ] , self . verifyCallSetsEqual ) <EOL> for badId in self . getBadIds ( ) : <EOL> request = protocol . SearchCallSetsRequest ( ) <EOL> request . variantSetId = variantSet . getId ( ) <EOL> request . name = badId <EOL> self . verifySearchResultsEmpty ( <EOL> request , path , protocol . SearchCallSetsResponse ) <EOL> for badId in self . getBadIds ( ) : <EOL> request = protocol . SearchCallSetsRequest ( ) <EOL> request . variantSetId = badId <EOL> self . verifySearchMethodFails ( request , path ) <EOL> def testReadGroupSetsSearch ( self ) : <EOL> path = '<STR_LIT>' <EOL> for dataset in self . dataRepo . getDatasets ( ) : <EOL> readGroupSets = dataset . getReadGroupSets ( ) <EOL> request = protocol . SearchReadGroupSetsRequest ( ) <EOL> request . datasetId = dataset . getId ( ) <EOL> self . verifySearchMethod ( <EOL> request , path , protocol . SearchReadGroupSetsResponse , <EOL> readGroupSets , self . verifyReadGroupSetsEqual ) <EOL> for readGroupSet in readGroupSets : <EOL> request = protocol . SearchReadGroupSetsRequest ( ) <EOL> request . datasetId = dataset . getId ( ) <EOL> request . name = readGroupSet . getLocalId ( ) <EOL> self . verifySearchMethod ( <EOL> request , path , protocol . SearchReadGroupSetsResponse , <EOL> [ readGroupSet ] , self . verifyReadGroupSetsEqual ) <EOL> for badId in self . getBadIds ( ) : <EOL> request = protocol . SearchReadGroupSetsRequest ( ) <EOL> request . datasetId = dataset . getId ( ) <EOL> request . name = badId <EOL> self . verifySearchResultsEmpty ( <EOL> request , path , protocol . SearchReadGroupSetsResponse ) <EOL> for badId in self . getBadIds ( ) : <EOL> request = protocol . SearchReadGroupSetsRequest ( ) <EOL> request . datasetId = badId <EOL> self . verifySearchMethodFails ( request , path ) <EOL> def testReferenceSetsSearch ( self ) : <EOL> request = protocol . SearchReferenceSetsRequest ( ) <EOL> referenceSets = self . dataRepo . getReferenceSets ( ) <EOL> path = '<STR_LIT>' <EOL> self . verifySearchMethod ( <EOL> request , path , protocol . SearchReferenceSetsResponse , referenceSets , <EOL> self . verifyReferenceSetsEqual ) <EOL> def testReferencesSearch ( self ) : <EOL> path = '<STR_LIT>' <EOL> for referenceSet in self . dataRepo . getReferenceSets ( ) : <EOL> references = referenceSet . getReferences ( ) <EOL> request = protocol . SearchReferencesRequest ( ) <EOL> request . referenceSetId = referenceSet . getId ( ) <EOL> self . verifySearchMethod ( <EOL> request , path , protocol . SearchReferencesResponse , references , <EOL> self . verifyReferencesEqual ) <EOL> for badId in self . getBadIds ( ) : <EOL> request = protocol . SearchReferencesRequest ( ) <EOL> request . referenceSetId = badId <EOL> self . verifySearchMethodFails ( request , path ) <EOL> def verifyReferenceSearchFilters ( <EOL> self , objectList , hasAssemblyId , path , requestFactory , <EOL> responseClass , objectVerifier ) : <EOL> """<STR_LIT>""" <EOL> self . assertGreater ( len ( objectList ) , <NUM_LIT:2> ) <EOL> for obj in objectList [ <NUM_LIT:1> : ] : <EOL> request = requestFactory ( ) <EOL> request . md5checksum = obj . getMd5Checksum ( ) <EOL> self . verifySearchMethod ( <EOL> request , path , responseClass , [ obj ] , objectVerifier ) <EOL> request . md5checksum = None <EOL> request . accession = obj . getSourceAccessions ( ) [ <NUM_LIT:0> ] <EOL> self . verifySearchMethod ( <EOL> request , path , responseClass , [ obj ] , objectVerifier ) <EOL> request . accession = None <EOL> if hasAssemblyId : <EOL> request . assemblyId = obj . getAssemblyId ( ) <EOL> self . verifySearchMethod ( <EOL> request , path , responseClass , [ obj ] , objectVerifier ) <EOL> request . assemblyId = None <EOL> request . md5checksum = obj . getMd5Checksum ( ) <EOL> badAccessions = [ <EOL> "<STR_LIT>" , objectList [ <NUM_LIT:0> ] . getSourceAccessions ( ) [ <NUM_LIT:0> ] ] <EOL> for accession in badAccessions : <EOL> request . accession = accession <EOL> self . verifySearchResultsEmpty ( request , path , responseClass ) <EOL> request . accession = None <EOL> if hasAssemblyId : <EOL> badAssemblyIds = [ <EOL> "<STR_LIT>" , objectList [ <NUM_LIT:0> ] . getAssemblyId ( ) ] <EOL> for assemblyId in badAssemblyIds : <EOL> request . assemblyId = assemblyId <EOL> self . verifySearchResultsEmpty ( request , path , responseClass ) <EOL> request . assemblyId = None <EOL> def testReferencesSearchFilters ( self ) : <EOL> path = '<STR_LIT>' <EOL> for referenceSet in self . dataRepo . getReferenceSets ( ) : <EOL> def requestFactory ( ) : <EOL> request = protocol . SearchReferencesRequest ( ) <EOL> request . referenceSetId = referenceSet . getId ( ) <EOL> return request <EOL> self . verifyReferenceSearchFilters ( <EOL> referenceSet . getReferences ( ) , False , path , requestFactory , <EOL> protocol . SearchReferencesResponse , self . verifyReferencesEqual ) <EOL> def testReferenceSetsSearchFilters ( self ) : <EOL> path = '<STR_LIT>' <EOL> def requestFactory ( ) : <EOL> return protocol . SearchReferenceSetsRequest ( ) <EOL> self . verifyReferenceSearchFilters ( <EOL> self . dataRepo . getReferenceSets ( ) , True , path , requestFactory , <EOL> protocol . SearchReferenceSetsResponse , <EOL> self . verifyReferenceSetsEqual ) <EOL> def testGetVariantSet ( self ) : <EOL> path = "<STR_LIT>" <EOL> for dataset in self . dataRepo . getDatasets ( ) : <EOL> for variantSet in dataset . getVariantSets ( ) : <EOL> responseObject = self . sendGetObject ( <EOL> path , variantSet . getId ( ) , protocol . VariantSet ) <EOL> self . verifyVariantSetsEqual ( responseObject , variantSet ) <EOL> for badId in self . getBadIds ( ) : <EOL> variantSet = variants . AbstractVariantSet ( dataset , badId ) <EOL> self . verifyGetMethodFails ( path , variantSet . getId ( ) ) <EOL> for badId in self . getBadIds ( ) : <EOL> self . verifyGetMethodFails ( path , badId ) <EOL> def testGetVariantAnnotationSet ( self ) : <EOL> path = "<STR_LIT>" <EOL> for dataset in self . dataRepo . getDatasets ( ) : <EOL> for variantAnnotationSet in dataset . getVariantAnnotationSets ( ) : <EOL> responseObject = self . sendGetObject ( <EOL> path , variantAnnotationSet . getId ( ) , <EOL> protocol . VariantAnnotationSet ) <EOL> self . assertEqual ( variantAnnotationSet . getId ( ) , <EOL> responseObject . id , <EOL> "<STR_LIT>" ) <EOL> for badId in self . getBadIds ( ) : <EOL> self . verifyGetMethodFails ( path , badId ) <EOL> def testGetVariant ( self ) : <EOL> referenceName = '<STR_LIT:1>' <EOL> start = <NUM_LIT:0> <EOL> request = protocol . SearchVariantsRequest ( ) <EOL> request . variantSetId = self . variantSet . getId ( ) <EOL> request . referenceName = referenceName <EOL> request . start = start <EOL> request . end = <NUM_LIT:2> ** <NUM_LIT:16> <EOL> path = '<STR_LIT>' <EOL> responseData = self . sendSearchRequest ( <EOL> path , request , protocol . SearchVariantsResponse ) <EOL> variants = responseData . variants [ : <NUM_LIT:10> ] <EOL> for variant in variants : <EOL> path = '<STR_LIT>' <EOL> responseObject = self . sendGetObject ( <EOL> path , variant . id , protocol . Variant ) <EOL> self . assertEqual ( responseObject , variant ) <EOL> def testGetReferenceSet ( self ) : <EOL> path = "<STR_LIT>" <EOL> for referenceSet in self . dataRepo . getReferenceSets ( ) : <EOL> responseObject = self . sendGetObject ( <EOL> path , referenceSet . getId ( ) , protocol . ReferenceSet ) <EOL> self . verifyReferenceSetsEqual ( responseObject , referenceSet ) <EOL> for badId in self . getBadIds ( ) : <EOL> self . verifyGetMethodFails ( path , badId ) <EOL> def testGetReference ( self ) : <EOL> path = "<STR_LIT>" <EOL> for referenceSet in self . dataRepo . getReferenceSets ( ) : <EOL> for reference in referenceSet . getReferences ( ) : <EOL> responseObject = self . sendGetObject ( <EOL> path , reference . getId ( ) , protocol . Reference ) <EOL> self . verifyReferencesEqual ( responseObject , reference ) <EOL> for badId in self . getBadIds ( ) : <EOL> referenceSet = references . AbstractReferenceSet ( badId ) <EOL> self . verifyGetMethodFails ( path , referenceSet . getId ( ) ) <EOL> for badId in self . getBadIds ( ) : <EOL> self . verifyGetMethodFails ( path , badId ) <EOL> def testGetCallSet ( self ) : <EOL> path = "<STR_LIT>" <EOL> for dataset in self . dataRepo . getDatasets ( ) : <EOL> for variantSet in dataset . getVariantSets ( ) : <EOL> for callSet in variantSet . getCallSets ( ) : <EOL> responseObject = self . sendGetObject ( <EOL> path , callSet . getId ( ) , protocol . CallSet ) <EOL> self . verifyCallSetsEqual ( responseObject , callSet ) <EOL> for badId in self . getBadIds ( ) : <EOL> callSet = variants . CallSet ( variantSet , badId ) <EOL> self . verifyGetMethodFails ( path , callSet . getId ( ) ) <EOL> for badId in self . getBadIds ( ) : <EOL> self . verifyGetMethodFails ( path , badId ) <EOL> def testGetReadGroup ( self ) : <EOL> path = "<STR_LIT>" <EOL> for dataset in self . dataRepo . getDatasets ( ) : <EOL> for readGroupSet in dataset . getReadGroupSets ( ) : <EOL> for readGroup in readGroupSet . getReadGroups ( ) : <EOL> responseObject = self . sendGetObject ( <EOL> path , readGroup . getId ( ) , protocol . ReadGroup ) <EOL> self . verifyReadGroupsEqual ( responseObject , readGroup ) <EOL> for badId in self . getBadIds ( ) : <EOL> readGroup = reads . AbstractReadGroup ( readGroupSet , badId ) <EOL> self . verifyGetMethodFails ( path , readGroup . getId ( ) ) <EOL> for badId in self . getBadIds ( ) : <EOL> readGroupSet = reads . AbstractReadGroupSet ( dataset , badId ) <EOL> self . verifyGetMethodFails ( path , readGroupSet . getId ( ) ) <EOL> for badId in self . getBadIds ( ) : <EOL> self . verifyGetMethodFails ( path , badId ) <EOL> def testVariantsSearch ( self ) : <EOL> referenceName = '<STR_LIT:1>' <EOL> request = protocol . SearchVariantsRequest ( ) <EOL> request . referenceName = referenceName <EOL> request . start = <NUM_LIT:0> <EOL> request . end = <NUM_LIT:0> <EOL> request . variantSetId = self . variantSet . getId ( ) <EOL> path = '<STR_LIT>' <EOL> responseData = self . sendSearchRequest ( <EOL> path , request , protocol . SearchVariantsResponse ) <EOL> self . assertIsNone ( responseData . nextPageToken ) <EOL> self . assertEqual ( [ ] , responseData . variants ) <EOL> request . end = <NUM_LIT:2> ** <NUM_LIT:16> <EOL> responseData = self . sendSearchRequest ( <EOL> path , request , protocol . SearchVariantsResponse ) <EOL> self . assertTrue ( protocol . SearchVariantsResponse . validate ( <EOL> responseData . toJsonDict ( ) ) ) <EOL> self . assertGreater ( len ( responseData . variants ) , <NUM_LIT:0> ) <EOL> for variant in responseData . variants : <EOL> self . assertGreaterEqual ( variant . start , <NUM_LIT:0> ) <EOL> self . assertLessEqual ( variant . end , <NUM_LIT:2> ** <NUM_LIT:16> ) <EOL> self . assertEqual ( variant . variantSetId , self . variantSet . getId ( ) ) <EOL> self . assertEqual ( variant . referenceName , referenceName ) <EOL> def testVariantAnnotationSetsSearch ( self ) : <EOL> self . assertIsNotNone ( self . variantAnnotationSet ) <EOL> request = protocol . SearchVariantAnnotationSetsRequest ( ) <EOL> request . variantSetId = "<STR_LIT>" <EOL> path = '<STR_LIT>' <EOL> response = self . sendJsonPostRequest ( path , request . toJsonString ( ) ) <EOL> responseData = protocol . SearchVariantAnnotationSetsResponse . fromJsonString ( response . data ) <EOL> self . assertTrue ( responseData . validate ( responseData . toJsonDict ( ) ) ) <EOL> self . assertIsNone ( responseData . nextPageToken ) <EOL> self . assertEqual ( [ ] , responseData . variantAnnotationSets , <EOL> "<STR_LIT>" ) <EOL> request . variantSetId = self . variantSet . getId ( ) <EOL> response = self . sendJsonPostRequest ( path , request . toJsonString ( ) ) <EOL> responseData = protocol . SearchVariantAnnotationSetsResponse . fromJsonString ( response . data ) <EOL> self . assertTrue ( protocol . SearchVariantAnnotationSetsResponse . validate ( <EOL> responseData . toJsonDict ( ) ) ) <EOL> self . assertGreater ( len ( responseData . variantAnnotationSets ) , <NUM_LIT:0> , <EOL> "<STR_LIT>" ) <EOL> def testVariantAnnotationsSearch ( self ) : <EOL> self . assertIsNotNone ( self . variantAnnotationSet ) <EOL> request = protocol . SearchVariantAnnotationsRequest ( ) <EOL> path = '<STR_LIT>' <EOL> request . start = <NUM_LIT:0> <EOL> request . end = <NUM_LIT> <EOL> request . pageSize = <NUM_LIT:1> <EOL> request . referenceName = "<STR_LIT:1>" <EOL> request . effects = None <EOL> request . variantAnnotationSetId = self . variantAnnotationSet . getId ( ) <EOL> response = self . sendJsonPostRequest ( path , request . toJsonString ( ) ) <EOL> responseData = protocol . SearchVariantAnnotationSetsResponse . fromJsonString ( response . data ) <EOL> self . assertIsNotNone ( <EOL> responseData . nextPageToken , <EOL> "<STR_LIT>" ) <EOL> request = protocol . SearchVariantAnnotationsRequest ( ) <EOL> request . variantAnnotationSetId = self . variantAnnotationSet . getId ( ) <EOL> request . start = <NUM_LIT:0> <EOL> request . end = <NUM_LIT:10> <EOL> request . referenceName = "<STR_LIT:1>" <EOL> request . effects = [ { "<STR_LIT:id>" : "<STR_LIT>" } ] <EOL> response = self . sendJsonPostRequest ( path , request . toJsonString ( ) ) <EOL> responseData = protocol . SearchVariantAnnotationsResponse . fromJsonString ( response . data ) <EOL> self . assertEquals ( <EOL> len ( responseData . variantAnnotations ) , <NUM_LIT:0> , <EOL> "<STR_LIT>" ) <EOL> request = protocol . SearchVariantAnnotationsRequest ( ) <EOL> request . variantAnnotationSetId = self . variantAnnotationSet . getId ( ) <EOL> request . start = <NUM_LIT:0> <EOL> request . end = <NUM_LIT:10> <EOL> request . referenceName = "<STR_LIT:1>" <EOL> response = self . sendJsonPostRequest ( path , request . toJsonString ( ) ) <EOL> responseData = protocol . SearchVariantAnnotationsResponse . fromJsonString ( response . data ) <EOL> self . assertGreater ( len ( responseData . variantAnnotations ) , <NUM_LIT:0> ) <EOL> for ann in responseData . variantAnnotations : <EOL> self . assertGreater ( <EOL> len ( ann . transcriptEffects ) , <NUM_LIT:0> , <EOL> ( "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> request = protocol . SearchVariantAnnotationsRequest ( ) <EOL> request . variantAnnotationSetId = self . variantAnnotationSet . getId ( ) <EOL> request . start = <NUM_LIT:0> <EOL> request . end = <NUM_LIT:5> <EOL> request . referenceName = "<STR_LIT:1>" <EOL> request . effects = [ { "<STR_LIT:id>" : "<STR_LIT>" } , { "<STR_LIT:id>" : "<STR_LIT>" } ] <EOL> response = self . sendJsonPostRequest ( path , request . toJsonString ( ) ) <EOL> responseData = protocol . SearchVariantAnnotationsResponse . fromJsonString ( response . data ) <EOL> responseLength = len ( responseData . variantAnnotations ) <EOL> self . assertGreater ( <EOL> responseLength , <NUM_LIT:0> , <EOL> "<STR_LIT>" ) <EOL> for ann in responseData . variantAnnotations : <EOL> effectPresent = False <EOL> for effect in ann . transcriptEffects : <EOL> for featureType in effect . effects : <EOL> if featureType . id in map ( <EOL> lambda e : e [ '<STR_LIT:id>' ] , request . effects ) : <EOL> effectPresent = True <EOL> self . assertEquals ( <EOL> True , effectPresent , <EOL> "<STR_LIT>" ) <EOL> request = protocol . SearchVariantAnnotationsRequest ( ) <EOL> request . variantAnnotationSetId = self . variantAnnotationSet . getId ( ) <EOL> request . start = <NUM_LIT:0> <EOL> request . end = <NUM_LIT:5> <EOL> request . referenceName = "<STR_LIT:1>" <EOL> request . effects = [ { "<STR_LIT:id>" : "<STR_LIT>" } , { "<STR_LIT:id>" : "<STR_LIT>" } ] <EOL> response = self . sendJsonPostRequest ( path , request . toJsonString ( ) ) <EOL> responseData = protocol . SearchVariantAnnotationsResponse . fromJsonString ( response . data ) <EOL> self . assertEqual ( <EOL> len ( responseData . variantAnnotations ) , <EOL> responseLength , <EOL> "<STR_LIT>" ) <EOL> for ann in responseData . variantAnnotations : <EOL> effectPresent = False <EOL> for effect in ann . transcriptEffects : <EOL> for featureType in effect . effects : <EOL> if featureType . id in map ( <EOL> lambda e : e [ '<STR_LIT:id>' ] , request . effects ) : <EOL> effectPresent = True <EOL> self . assertEquals ( <EOL> True , <EOL> effectPresent , <EOL> "<STR_LIT>" ) <EOL> request = protocol . SearchVariantAnnotationsRequest ( ) <EOL> request . variantAnnotationSetId = self . variantAnnotationSet . getId ( ) <EOL> request . start = <NUM_LIT:0> <EOL> request . end = <NUM_LIT:5> <EOL> request . referenceName = "<STR_LIT:1>" <EOL> request . effects = [ { "<STR_LIT:id>" : "<STR_LIT>" } ] <EOL> response = self . sendJsonPostRequest ( path , request . toJsonString ( ) ) <EOL> responseData = protocol . SearchVariantAnnotationsResponse . fromJsonString ( response . data ) <EOL> self . assertGreater ( len ( responseData . variantAnnotations ) , <NUM_LIT:0> , <EOL> "<STR_LIT>" ) <EOL> for ann in responseData . variantAnnotations : <EOL> effectPresent = False <EOL> for effect in ann . transcriptEffects : <EOL> for featureType in effect . effects : <EOL> if featureType . id in map ( <EOL> lambda e : e [ '<STR_LIT:id>' ] , request . effects ) : <EOL> effectPresent = True <EOL> self . assertEquals ( True , effectPresent , <EOL> "<STR_LIT>" ) <EOL> request = protocol . SearchVariantAnnotationsRequest ( ) <EOL> request . variantAnnotationSetId = self . variantAnnotationSet . getId ( ) <EOL> request . start = <NUM_LIT:0> <EOL> request . end = <NUM_LIT:10> <EOL> request . referenceName = "<STR_LIT:1>" <EOL> request . effects = [ { "<STR_LIT:id>" : "<STR_LIT>" } , { "<STR_LIT:id>" : "<STR_LIT>" } ] <EOL> response = self . sendJsonPostRequest ( path , request . toJsonString ( ) ) <EOL> responseData = protocol . SearchVariantAnnotationsResponse . fromJsonString ( response . data ) <EOL> self . assertGreater ( len ( responseData . variantAnnotations ) , <NUM_LIT:0> ) <EOL> def testGetFeatureSet ( self ) : <EOL> path = "<STR_LIT>" <EOL> for dataset in self . dataRepo . getDatasets ( ) : <EOL> for featureSet in dataset . getFeatureSets ( ) : <EOL> responseObject = self . sendGetObject ( <EOL> path , featureSet . getId ( ) , protocol . FeatureSet ) <EOL> self . verifyFeatureSetsEqual ( responseObject , featureSet ) <EOL> for badId in self . getBadIds ( ) : <EOL> featureSet = features . AbstractFeatureSet ( dataset , badId ) <EOL> self . verifyGetMethodFails ( path , featureSet . getId ( ) ) <EOL> for badId in self . getBadIds ( ) : <EOL> self . verifyGetMethodFails ( path , badId ) <EOL> def testFeatureSetsSearch ( self ) : <EOL> path = '<STR_LIT>' <EOL> for dataset in self . dataRepo . getDatasets ( ) : <EOL> featureSets = dataset . getFeatureSets ( ) <EOL> request = protocol . SearchFeatureSetsRequest ( ) <EOL> request . datasetId = dataset . getId ( ) <EOL> self . verifySearchMethod ( <EOL> request , path , protocol . SearchFeatureSetsResponse , featureSets , <EOL> self . verifyFeatureSetsEqual ) <EOL> for badId in self . getBadIds ( ) : <EOL> request = protocol . SearchFeatureSetsRequest ( ) <EOL> request . datasetId = badId <EOL> self . verifySearchMethodFails ( request , path ) <EOL> def testGetFeature ( self ) : <EOL> dataset = self . dataRepo . getDatasets ( ) [ <NUM_LIT:0> ] <EOL> featureSet = dataset . getFeatureSets ( ) [ <NUM_LIT:0> ] <EOL> request = protocol . SearchFeaturesRequest ( ) <EOL> request . featureSetId = featureSet . getId ( ) <EOL> request . referenceName = "<STR_LIT>" <EOL> request . start = <NUM_LIT:0> <EOL> request . end = <NUM_LIT:2> ** <NUM_LIT:16> <EOL> request . parentId = None <EOL> request . featureTypes = [ ] <EOL> path = '<STR_LIT>' <EOL> responseData = self . sendSearchRequest ( <EOL> path , request , protocol . SearchFeaturesResponse ) <EOL> features = responseData . features [ : <NUM_LIT:10> ] <EOL> for feature in features : <EOL> path = '<STR_LIT>' <EOL> responseObject = self . sendGetObject ( <EOL> path , feature . id , protocol . Feature ) <EOL> self . verifyFeaturesEquivalent ( responseObject , feature ) <EOL> def testFeaturesSearch ( self ) : <EOL> dataset = self . dataRepo . getDatasets ( ) [ <NUM_LIT:0> ] <EOL> featureSet = dataset . getFeatureSets ( ) [ <NUM_LIT:0> ] <EOL> referenceName = '<STR_LIT>' <EOL> request = protocol . SearchFeaturesRequest ( ) <EOL> request . referenceName = referenceName <EOL> request . featureSetId = featureSet . getId ( ) <EOL> request . start = <NUM_LIT:0> <EOL> request . end = <NUM_LIT:1> <EOL> request . parentId = '<STR_LIT>' <EOL> path = '<STR_LIT>' <EOL> responseData = self . sendSearchRequest ( <EOL> path , request , protocol . SearchFeaturesResponse ) <EOL> self . assertIsNone ( responseData . nextPageToken ) <EOL> self . assertEqual ( [ ] , responseData . features ) <EOL> request . start = <NUM_LIT:0> <EOL> request . end = <NUM_LIT:2> ** <NUM_LIT:16> <EOL> responseData = self . sendSearchRequest ( <EOL> path , request , protocol . SearchFeaturesResponse ) <EOL> self . assertTrue ( protocol . SearchFeaturesResponse . validate ( <EOL> responseData . toJsonDict ( ) ) ) <EOL> self . assertGreater ( len ( responseData . features ) , <NUM_LIT:0> ) <EOL> for feature in responseData . features : <EOL> self . assertGreaterEqual ( feature . start , <NUM_LIT:0> ) <EOL> self . assertLessEqual ( feature . end , <NUM_LIT:2> ** <NUM_LIT:16> ) <EOL> self . assertEqual ( feature . featureSetId , featureSet . getId ( ) ) <EOL> self . assertEqual ( feature . referenceName , referenceName ) <EOL> def testListReferenceBases ( self ) : <EOL> for referenceSet in self . dataRepo . getReferenceSets ( ) : <EOL> for reference in referenceSet . getReferences ( ) : <EOL> id_ = reference . getId ( ) <EOL> length = reference . getLength ( ) <EOL> sequence = reference . getBases ( <NUM_LIT:0> , length ) <EOL> args = protocol . ListReferenceBasesRequest ( ) <EOL> response = self . sendListReferenceBasesRequest ( id_ , args ) <EOL> self . assertEqual ( response . sequence , sequence ) <EOL> ranges = [ ( <NUM_LIT:0> , length ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) , ( length - <NUM_LIT:1> , length ) , ( <NUM_LIT:0> , <NUM_LIT:0> ) ] <EOL> for start , end in ranges : <EOL> args = protocol . ListReferenceBasesRequest ( ) <EOL> args . start , args . end = start , end <EOL> response = self . sendListReferenceBasesRequest ( id_ , args ) <EOL> self . assertEqual ( response . sequence , sequence [ start : end ] ) <EOL> self . assertIsNone ( response . nextPageToken ) <EOL> self . assertEqual ( response . offset , start ) <EOL> def testListReferenceBasesErrors ( self ) : <EOL> referenceSet = self . dataRepo . getReferenceSets ( ) [ <NUM_LIT:0> ] <EOL> for badId in self . getBadIds ( ) : <EOL> path = '<STR_LIT>' . format ( badId ) <EOL> response = self . app . get ( path ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> reference = references . AbstractReference ( referenceSet , badId ) <EOL> path = '<STR_LIT>' . format ( reference . getId ( ) ) <EOL> response = self . app . get ( path ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> path = '<STR_LIT>' . format ( self . reference . getId ( ) ) <EOL> length = self . reference . getLength ( ) <EOL> badRanges = [ ( - <NUM_LIT:1> , <NUM_LIT:0> ) , ( - <NUM_LIT:1> , - <NUM_LIT:1> ) , ( length , <NUM_LIT:0> ) , ( <NUM_LIT:0> , length + <NUM_LIT:1> ) ] <EOL> for start , end in badRanges : <EOL> args = protocol . ListReferenceBasesRequest ( ) <EOL> args . start , args . end = start , end <EOL> response = self . app . get ( path , query_string = args . toJsonDict ( ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def testListReferenceBasesPaging ( self ) : <EOL> id_ = self . reference . getId ( ) <EOL> length = self . reference . getLength ( ) <EOL> completeSequence = self . reference . getBases ( <NUM_LIT:0> , length ) <EOL> for start , end in [ ( <NUM_LIT:0> , length ) , ( <NUM_LIT:5> , <NUM_LIT:10> ) , ( length // <NUM_LIT:2> , length ) ] : <EOL> sequence = completeSequence [ start : end ] <EOL> for pageSize in [ <NUM_LIT:1> , <NUM_LIT:2> , length - <NUM_LIT:1> ] : <EOL> self . backend . setMaxResponseLength ( pageSize ) <EOL> args = protocol . ListReferenceBasesRequest ( ) <EOL> args . start , args . end = start , end <EOL> response = self . sendListReferenceBasesRequest ( id_ , args ) <EOL> self . assertEqual ( response . sequence , sequence [ : pageSize ] ) <EOL> self . assertEqual ( response . offset , start ) <EOL> sequenceFragments = [ response . sequence ] <EOL> while response . nextPageToken is not None : <EOL> args = protocol . ListReferenceBasesRequest ( ) <EOL> args . pageToken = response . nextPageToken <EOL> args . start , args . end = start , end <EOL> response = self . sendListReferenceBasesRequest ( id_ , args ) <EOL> self . assertGreater ( len ( response . sequence ) , <NUM_LIT:0> ) <EOL> sequenceFragments . append ( response . sequence ) <EOL> offset = response . offset <EOL> self . assertEqual ( <EOL> response . sequence , <EOL> completeSequence [ <EOL> offset : offset + len ( response . sequence ) ] ) <EOL> self . assertEqual ( "<STR_LIT>" . join ( sequenceFragments ) , sequence ) <EOL> def testReads ( self ) : <EOL> path = '<STR_LIT>' <EOL> for dataset in self . dataRepo . getDatasets ( ) : <EOL> for readGroupSet in dataset . getReadGroupSets ( ) : <EOL> referenceSet = readGroupSet . getReferenceSet ( ) <EOL> for reference in referenceSet . getReferences ( ) : <EOL> for readGroup in readGroupSet . getReadGroups ( ) : <EOL> request = protocol . SearchReadsRequest ( ) <EOL> request . readGroupIds = [ readGroup . getId ( ) ] <EOL> request . referenceId = reference . getId ( ) <EOL> responseData = self . sendSearchRequest ( <EOL> path , request , protocol . SearchReadsResponse ) <EOL> alignments = responseData . alignments <EOL> self . assertGreater ( len ( alignments ) , <NUM_LIT:0> ) <EOL> for alignment in alignments : <EOL> self . assertEqual ( <EOL> alignment . readGroupId , readGroup . getId ( ) ) <EOL> def testUnsupportedReadOperations ( self ) : <EOL> path = '<STR_LIT>' <EOL> request = protocol . SearchReadsRequest ( ) <EOL> request . readGroupIds = [ self . readGroup . getId ( ) ] <EOL> request . referenceId = None <EOL> self . verifySearchMethodNotSupported ( request , path ) <EOL> request . readGroupIds = [ self . readGroup . getId ( ) , "<STR_LIT>" ] <EOL> request . referenceId = self . reference . getId ( ) <EOL> response = self . sendJsonPostRequest ( path , request . toJsonString ( ) ) <EOL> self . assertEqual ( <NUM_LIT> , response . status_code ) <EOL> def testReadsMultipleReadGroupSets ( self ) : <EOL> path = '<STR_LIT>' <EOL> readGroupIds = [ <EOL> readGroup . getId ( ) for readGroup in <EOL> self . readGroupSet . getReadGroups ( ) ] <EOL> referenceId = self . reference . getId ( ) <EOL> request = protocol . SearchReadsRequest ( ) <EOL> request . readGroupIds = readGroupIds <EOL> request . referenceId = referenceId <EOL> responseData = self . sendSearchRequest ( <EOL> path , request , protocol . SearchReadsResponse ) <EOL> readGroupAlignments = [ ] <EOL> for readGroup in self . readGroupSet . getReadGroups ( ) : <EOL> readGroupAlignments . extend ( list ( <EOL> readGroup . getReadAlignments ( referenceId , None , None ) ) ) <EOL> alignments = responseData . alignments <EOL> self . assertEqual ( len ( alignments ) , len ( readGroupAlignments ) ) <EOL> for alignment , rgAlignment in zip ( alignments , readGroupAlignments ) : <EOL> self . assertEqual ( alignment . id , rgAlignment . id ) <EOL> self . assertEqual ( alignment . readGroupId , rgAlignment . readGroupId ) </s>
