Esempio n. 1
0
 def test_do_ned_query(self):
     '''Test to see if single NED object lookup behaves'''
     from object_service.NED import do_ned_object_lookup
     identifier = "LMC"
     mockdata = {
         u'NameResolver': u'NED-Egret',
         u'Copyright': u'(C) 2017 California Institute of Technology',
         u'Preferred': {
             u'Name': u'Large Magellanic Cloud'
         },
         u'ResultCode': 3,
         u'StatusCode': 100
     }
     QUERY_URL = self.app.config.get('OBJECTS_NED_URL')
     httpretty.register_uri(httpretty.POST,
                            QUERY_URL,
                            content_type='application/json',
                            status=500,
                            body='%s' % json.dumps(mockdata))
     result = do_ned_object_lookup(QUERY_URL, identifier)
     expected = {
         "Error": "Unable to get results!",
         "Error Info": "NED returned status 500"
     }
     self.assertEqual(result, expected)
Esempio n. 2
0
    def test_do_ned_lookup_exception(self):
        '''Test to see if single NED lookupthrows proper exception at timeout'''
        from object_service.NED import do_ned_object_lookup

        def exceptionCallback(request, uri, headers):
            raise Exception('Oops! Something went boink!')

        self.app.config['OBJECTS_NED_TIMEOUT'] = 0.1
        QUERY_URL = "http://aaaa.org"
        httpretty.register_uri(
            httpretty.POST, QUERY_URL,
            body=exceptionCallback)
        result = do_ned_object_lookup(QUERY_URL, "bar")
        expected = {'Error': 'Unable to get results!', 'Error Info': 'NED request failed (Oops! Something went boink!)'}
        self.assertDictEqual(result, expected)