def test_connection_fail(self): test_executor = OpenSearchConnection(endpoint=INVALID_ENDPOINT) err_message = "Can not connect to endpoint %s" % INVALID_ENDPOINT with mock.patch("sys.exit") as mock_sys_exit, mock.patch("src.opensearch_sql_cli.opensearch_connection.click.secho") as mock_secho: test_executor.set_connection() mock_sys_exit.assert_called() mock_secho.assert_called_with(message=err_message, fg="red")
def test_select_client(self): od_test_executor = OpenSearchConnection(endpoint=OPEN_DISTRO_ENDPOINT, http_auth=AUTH) aes_test_executor = OpenSearchConnection(endpoint=AES_ENDPOINT, use_aws_authentication=True) with mock.patch.object(od_test_executor, "get_open_distro_client") as mock_od_client, mock.patch.object( OpenSearchConnection, "is_sql_plugin_installed", return_value=True ): od_test_executor.set_connection() mock_od_client.assert_called() with mock.patch.object(aes_test_executor, "get_aes_client") as mock_aes_client, mock.patch.object( OpenSearchConnection, "is_sql_plugin_installed", return_value=True ): aes_test_executor.set_connection() mock_aes_client.assert_called()
def test_reconnection_exception(self): test_executor = OpenSearchConnection(endpoint=INVALID_ENDPOINT) with pytest.raises(ConnectionError) as error: assert test_executor.set_connection(True)
def get_connection(): test_es_connection = OpenSearchConnection(endpoint=ENDPOINT) test_es_connection.set_connection(is_reconnect=True) return test_es_connection