From 4ff66993ec809ce630f1b118726d734a5dcbd7c8 Mon Sep 17 00:00:00 2001 From: mibe Date: Thu, 11 Jan 2024 10:45:49 +0000 Subject: [PATCH] Fixing the integration test --- .../test_transformers_extension_wrapper.py | 34 ++++-------- test/utils/integration_test_utils.py | 55 ++++++------------- 2 files changed, 28 insertions(+), 61 deletions(-) diff --git a/test/integration/test_transformers_extension_wrapper.py b/test/integration/test_transformers_extension_wrapper.py index f61ba14..d427fca 100644 --- a/test/integration/test_transformers_extension_wrapper.py +++ b/test/integration/test_transformers_extension_wrapper.py @@ -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) diff --git a/test/utils/integration_test_utils.py b/test/utils/integration_test_utils.py index 3be5923..377f559 100644 --- a/test/utils/integration_test_utils.py +++ b/test/utils/integration_test_utils.py @@ -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.+?)://(?P.+?):(?P\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: