Exemple #1
0
 def test_error_response_pagination(self):
     """Tests the get functions in case of an error coming from SOLR"""
     error_response = {"responseHeader":{
                         "status":400,
                         "QTime":1,},
                       "error":{
                         "msg":"org.apache.lucene.queryparser.classic.ParseException: undefined field authsorfsd",
                         "code":400}}
      
     with canned_solr_response_data(error_response):
         with self.app.test_request_context():
             resp = solr.query("foo")
              
             self.assertEqual(resp.get_count(), 0)
             self.assertEqual(resp.get_hits(), 0)
             self.assertEqual(resp.get_start_count(), 0)
              
             #pagination dictionar.y
             pag_dict = {
                    'max_pagination_len': 5 ,
                    'num_total_pages': 0,
                    'current_page': 1,
                    'pages_before': [],
                    'pages_after': [],       
             }
             self.assertEqual(resp.get_pagination(), pag_dict)
Exemple #2
0
 def test_response_content_with_facets(self):
     with canned_solr_response_data():
         with self.app.test_request_context():
             resp = solr.query("foo", facets=[('year',)])
             resp_data = resp.search_response()
             self.assertIn('facets', resp_data['results'])
             self.assertEqual(resp.get_all_facet_queries(), {'year:[2000 TO 2003]': 13})
             self.assertEqual(resp.get_all_facet_fields(), {'bibstem_facet': ['ApJ', 10, 'ArXiv', 8], 'year': ['2009', 3, '2008', 5]})
 def test_empty_dev_key(self):
     """ensure that a user record with a dev_key of "" doesn't allow access to empty dev_key input"""
     
     self.insert_user("foo", developer=True)
     with canned_solr_response_data():
         user = AdsApiUser.from_dev_key("foo_dev_key")
         user.set_dev_key("")
         rv = self.client.get('/api/search/?q=black+holes&dev_key=')
         self.assertEqual(rv.status_code, 401)
 def test_authorized_request(self):
     
     self.insert_user("foo", developer=True)
     
     with canned_solr_response_data():
         rv = self.client.get('/api/search/?q=black+holes&dev_key=foo_dev_key')
         self.assertEqual(rv.status_code, 200)
         rv = self.client.get('/api/record/1234?dev_key=foo_dev_key')
         self.assertEqual(rv.status_code, 200)
Exemple #5
0
 def test_highlight_inclusion(self):
     with canned_solr_response_data():
         with self.app.test_request_context():
             resp = solr.query("foo")
             doc = resp.get_doc(0)
             self.assertNotIn('highlights',doc)
             resp = solr.query("foo", highlights=[('abstract',)])
             doc = resp.get_doc(0)
             self.assertIn('highlights',doc)
Exemple #6
0
    def test_response_content(self):
        with canned_solr_response_data():
            with self.app.test_request_context():
                resp = solr.query("foo")
                self.assertEqual(resp.get_http_status(), 200)
                self.assertFalse(resp.is_error())

                resp_data = resp.search_response()
                self.assertIn('results', resp_data)
                self.assertNotIn('facets', resp_data['results'])
    def test_record_output_02(self):

        self.insert_user("foo", developer=True)

        canned_data = CannedSolrResponse.DEFAULT_DATA
        canned_data['response']['numFound'] = 0

        with canned_solr_response_data(canned_data):
            rv = self.client.get('/api/record/2012ApJ...751...88M?dev_key=foo_dev_key')
            self.assertEqual(rv.status_code, 404)
            self.assertIn("No record found with identifier 2012ApJ...751...88M", rv.data)
    def test_record_output_01(self):
        
        self.insert_user("foo", developer=True)
        
        canned_data = CannedSolrResponse.DEFAULT_DATA
        canned_data['response']['docs'][0]['title'] = 'Foo Bar Polarization'

        with canned_solr_response_data(canned_data):
            rv = self.client.get('/api/record/2012ApJ...751...88M?dev_key=foo_dev_key')
            resp_data = json.loads(rv.data)
            self.assertIn("Polarization", resp_data['title'])
 def test_api_version_header(self):
     
     self.insert_user("foo", developer=True)
     
     with canned_solr_response_data():
         rv = self.client.get('/api/search/?q=black+holes&dev_key=foo_dev_key')
         self.assertIn('X-API-Version', rv.headers)
         self.assertEqual(config.API_CURRENT_VERSION, rv.headers['X-API-Version'])
         resp_data = json.loads(rv.data)
         self.assertEqual(config.API_CURRENT_VERSION, resp_data['meta']['api-version'])
         
         rv = self.client.get('/api/search/?q=black+holes&dev_key=foo_dev_key', headers=[('X-API-Version','0.2')])
         self.assertEqual('0.2', rv.headers['X-API-Version'])
         resp_data = json.loads(rv.data)
         self.assertEqual('0.2', resp_data['meta']['api-version'])
Exemple #10
0
 def test_error_response_parsing_02(self):
     #case of possible error string not containg solr class exception    
     error_response = {"responseHeader":{
                         "status":500,
                         "QTime":1,},
                       "error":{"msg":"random string here",
                         "code":500}}
     with canned_solr_response_data(error_response, 500):
         with self.app.test_request_context('/'):
             resp = solr.query("foo")
      
             self.assertEqual(resp.get_http_status(), 500)
             self.assertTrue(resp.is_error())
             self.assertEqual(resp.get_error(), "random string here")
             self.assertEqual(resp.get_error_message(), "random string here")
Exemple #11
0
 def test_error_response_parsing_01(self):
     """Tests the get functions in case of an error coming from SOLR"""
     #error coming from query parser on SOLR
     error_response = {"responseHeader":{
                         "status":400,
                         "QTime":1,},
                       "error":{"msg":"org.apache.lucene.queryparser.classic.ParseException: undefined field authsorfsd",
                         "code":400}}
     with canned_solr_response_data(error_response, 400):
         with self.app.test_request_context():
             resp = solr.query("foo")
      
             self.assertEqual(resp.get_http_status(), 400)
             self.assertTrue(resp.is_error())
             self.assertEqual(resp.get_error(), "org.apache.lucene.queryparser.classic.ParseException: undefined field authsorfsd")
             self.assertEqual(resp.get_error_message(), "undefined field authsorfsd")
 def test_search_output(self):
     
     self.insert_user("foo", developer=True)
     with canned_solr_response_data():
         rv = self.client.get('/api/search/?q=black+holes&dev_key=foo_dev_key')
         resp_data = json.loads(rv.data)
         self.assertIn('meta', resp_data)
         self.assertIn('results', resp_data)
         self.assertTrue(resp_data['meta']['count'] >= 1)
         self.assertIsInstance(resp_data['results']['docs'], list)
         
         self.insert_user("bar", developer=True, dev_perms={'facets': True, 'allowed_fields': ['author']})
         rv = self.client.get('/api/search/?q=black+holes&dev_key=bar_dev_key')
         resp_data = json.loads(rv.data)
         self.assertNotIn('facets', resp_data['results'])
         rv = self.client.get('/api/search/?q=black+holes&dev_key=bar_dev_key&facet=author')
         resp_data = json.loads(rv.data)
         self.assertIn('facets', resp_data['results'])
 def test_content_types(self):
      
     self.insert_user("foo", developer=True)
      
     with canned_solr_response_data(): 
         # default should be json
         rv = self.client.get('/api/search/?q=black+holes&dev_key=foo_dev_key')
         self.assertIn('application/json', rv.content_type)
          
         rv = self.client.get('/api/record/2012ApJ...751...88M?dev_key=foo_dev_key')
         self.assertIn('application/json', rv.content_type)
      
         rv = self.client.get('/api/search/?q=black+holes&dev_key=foo_dev_key', headers=Headers({'Accept': 'application/json'}))
         self.assertIn('application/json', rv.content_type)
      
         rv = self.client.get('/api/search/?q=black+holes&dev_key=foo_dev_key', headers=Headers({'Accept': 'application/xml'}))
         self.assertIn('text/xml', rv.content_type)
      
         rv = self.client.get('/api/record/2012ApJ...751...88M?dev_key=foo_dev_key', headers=Headers({'Accept': 'application/xml'}))
         self.assertIn('text/xml', rv.content_type)
      
         rv = self.client.get('/api/record/2012ApJ...751...88M?dev_key=foo_dev_key')
         rv = self.client.get('/api/search/?q=black+holes&dev_key=foo_dev_key&fmt=xml')
         self.assertIn('text/xml', rv.content_type)
          
         try:
             rv = self.client.get('/api/search/?q=black+holes&dev_key=foo_dev_key&fmt=blah')
         except Exception, e:
             self.assertIsInstance(e, RendererNotFound)
          
         rv = self.client.get('/api/settings/?dev_key=foo_dev_key&fmt=xml')
         self.assertIn('<settings>', rv.data)
          
         rv = self.client.get('/api/record/xyz?dev_key=foo_dev_key&fmt=xml')
         self.assertIn('<bibcode type="str">xyz</bibcode', rv.data)
          
         rv = self.client.get('/api/search/?q=black+holes&dev_key=foo_dev_key', headers=Headers({'Accept': 'application/xml'}))
         self.assertIn('<hits type="int">1</hits>', rv.data)