def test_do_ned_refcode_query_non200(self): '''Test to see if single NED refcode query throws proper exception at non-timeout exception''' from object_service.NED import get_NED_refcodes obj_data = {'objects': ['FOO_BAR']} self.app.config['OBJECTS_NED_TIMEOUT'] = 0.1 QUERY_URL = self.app.config.get('OBJECTS_NED_URL') httpretty.register_uri(httpretty.POST, QUERY_URL, status=500, body={}) result = get_NED_refcodes(obj_data) expected = { 'Error': 'Unable to get results!', 'Error Info': 'NED returned status 500' } self.assertDictEqual(result, expected)
def test_do_ned_refcode_query_exception(self): '''Test to see if single NED refcode query throws proper exception at non-timeout exception''' from object_service.NED import get_NED_refcodes def exceptionCallback(request, uri, headers): raise Exception('Oops! Something went boink!') obj_data = {'objects': ['FOO_BAR']} self.app.config['OBJECTS_NED_TIMEOUT'] = 0.1 QUERY_URL = self.app.config.get('OBJECTS_NED_URL') httpretty.register_uri(httpretty.POST, QUERY_URL, body=exceptionCallback) result = get_NED_refcodes(obj_data) expected = { 'Error': 'Unable to get results!', 'Error Info': 'NED request failed (Oops! Something went boink!)' } self.assertDictEqual(result, expected)
def test_malformed_solr_response(self): '''Test to see if single NED object lookup behaves''' from object_service.NED import get_NED_refcodes # Inpiut data obj_data = { 'objects': ['FOO_BAR'], 'journals': ['ApJ', 'A&A'], 'refereed_status': 'refereed' } # Solr mock solr_mockdata = {'foo': 'bar'} SOLR_URL = self.app.config.get('OBJECTS_SOLRQUERY_URL') httpretty.register_uri(httpretty.GET, SOLR_URL, content_type='application/json', status=200, body='%s' % json.dumps(solr_mockdata)) # NED mock ned_mockdata = { u'NameResolver': u'NED-Egret', u'Copyright': u'(C) 2017 California Institute of Technology', u'Preferred': { u'Name': u'FOO BAR' }, u'ResultCode': 3, u'StatusCode': 100 } NED_URL = self.app.config.get('OBJECTS_NED_URL') httpretty.register_uri(httpretty.POST, NED_URL, content_type='application/json', status=200, body='%s' % json.dumps(ned_mockdata)) # Now run the query result = get_NED_refcodes(obj_data) expected = { "Error": "Unable to get results!", "Error Info": "No bibcodes returned for query: nedid:FOO_BAR year:1800-2018 bibstem:(ApJ OR A&A) property:refereed" } self.assertEqual(result, expected)
def test_error_solr_response(self): '''Test to see if single NED object lookup behaves''' from object_service.NED import get_NED_refcodes # Inpiut data obj_data = {'objects': ['FOO_BAR']} # Solr mock solr_mockdata = {'foo': 'bar'} SOLR_URL = self.app.config.get('OBJECTS_SOLRQUERY_URL') httpretty.register_uri(httpretty.GET, SOLR_URL, content_type='application/json', status=500, body='we have a problem') # NED mock ned_mockdata = { u'NameResolver': u'NED-Egret', u'Copyright': u'(C) 2017 California Institute of Technology', u'Preferred': { u'Name': u'FOO BAR' }, u'ResultCode': 3, u'StatusCode': 100 } NED_URL = self.app.config.get('OBJECTS_NED_URL') httpretty.register_uri(httpretty.POST, NED_URL, content_type='application/json', status=200, body='%s' % json.dumps(ned_mockdata)) # Now run the query result = get_NED_refcodes(obj_data) expected = { "Error": "Unable to get results!", "Error Info": "we have a problem", "Status Code": 500 } self.assertEqual(result, expected)