1+ import os
12import json
23import unittest
34
67
78from elasticsearch import Elasticsearch
89
9- from mme_server import models
1010from mme_server .datastore import DatastoreConnection
1111from mme_server .schemas import validate_request , validate_response , ValidationError
1212
1919 'institution' : 'Contact Institution' ,
2020 'href' :
'mailto:[email protected] ' ,
2121 },
22+ 'ageOfOnset' : 'HP:0003577' ,
23+ 'inheritanceMode' : 'HP:0000006' ,
2224 'features' : [
2325 {
2426 'id' : 'HP:0000252' ,
2729 {
2830 'id' : 'HP:0000522' ,
2931 'label' : 'Alacrima' ,
32+ 'ageOfOnset' : 'HP:0003593' ,
3033 },
3134 ],
3235 'genomicFeatures' : [{
3336 "gene" : {
34- "id" : "EFTUD2"
37+ "id" : "EFTUD2" ,
3538 },
3639 "type" : {
3740 "id" : "SO:0001587" ,
38- "label" : "STOPGAIN"
41+ "label" : "STOPGAIN" ,
3942 },
4043 "variant" : {
4144 "alternateBases" : "A" ,
4245 "assembly" : "GRCh37" ,
4346 "end" : 42929131 ,
4447 "referenceBases" : "G" ,
4548 "referenceName" : "17" ,
46- "start" : 42929130
49+ "start" : 42929130 ,
4750 },
48- "zygosity" : 1
51+ "zygosity" : 1 ,
4952 }],
5053 'disorders' : [{
51- "id" : "MIM:610536"
54+ "id" : "MIM:610536" ,
5255 }],
5356 }
5457}
@@ -201,13 +204,11 @@ def setUp(self):
201204 def assertValidResponse (self , data ):
202205 validate_response (data )
203206
204- def test_with_headers (self ):
207+ def test_match_request (self ):
205208 response = self .client .post ('/match' , data = self .data , headers = self .headers )
206209 self .assertEqual (response .status_code , 200 )
207-
208- def test_response_content_type (self ):
209- response = self .client .post ('/match' , data = self .data , headers = self .headers )
210210 self .assertEqual (response .headers ['Content-Type' ], 'application/vnd.ga4gh.matchmaker.v1.0+json' )
211+ self .assertValidResponse (json .loads (response .get_data (as_text = True )))
211212
212213 def test_accept_header_required (self ):
213214 headers = self .headers
@@ -226,9 +227,29 @@ def test_invalid_query(self):
226227 self .assertEqual (response .status_code , 422 )
227228 self .assertTrue (json .loads (response .get_data (as_text = True ))['message' ])
228229
229- def test_response_schema (self ):
230+
231+ class EndToEndTests (unittest .TestCase ):
232+ def test_query (self ):
233+ from mme_server .server import app
234+ self .client = app .test_client ()
235+ self .data = json .dumps (EXAMPLE_REQUEST )
236+ self .accept_header = ('Accept' , 'application/vnd.ga4gh.matchmaker.v1.0+json' )
237+ self .content_type_header = ('Content-Type' , 'application/json' )
238+ self .headers = [self .accept_header , self .content_type_header ]
239+
230240 response = self .client .post ('/match' , data = self .data , headers = self .headers )
231- self .assertValidResponse (json .loads (response .get_data (as_text = True )))
241+ self .assertEqual (response .status_code , 200 )
242+ self .assertEqual (response .headers ['Content-Type' ], 'application/vnd.ga4gh.matchmaker.v1.0+json' )
243+ response_data = json .loads (response .get_data (as_text = True ))
244+ validate_response (response_data )
245+ self .assertEqual (len (response_data ['results' ]), 5 )
246+
247+ @unittest .skipUnless ('MME_TEST_QUICKSTART' in os .environ , 'Not testing quickstart data loading' )
248+ def test_quickstart (self ):
249+ from mme_server import main
250+ # Index all data
251+ main (['quickstart' ])
252+ self .test_query ()
232253
233254
234255if __name__ == '__main__' :
0 commit comments