Skip to content

Commit

Permalink
Fixing the integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
ahsimb committed Jan 11, 2024
1 parent 4c46196 commit 4ff6699
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 61 deletions.
34 changes: 10 additions & 24 deletions test/integration/test_transformers_extension_wrapper.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,31 @@
from contextlib import ExitStack
from test.utils.integration_test_utils import (
activate_languages,
assert_connection_exists,
assert_run_empty_udf,
create_schema_with_reverse,
get_script_counts,
setup_test_configuration,
)
from typing import Callable

from _pytest.fixtures import FixtureRequest
from pyexasol import ExaConnection
from pytest_itde import config

from exasol.connections import open_pyexasol_connection
from exasol.secret_store import Secrets
from exasol.transformers_extension_wrapper import (
BFS_CONNECTION_KEY,
HF_CONNECTION_KEY,
initialize_te_extension,
)
from test.utils.integration_test_utils import (
setup_itde,
activate_languages,
assert_connection_exists,
assert_run_empty_udf,
get_script_counts
)


def test_initialize_te_extension(
request: FixtureRequest,
connection_factory: Callable[[config.Exasol], ExaConnection],
exasol_config: config.Exasol,
bucketfs_config: config.BucketFs,
secrets: Secrets,
setup_itde
):
test_name: str = request.node.name
schema = test_name
language_alias = f"PYTHON3_TE_{test_name.upper()}"
# Create the configuration in the secret store that would be expected
# prior to the deployment of the Transformers Extension.
setup_test_configuration(schema, exasol_config, bucketfs_config, secrets)
secrets.save("HF_TOKEN", "abc")

with ExitStack() as stack:
pyexasol_connection = stack.enter_context(connection_factory(exasol_config))
# Create the schema, which should also exist prior to the deployment.
stack.enter_context(create_schema_with_reverse(pyexasol_connection, secrets))
with open_pyexasol_connection(secrets) as pyexasol_connection:

# Run the extension deployment.
initialize_te_extension(secrets, language_alias=language_alias)
Expand Down
55 changes: 18 additions & 37 deletions test/utils/integration_test_utils.py
Original file line number Diff line number Diff line change
@@ -1,56 +1,37 @@
import contextlib
import re
import textwrap
from typing import Dict
import pytest

from pyexasol import ExaConnection
from pytest_itde import config

from exasol.language_container_activation import get_activation_sql
from exasol.secret_store import Secrets
from exasol.itde_manager import (
bring_itde_up,
take_itde_down
)
from exasol.ai_lab_config import AILabConfig
from exasol.connections import open_pyexasol_connection


def setup_test_configuration(
schema: str,
exasol_config: config.Exasol,
bucketfs_config: config.BucketFs,
secrets: Secrets,
) -> None:
@pytest.fixture(scope='session')
def setup_itde(secrets) -> None:
"""
Creates the configuration in the secret store corresponding to the
test database.
Brings up the ITDE and takes it down when the tests are completed or failed.
Creates a schema and saves its name in the secret store.
"""

url_pattern = r"\A(?P<protocol>.+?)://(?P<host>.+?):(?P<port>\d+)"
url_parse = re.match(url_pattern, bucketfs_config.url)
secrets.save("EXTERNAL_HOST_NAME", exasol_config.host)
secrets.save("DB_PORT", str(exasol_config.port))
secrets.save("USER", exasol_config.username)
secrets.save("SCHEMA", schema)
secrets.save("PASSWORD", exasol_config.password)
secrets.save("BUCKETFS_HOST_NAME", url_parse.group("host"))
secrets.save("BUCKETFS_PORT", url_parse.group("port"))
secrets.save("BUCKETFS_USER", bucketfs_config.username)
secrets.save("BUCKETFS_PASSWORD", bucketfs_config.password)
secrets.save("BUCKETFS_SERVICE", "bfsdefault")
secrets.save("BUCKETFS_BUCKET", "default")
secrets.save("BUCKETFS_ENCRYPTION", str("https" in url_parse.group("protocol")))
secrets.save("ENCRYPTION", "True"),
secrets.save("CERTIFICATE_VALIDATION", "False")


@contextlib.contextmanager
def create_schema_with_reverse(pyexasol_connection: ExaConnection, secrets: Secrets):
"""
Creates the schema in a contextualized manner. Drops this schema on exit.
"""
bring_itde_up(secrets)

schema = 'INTEGRATION_TEST'
secrets.save(AILabConfig.db_schema.value, schema)
with open_pyexasol_connection(secrets) as pyexasol_connection:
pyexasol_connection.execute(f"CREATE SCHEMA {schema};")

try:
pyexasol_connection.execute(f"DROP SCHEMA IF EXISTS {secrets.SCHEMA} CASCADE;")
pyexasol_connection.execute(f"CREATE SCHEMA {secrets.SCHEMA};")
yield
finally:
pyexasol_connection.execute(f"DROP SCHEMA IF EXISTS {secrets.SCHEMA} CASCADE;")
take_itde_down(secrets)


def activate_languages(pyexasol_connection: ExaConnection, secrets: Secrets) -> None:
Expand Down

0 comments on commit 4ff6699

Please sign in to comment.