def test_execute_single_no_return_value(self): es = None params = None runner = mock.Mock() total_ops, total_ops_unit, request_meta_data = driver.execute_single(self.context_managed(runner), es, params) self.assertEqual(1, total_ops) self.assertEqual("ops", total_ops_unit) self.assertEqual({"success": True}, request_meta_data)
def test_execute_single_with_key_error(self): class FailingRunner: def __call__(self, *args): raise KeyError("bulk-size missing") def __str__(self): return "failing_mock_runner" es = None params = collections.OrderedDict() # simulating an error; this should be "bulk-size" params["bulk"] = 5000 params["mode"] = "append" runner = FailingRunner() with self.assertRaises(exceptions.SystemSetupError) as ctx: driver.execute_single(self.context_managed(runner), es, params) self.assertEqual( "Cannot execute [failing_mock_runner]. Provided parameters are: ['bulk', 'mode']. Error: ['bulk-size missing'].", ctx.exception.args[0])
def test_execute_single_tuple(self): es = None params = None runner = mock.Mock() runner.return_value = (500, "MB") total_ops, total_ops_unit, request_meta_data = driver.execute_single(self.context_managed(runner), es, params) self.assertEqual(500, total_ops) self.assertEqual("MB", total_ops_unit) self.assertIsNone(request_meta_data)
def test_execute_single_with_http_400(self): import elasticsearch es = None params = None runner = mock.Mock(side_effect=elasticsearch.NotFoundError(404, "not found")) total_ops, total_ops_unit, request_meta_data = driver.execute_single(self.context_managed(runner), es, params) self.assertEqual(0, total_ops) self.assertEqual("ops", total_ops_unit) self.assertEqual({ "http-status": 404, "error-description": "not found", "success": False }, request_meta_data)
def test_execute_single_with_http_400(self): import elasticsearch es = None params = None runner = mock.Mock(side_effect=elasticsearch.NotFoundError(404, "not found")) total_ops, total_ops_unit, request_meta_data = driver.execute_single(self.context_managed(runner), es, params) self.assertEqual(0, total_ops) self.assertEqual("ops", total_ops_unit) self.assertEqual({ "http-status": 404, "error-type": "transport", "error-description": "not found", "success": False }, request_meta_data)
def test_execute_single_with_connection_error(self): import elasticsearch es = None params = None # ES client uses pseudo-status "N/A" in this case... runner = mock.Mock(side_effect=elasticsearch.ConnectionError("N/A", "no route to host")) total_ops, total_ops_unit, request_meta_data = driver.execute_single(self.context_managed(runner), es, params) self.assertEqual(0, total_ops) self.assertEqual("ops", total_ops_unit) self.assertEqual({ # Look ma: No http-status! "error-description": "no route to host", "success": False }, request_meta_data)
def test_execute_single_with_connection_error(self): import elasticsearch es = None params = None # ES client uses pseudo-status "N/A" in this case... runner = mock.Mock(side_effect=elasticsearch.ConnectionError("N/A", "no route to host")) total_ops, total_ops_unit, request_meta_data = driver.execute_single(self.context_managed(runner), es, params) self.assertEqual(0, total_ops) self.assertEqual("ops", total_ops_unit) self.assertEqual({ # Look ma: No http-status! "error-description": "no route to host", "error-type": "transport", "success": False }, request_meta_data)
def test_execute_single_dict(self): es = None params = None runner = mock.Mock() runner.return_value = { "weight": 50, "unit": "docs", "some-custom-meta-data": "valid", "http-status": 200 } total_ops, total_ops_unit, request_meta_data = driver.execute_single(self.context_managed(runner), es, params) self.assertEqual(50, total_ops) self.assertEqual("docs", total_ops_unit) self.assertEqual({ "some-custom-meta-data": "valid", "http-status": 200 }, request_meta_data)