Exemplo n.º 1
0
 def test_response_from_search_request(self):
     body = get_data('search.json')
     resp = SolrResponse(body=body, status=200)
     self.assertTrue(resp.is_ok())
     self.assertEqual(len(resp.docs), 3)
     self.assertEqual(resp.num_found, 3)
     self.assertEqual(resp.start, 0)
Exemplo n.º 2
0
    def setUp(self):
        super(SolrMockupTestCase, self).setUp()
        assert self.schema is not None, 'A path for Solr schema is needed'
        conn = MagicMock(name='SolrConnection')
        conn.get = MagicMock(name='get',
                             return_value=SolrResponse(
                                 body=self.schema,
                                 status=200,
                             ))

        manager = MagicMock(name='SolrConnectionManager')
        manager.connection = conn
        manager.schema = SolrSchema(manager)

        solr = getUtility(ISolrSearch)
        solr._manager = manager

        assert self.search is not None, 'A path for Solr search is needed'
        solr.search = MagicMock(name='search',
                                return_value=SolrResponse(
                                    body=self.search,
                                    status=200,
                                ))
        self.solr = solr
        self.source = UsersContactsInboxesSource(self.portal)
Exemplo n.º 3
0
 def test_response_from_bad_request(self):
     body = get_data('bad_request.json')
     resp = SolrResponse(body=body, status=400)
     self.assertFalse(resp.is_ok())
     self.assertEqual(resp.http_status, 400)
     self.assertEqual(resp.status, 400)
     self.assertEqual(resp[u'error'][u'code'], 400)
Exemplo n.º 4
0
 def mock_solr(self, response_file):
     conn = MagicMock(name='SolrConnection')
     schema_resp = assets.load('solr_schema.json')
     conn.get = MagicMock(name='get',
                          return_value=SolrResponse(body=schema_resp,
                                                    status=200))
     manager = MagicMock(name='SolrConnectionManager')
     manager.connection = conn
     manager.schema = SolrSchema(manager)
     solr = getUtility(ISolrSearch)
     solr._manager = manager
     search_resp = assets.load(response_file)
     solr.search = MagicMock(name='search',
                             return_value=SolrResponse(body=search_resp,
                                                       status=200))
     return solr
Exemplo n.º 5
0
 def setUp(self):
     super(TestSolrSearch, self).setUp()
     self.search = self.portal.unrestrictedTraverse('@@search')
     conn = MagicMock(name='SolrConnection')
     schema_resp = open(os.path.join(
         os.path.dirname(__file__), 'data', 'solr_schema.json'), 'r').read()
     conn.get = MagicMock(name='get', return_value=SolrResponse(
         body=schema_resp, status=200))
     manager = MagicMock(name='SolrConnectionManager')
     manager.connection = conn
     manager.schema = SolrSchema(manager)
     solr = getUtility(ISolrSearch)
     solr._manager = manager
     search_resp = open(os.path.join(
         os.path.dirname(__file__), 'data', 'solr_search.json'), 'r').read()
     solr.search = MagicMock(name='search', return_value=SolrResponse(
         body=search_resp, status=200))
     self.solr = solr
Exemplo n.º 6
0
    def setUp(self):
        super(TestListingEndpointWithSolr, self).setUp()

        # Mock Solr connection
        self.conn = Mock(name='SolrConnection')
        self.conn.search.return_value = SolrResponse()
        self.solr = getUtility(ISolrSearch)
        self._manager = self.solr._manager
        self.solr._manager = Mock(name='SolrConnectionManager')
        self.solr.manager.connection = self.conn
Exemplo n.º 7
0
 def setUp(self):
     super(TestSolrSearch, self).setUp()
     conn = MagicMock(name='SolrConnection')
     schema_resp = open(os.path.join(
         pkg_path, 'opengever', 'base', 'tests', 'data',
         'solr_schema.json'), 'r').read()
     conn.get = MagicMock(name='get', return_value=SolrResponse(
         body=schema_resp, status=200))
     manager = MagicMock(name='SolrConnectionManager')
     manager.connection = conn
     manager.schema = SolrSchema(manager)
     solr = getUtility(ISolrSearch)
     solr._manager = manager
     search_resp = open(os.path.join(
         pkg_path, 'opengever', 'base', 'tests', 'data',
         'solr_search.json'), 'r').read()
     solr.search = MagicMock(name='search', return_value=SolrResponse(
         body=search_resp, status=200))
     self.solr = solr
     self.source = GeverCatalogTableSource(
         BaseCatalogListingTab(self.portal, self.request), self.request)
    def mock_solr(self, response_file=None, response_json=None):
        conn = MagicMock(name='SolrConnection')
        schema_resp = assets.load('solr_schema.json')
        conn.get = MagicMock(name='get', return_value=SolrResponse(
            body=schema_resp, status=200))
        manager = MagicMock(name='SolrConnectionManager')
        manager.connection = conn
        manager.schema = SolrSchema(manager)
        solr = getUtility(ISolrSearch)
        solr._manager = manager
        if response_file:
            search_resp = assets.load(response_file)
        else:
            # Make sure status is in header
            if u'responseHeader' not in response_json:
                response_json[u'responseHeader'] = {}
            if 'status' not in response_json[u'responseHeader']:
                response_json[u'responseHeader']['status'] = 0
            search_resp = json.dumps(response_json)

        solr.search = MagicMock(name='search', return_value=SolrResponse(
            body=search_resp, status=200))
        return solr
Exemplo n.º 9
0
 def test_contentlisting_returns_og_types(self):
     body = """{
         "responseHeader": {"status": 0},
         "response": {
             "numFound": 1,
             "start": 0,
             "docs": [{
                 "UID": "85bed8c49f6d4f8b841693c6a7c6cff1",
                 "Title": "My Item"
             }]
         }
     }"""
     resp = SolrResponse(body=body, status=200)
     listing = OGSolrContentListing(resp)
     self.assertTrue(isinstance(listing[0], OGSolrContentListingObject))
     self.assertTrue(isinstance(listing[0].doc, OGSolrDocument))
Exemplo n.º 10
0
 def test_response_from_exception(self):
     exception = socket.error(61, 'Connection refused')
     resp = SolrResponse(exception=exception)
     self.assertFalse(resp.is_ok())
     self.assertEqual(resp.exception, exception)
Exemplo n.º 11
0
 def test_response_from_schema_request(self):
     body = get_data('schema.json')
     resp = SolrResponse(body=body, status=200)
     self.assertTrue(resp.is_ok())
     self.assertIn('schema', resp)
Exemplo n.º 12
0
 def test_response_from_search_with_highlighting(self):
     body = get_data('highlighting.json')
     resp = SolrResponse(body=body, status=200)
     self.assertTrue(resp.is_ok())
     self.assertIn('highlighting', resp)
Exemplo n.º 13
0
 def test_response_from_bad_body(self):
     resp = SolrResponse(body='bad', status=200)
     self.assertFalse(resp.is_ok())
     self.assertEqual(resp.status, -1)