def index_callback(self, parsed_message): logger.debug("Processing `index` message for entity: %s" % parsed_message.entity_type) entity = SCHEMA[parsed_message.entity_type] converter = entity.query_result_to_dict query = entity.query condition = and_(entity.model.id.in_(parsed_message.ids)) with db_session_ctx(self.session) as session: query = query.filter(condition).with_session(session) send_data_to_solr(self.cores[parsed_message.entity_type], [converter(obj) for obj in query.all()])
def test_fail_send(self): self.solr_connection.add.side_effect = SolrError('Test Error') self.assertFalse(FAILED.value) send_data_to_solr(self.solr_connection, [{"foo": "bar"}]) self.assertTrue(FAILED.value)
def test_normal_send(self): send_data_to_solr(self.solr_connection, [{"foo": "bar"}]) expected = [mock.call([{"foo": "bar"}])] calls = self.solr_connection.add.call_args_list self.assertEqual(calls, expected)
def test_bad_request_ignored(self): self.solr_connection.add_many.side_effect = [SolrException(400), None] send_data_to_solr(self.solr_connection, 1)
def test_normal_send(self): send_data_to_solr(self.solr_connection, [{"foo": "bar"}]) expected = [mock.call([{"foo": "bar"}])] calls = self.solr_connection.add_many.call_args_list self.assertEqual(calls, expected)