def test_catch_index_error_not_index_error(self): conn = es.ESHttpConnection() try: conn._catch_index_error( (1, 2, '{"errors":true, "items": [{"foo": "bar"}]}')) except: raise Exception('Unexpected exeption')
def test_perform_request_no_index(self, mock_log): mock_log.level = logging.DEBUG mock_log.debug.side_effect = TransportError(404, 'IndexMissingException') conn = es.ESHttpConnection() with pytest.raises(es.IndexNotFoundException): conn.perform_request('POST', 'http://localhost:9200')
def test_perform_request_debug(self, mock_log, mock_catch): mock_log.level = logging.DEBUG conn = es.ESHttpConnection() conn.pool = Mock() conn.pool.urlopen.return_value = Mock(data=six.b('foo'), status=200) conn.perform_request('POST', 'http://localhost:9200') mock_log.debug.assert_called_once_with( "('POST', 'http://localhost:9200')") conn.perform_request('POST', 'http://localhost:9200' * 200) assert mock_catch.called assert mock_log.debug.call_count == 2
def test_perform_request_exception(self): conn = es.ESHttpConnection() conn.pool = Mock() conn.pool.urlopen.side_effect = TransportError('N/A', '') with pytest.raises(JHTTPBadRequest): conn.perform_request('POST', 'http://localhost:9200')
def test_catch_index_error(self): conn = es.ESHttpConnection() with pytest.raises(JHTTPBadRequest): conn._catch_index_error( (1, 2, '{"errors":true, "items": [{"index": {"error": "FOO"}}]}'))
def test_catch_index_error_no_errors(self): conn = es.ESHttpConnection() try: conn._catch_index_error((1, 2, '{"errors":false}')) except: raise Exception('Unexpected exeption')
def test_catch_index_error_no_data_loaded(self): conn = es.ESHttpConnection() try: conn._catch_index_error((1, 2, '[]')) except: raise Exception('Unexpected exeption')