Ejemplo n.º 1
0
    def test_commit_update(self):
        appscale_info = flexmock()
        appscale_info.should_receive("get_search_location").and_return(
            "somelocation")
        solr = solr_interface.Solr()

        flexmock(simplejson)
        simplejson.should_receive("loads").and_return({})

        flexmock(urllib2)
        urllib2.should_receive("urlopen").and_return(FakeConnection(False))
        self.assertRaises(search_exceptions.InternalError, solr.commit_update,
                          {})

        simplejson.should_receive("load").and_raise(ValueError)
        urllib2.should_receive("urlopen").and_return(FakeConnection(True))
        self.assertRaises(search_exceptions.InternalError, solr.commit_update,
                          {})

        dictionary = {'responseHeader': {'status': 1}}
        simplejson.should_receive("load").and_return(dictionary).once()
        self.assertRaises(search_exceptions.InternalError, solr.commit_update,
                          {})

        dictionary = {'responseHeader': {'status': 0}}
        simplejson.should_receive("load").and_return(dictionary).once()
        solr.commit_update({})
Ejemplo n.º 2
0
  def test_get_index(self):
    appscale_info = flexmock()
    appscale_info.should_receive("get_search_location").and_return("somelocation")
    solr = solr_interface.Solr()
    solr = flexmock(solr)
    solr.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, "app_id", "ns", "name")

    # Test the case of ValueError on a simplejson.load.
    urllib2.should_receive("urlopen").and_return(FakeConnection(True))
    flexmock(simplejson)
    simplejson.should_receive("load").and_raise(ValueError)
    self.assertRaises(search_exceptions.InternalError, solr.get_index, "app_id", "ns", "name")

    # Test a bad status from SOLR.
    dictionary = {'responseHeader':{'status': 1}}
    simplejson.should_receive("load").and_return(dictionary)
    self.assertRaises(search_exceptions.InternalError, solr.get_index, "app_id", "ns", "name")

    fields = [{'name':"index_ns_name_"}]
    dictionary = {'responseHeader':{'status': 0}, "fields": fields}
    simplejson.should_receive("load").and_return(dictionary)
    index = solr.get_index("app_id", "ns", "name")
    self.assertEquals(index.schema.fields[0]['name'], "index_ns_name_")
Ejemplo n.º 3
0
    def test_get_index(self):
        appscale_info = flexmock()
        appscale_info.should_receive("get_search_location").and_return(
            "somelocation")
        solr = solr_interface.Solr()
        solr = flexmock(solr)
        solr.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,
                          "app_id", "ns", "name")

        # Test the case of ValueError on a simplejson.load.
        urllib2.should_receive("urlopen").and_return(FakeConnection(True))
        flexmock(simplejson)
        simplejson.should_receive("load").and_raise(ValueError)
        self.assertRaises(search_exceptions.InternalError, solr.get_index,
                          "app_id", "ns", "name")

        # Test a bad status from SOLR.
        dictionary = {'responseHeader': {'status': 1}}
        simplejson.should_receive("load").and_return(dictionary)
        self.assertRaises(search_exceptions.InternalError, solr.get_index,
                          "app_id", "ns", "name")

        fields = [{'name': "index_ns_name_"}]
        dictionary = {'responseHeader': {'status': 0}, "fields": fields}
        simplejson.should_receive("load").and_return(dictionary)
        index = solr.get_index("app_id", "ns", "name")
        self.assertEquals(index.schema.fields[0]['name'], "index_ns_name_")
Ejemplo n.º 4
0
    def test_update_schema(self):
        appscale_info = flexmock()
        appscale_info.should_receive("get_search_location").and_return(
            "somelocation")
        solr = solr_interface.Solr()

        flexmock(urllib2)
        urllib2.should_receive("urlopen").and_return(FakeConnection(False))
        updates = []
        self.assertRaises(search_exceptions.InternalError, solr.update_schema,
                          updates)

        updates = [{'name': 'name1', 'type': 'type1'}]
        flexmock(simplejson)
        simplejson.should_receive("load").and_raise(ValueError)
        urllib2.should_receive("urlopen").and_return(FakeConnection(True))
        self.assertRaises(search_exceptions.InternalError, solr.update_schema,
                          updates)

        dictionary = {"responseHeader": {"status": 1}}
        simplejson.should_receive("load").and_return(dictionary)
        self.assertRaises(search_exceptions.InternalError, solr.update_schema,
                          updates)

        dictionary = {"responseHeader": {"status": 0}}
        simplejson.should_receive("load").and_return(dictionary)
        solr.update_schema(updates)
Ejemplo n.º 5
0
  def test_commit_update(self):
    appscale_info = flexmock()
    appscale_info.should_receive("get_search_location").and_return("somelocation")
    solr = solr_interface.Solr()
    
    flexmock(simplejson)
    simplejson.should_receive("loads").and_return({})

    flexmock(urllib2)
    urllib2.should_receive("urlopen").and_return(FakeConnection(False))
    self.assertRaises(search_exceptions.InternalError, solr.commit_update, {})

    simplejson.should_receive("load").and_raise(ValueError)
    urllib2.should_receive("urlopen").and_return(FakeConnection(True))
    self.assertRaises(search_exceptions.InternalError, solr.commit_update, {})

    dictionary = {'responseHeader':{'status': 1}}
    simplejson.should_receive("load").and_return(dictionary).once()
    self.assertRaises(search_exceptions.InternalError, solr.commit_update, {})

    dictionary = {'responseHeader':{'status': 0}}
    simplejson.should_receive("load").and_return(dictionary).once()
    solr.commit_update({})
Ejemplo n.º 6
0
  def test_update_schema(self):
    appscale_info = flexmock()
    appscale_info.should_receive("get_search_location").and_return("somelocation")
    solr = solr_interface.Solr()

    flexmock(urllib2)
    urllib2.should_receive("urlopen").and_return(FakeConnection(False))
    updates = []
    self.assertRaises(search_exceptions.InternalError, solr.update_schema, updates)

    updates = [{'name': 'name1', 'type':'type1'}]
    flexmock(simplejson)
    simplejson.should_receive("load").and_raise(ValueError)
    urllib2.should_receive("urlopen").and_return(FakeConnection(True))
    self.assertRaises(search_exceptions.InternalError, solr.update_schema, updates)

    dictionary = {"responseHeader":{"status":1}}
    simplejson.should_receive("load").and_return(dictionary)
    self.assertRaises(search_exceptions.InternalError, solr.update_schema, updates)
    
    dictionary = {"responseHeader":{"status":0}}
    simplejson.should_receive("load").and_return(dictionary)
    solr.update_schema(updates)