def test_get_index_adapter(self): appscale_info = flexmock() appscale_info.should_receive("get_search_location").\ and_return("somelocation") solr = solr_interface.Solr() solr = flexmock(solr) flexmock(solr_interface) solr_interface.should_receive("get_index_name").and_return("index_ns_name") flexmock(urllib2) urllib2.should_receive("urlopen").and_return(FakeConnection(False)) self.assertRaises(search_exceptions.InternalError, solr._get_index_adapter, "app_id", "ns", "name") # Test the case of ValueError on a json.load. urllib2.should_receive("urlopen").and_return(FakeConnection(True)) flexmock(json) json.should_receive("load").and_raise(ValueError) self.assertRaises(search_exceptions.InternalError, solr._get_index_adapter, "app_id", "ns", "name") # Test a bad status from SOLR. dictionary = {'responseHeader':{'status': 1}} json.should_receive("load").and_return(dictionary) self.assertRaises(search_exceptions.InternalError, solr._get_index_adapter, "app_id", "ns", "name") fields = [{'name':"index_ns_name_"}] dictionary = {'responseHeader':{'status': 0}, "fields": fields} json.should_receive("load").and_return(dictionary) index = solr._get_index_adapter("app_id", "ns", "name") self.assertEquals(index.schema[0]['name'], "index_ns_name_")
def test_get_index_adapter(self): appscale_info = flexmock() appscale_info.should_receive("get_search_location").\ and_return("somelocation") solr = solr_interface.Solr() solr = flexmock(solr) flexmock(solr_interface) solr_interface.should_receive("get_index_name").and_return( "index_ns_name") flexmock(urllib2) urllib2.should_receive("urlopen").and_return(FakeConnection(False)) self.assertRaises(search_exceptions.InternalError, solr._get_index_adapter, "app_id", "ns", "name") # Test the case of ValueError on a json.load. urllib2.should_receive("urlopen").and_return(FakeConnection(True)) flexmock(json) json.should_receive("load").and_raise(ValueError) self.assertRaises(search_exceptions.InternalError, solr._get_index_adapter, "app_id", "ns", "name") # Test a bad status from SOLR. dictionary = {'responseHeader': {'status': 1}} json.should_receive("load").and_return(dictionary) self.assertRaises(search_exceptions.InternalError, solr._get_index_adapter, "app_id", "ns", "name") fields = [{'name': "index_ns_name_"}] dictionary = {'responseHeader': {'status': 0}, "fields": fields} json.should_receive("load").and_return(dictionary) index = solr._get_index_adapter("app_id", "ns", "name") self.assertEquals(index.schema[0]['name'], "index_ns_name_")
def test_index_document(self): solr_interface = flexmock() solr_interface.should_receive("Solr").and_return(FakeSolr()) solr_interface.should_receive("update_document") fake_response = FakeIndexDocumentResponse() flexmock(search_service_pb) search_service_pb.should_receive("IndexDocumentRequest").and_return(FakeIndexDocumentRequest("data")) search_service_pb.should_receive("IndexDocumentResponse").and_return(fake_response) search_service = search_api.SearchService() search_service = flexmock(search_service) self.assertEquals(search_service.index_document("app_data"), ("encoded", 0, ""))
def test_remote_request(self): solr_interface = flexmock() solr_interface.should_receive("Solr").and_return(FakeSolr()) flexmock(remote_api_pb) remote_api_pb.should_receive("Request").and_return(FakeRequest()) remote_api_pb.should_receive("Response").and_return(FakeResponse()) search_service = search_api.SearchService() search_service = flexmock(search_service) search_service.should_receive("index_document").and_return("response_data", 0, "").once() self.assertEquals(search_service.remote_request("app_data"), "encoded")
def test_unknown_request(self): flexmock(solr_interface) solr_interface.should_receive("Solr").and_return(FakeSolr()) search_service = search_api.SearchService() self.assertRaises(NotImplementedError, search_service.unknown_request, "some_unknown_type")