Skip to content

Commit

Permalink
#120 Added the backend fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
ahsimb committed Jun 26, 2024
1 parent 02d59de commit a24a46d
Show file tree
Hide file tree
Showing 14 changed files with 81 additions and 116 deletions.
8 changes: 2 additions & 6 deletions tests/ci_tests/test_deploying_autopilot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from datetime import datetime

import pytest
import exasol.bucketfs as bfs

from tests.fixtures.prepare_environment_fixture import CITestEnvironment
from tests.ci_tests.utils import parameters
Expand Down Expand Up @@ -54,11 +53,8 @@ def _deploy_endpoint(job_name, endpoint_name, model_setup_params, ci_test_env: C
assert endpoint_name in list(map(lambda x: x[0], all_scripts))


@pytest.mark.parametrize("db_conn,deploy_params", [
(bfs.path.StorageBackend.onprem, bfs.path.StorageBackend.onprem),
(bfs.path.StorageBackend.saas, bfs.path.StorageBackend.saas)
], indirect=True)
def test_deploy_autopilot_endpoint(db_conn, deploy_params, prepare_ci_test_environment):
@pytest.mark.slow
def test_deploy_autopilot_endpoint(prepare_ci_test_environment):
curr_datetime = datetime.now().strftime("%y%m%d%H%M%S")
model_name = ''.join((cls_model_setup_params.model_type, curr_datetime))
job_name = ''.join((model_name, 'job'))
Expand Down
8 changes: 2 additions & 6 deletions tests/ci_tests/test_polling_autopilot.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
from datetime import datetime

import pytest
import exasol.bucketfs as bfs

from tests.ci_tests.utils.autopilot_polling import AutopilotTestPolling
from tests.ci_tests.utils.autopilot_training import AutopilotTestTraining
from tests.ci_tests.utils.parameters import cls_model_setup_params


@pytest.mark.parametrize("db_conn,deploy_params", [
(bfs.path.StorageBackend.onprem, bfs.path.StorageBackend.onprem),
(bfs.path.StorageBackend.saas, bfs.path.StorageBackend.saas)
], indirect=True)
def test_poll_autopilot_job(db_conn, deploy_params, prepare_ci_test_environment):
@pytest.mark.slow
def test_poll_autopilot_job(prepare_ci_test_environment):
curr_datetime = datetime.now().strftime("%y%m%d%H%M%S")
model_name = ''.join((cls_model_setup_params.model_type, curr_datetime))
job_name = ''.join((model_name, 'job'))
Expand Down
15 changes: 4 additions & 11 deletions tests/ci_tests/test_predicting_autopilot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from datetime import datetime

import pytest
import exasol.bucketfs as bfs

from tests.fixtures.prepare_environment_fixture import CITestEnvironment
from tests.ci_tests.utils import parameters
Expand Down Expand Up @@ -55,11 +54,8 @@ def _make_prediction(job_name, endpoint_name, model_setup_params, ci_test_env: C
assert predictions


@pytest.mark.parametrize("db_conn,deploy_params", [
(bfs.path.StorageBackend.onprem, bfs.path.StorageBackend.onprem),
(bfs.path.StorageBackend.saas, bfs.path.StorageBackend.saas)
], indirect=True)
def test_predict_autopilot_regression_job(db_conn, deploy_params, prepare_ci_test_environment):
@pytest.mark.slow
def test_predict_autopilot_regression_job(prepare_ci_test_environment):
curr_datetime = datetime.now().strftime("%y%m%d%H%M%S")
model_name = ''.join((reg_model_setup_params.model_type, curr_datetime))
job_name = ''.join((model_name, 'job'))
Expand All @@ -77,11 +73,8 @@ def test_predict_autopilot_regression_job(db_conn, deploy_params, prepare_ci_tes
db_conn=prepare_ci_test_environment)


@pytest.mark.parametrize("db_conn,deploy_params", [
(bfs.path.StorageBackend.onprem, bfs.path.StorageBackend.onprem),
(bfs.path.StorageBackend.saas, bfs.path.StorageBackend.saas)
], indirect=True)
def test_predict_autopilot_classification_job(db_conn, deploy_params, prepare_ci_test_environment):
@pytest.mark.slow
def test_predict_autopilot_classification_job(prepare_ci_test_environment):
curr_datetime = datetime.now().strftime("%y%m%d%H%M%S")
model_name = ''.join((cls_model_setup_params.model_type, curr_datetime))
job_name = ''.join((model_name, 'job'))
Expand Down
15 changes: 4 additions & 11 deletions tests/ci_tests/test_training_autopilot.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from datetime import datetime

import pytest
import exasol.bucketfs as bfs

from tests.fixtures.prepare_environment_fixture import CITestEnvironment
from tests.ci_tests.utils.autopilot_training import AutopilotTestTraining
Expand All @@ -10,11 +9,8 @@
from tests.ci_tests.utils.queries import DatabaseQueries


@pytest.mark.parametrize("db_conn,deploy_params", [
(bfs.path.StorageBackend.onprem, bfs.path.StorageBackend.onprem),
(bfs.path.StorageBackend.saas, bfs.path.StorageBackend.saas)
], indirect=True)
def test_train_autopilot_regression_job(db_conn, deploy_params, prepare_ci_test_environment):
@pytest.mark.slow
def test_train_autopilot_regression_job(prepare_ci_test_environment):
curr_datetime = datetime.now().strftime("%y%m%d%H%M%S")
model_name = ''.join((reg_model_setup_params.model_type, curr_datetime))
job_name = ''.join((model_name, 'job'))
Expand All @@ -27,11 +23,8 @@ def test_train_autopilot_regression_job(db_conn, deploy_params, prepare_ci_test_
job_name, reg_model_setup_params, prepare_ci_test_environment)


@pytest.mark.parametrize("db_conn,deploy_params", [
(bfs.path.StorageBackend.onprem, bfs.path.StorageBackend.onprem),
(bfs.path.StorageBackend.saas, bfs.path.StorageBackend.saas)
], indirect=True)
def test_train_autopilot_classification_job(db_conn, deploy_params, prepare_ci_test_environment):
@pytest.mark.slow
def test_train_autopilot_classification_job(prepare_ci_test_environment):
curr_datetime = datetime.now().strftime("%y%m%d%H%M%S")
model_name = ''.join((cls_model_setup_params.model_type, curr_datetime))
job_name = ''.join((model_name, 'job'))
Expand Down
6 changes: 1 addition & 5 deletions tests/deployment/test_deploy_cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pytest
from click.testing import CliRunner
import exasol.bucketfs as bfs

from exasol_sagemaker_extension.deployment import deploy_cli
from tests.ci_tests.utils.parameters import get_deploy_arg_list
Expand Down Expand Up @@ -37,10 +36,7 @@ def get_all_scripts(db_conn):
return list(map(lambda x: x[0], all_scripts))


@pytest.mark.parametrize("db_conn,deploy_params", [
(bfs.path.StorageBackend.onprem, bfs.path.StorageBackend.onprem),
(bfs.path.StorageBackend.saas, bfs.path.StorageBackend.saas)
], indirect=True)
@pytest.mark.slow
def test_deploy_cli_main(db_conn, deploy_params):

args_list = get_deploy_arg_list(deploy_params, DB_SCHEMA)
Expand Down
6 changes: 1 addition & 5 deletions tests/deployment/test_deploy_create_statements.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest
import exasol.bucketfs as bfs

from exasol_sagemaker_extension.deployment.deploy_create_statements import \
DeployCreateStatements
Expand Down Expand Up @@ -28,10 +27,7 @@ def get_all_scripts(db_conn):
return list(map(lambda x: x[0], all_scripts))


@pytest.mark.parametrize("db_conn,deploy_params", [
(bfs.path.StorageBackend.onprem, bfs.path.StorageBackend.onprem),
(bfs.path.StorageBackend.saas, bfs.path.StorageBackend.saas)
], indirect=True)
@pytest.mark.slow
def test_deploy_create_statements(db_conn, deploy_params):

# We validate the server certificate in SaaS, but not in the Docker DB
Expand Down
95 changes: 56 additions & 39 deletions tests/fixtures/database_connection_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,23 @@ def _open_pyexasol_connection(**kwargs) -> pyexasol.ExaConnection:
compression=True)


@pytest.fixture(scope='session', params=[bfs.path.StorageBackend.onprem, bfs.path.StorageBackend.saas])
def backend(request) -> bfs.path.StorageBackend:
# Here we are going to add
# pytest.skip()
# if there is an instruction to skip a particular backed in the command line.
return request.param


@pytest.fixture(scope="session")
def db_conn_onprem() -> pyexasol.ExaConnection:
conn = _open_pyexasol_connection(dsn=f"{db_params.host}:{db_params.port}",
user=db_params.user,
password=db_params.password)
upload_language_container_onprem(db_conn=conn)
return conn
def db_conn_onprem(backend) -> pyexasol.ExaConnection | None:
if backend == bfs.path.StorageBackend.onprem:
conn = _open_pyexasol_connection(dsn=f"{db_params.host}:{db_params.port}",
user=db_params.user,
password=db_params.password)
upload_language_container_onprem(db_conn=conn)
return conn
return None


@pytest.fixture(scope="session")
Expand All @@ -58,47 +68,54 @@ def saas_token() -> str:


@pytest.fixture(scope="session")
def saas_database_id(saas_url, saas_account_id, saas_token) -> str:

with ExitStack() as stack:
# Create and configure the SaaS client.
client = create_saas_client(host=saas_url, pat=saas_token)
api_access = OpenApiAccess(client=client, account_id=saas_account_id)
stack.enter_context(api_access.allowed_ip())

# Create a temporary database and waite till it becomes operational
db = stack.enter_context(api_access.database(
name=timestamp_name('SME_CI'),
idle_time=timedelta(hours=12)))
api_access.wait_until_running(db.id)
yield db.id
def saas_database_id(backend, saas_url, saas_account_id, saas_token) -> str:

if backend == bfs.path.StorageBackend.saas:
with ExitStack() as stack:
# Create and configure the SaaS client.
client = create_saas_client(host=saas_url, pat=saas_token)
api_access = OpenApiAccess(client=client, account_id=saas_account_id)
stack.enter_context(api_access.allowed_ip())

# Create a temporary database and waite till it becomes operational
db = stack.enter_context(api_access.database(
name=timestamp_name('SME_CI'),
idle_time=timedelta(hours=12)))
api_access.wait_until_running(db.id)
yield db.id
else:
yield ''


@pytest.fixture(scope="session")
def db_conn_saas(saas_url, saas_account_id, saas_database_id, saas_token) -> pyexasol.ExaConnection:

# Create a connection to the database.
conn_params = get_connection_params(host=saas_url,
account_id=saas_account_id,
database_id=saas_database_id,
pat=saas_token)
conn = _open_pyexasol_connection(**conn_params)

# Build, upload and activate the language container
upload_language_container_saas(db_conn=conn,
saas_url=saas_url,
saas_account_id=saas_account_id,
saas_database_id=saas_database_id,
saas_token=saas_token)
yield conn
def db_conn_saas(backend, saas_url, saas_account_id, saas_database_id, saas_token) -> pyexasol.ExaConnection | None:

if backend == bfs.path.StorageBackend.saas:
# Create a connection to the database.
conn_params = get_connection_params(host=saas_url,
account_id=saas_account_id,
database_id=saas_database_id,
pat=saas_token)
conn = _open_pyexasol_connection(**conn_params)

# Build, upload and activate the language container
upload_language_container_saas(db_conn=conn,
saas_url=saas_url,
saas_account_id=saas_account_id,
saas_database_id=saas_database_id,
saas_token=saas_token)
yield conn
else:
yield None


@pytest.fixture(scope="session")
def db_conn(request,
def db_conn(backend,
db_conn_onprem,
db_conn_saas) -> pyexasol.ExaConnection:
if (hasattr(request, 'param') and
(request.param == bfs.path.StorageBackend.saas)):
if backend == bfs.path.StorageBackend.saas:
assert db_conn_saas is not None
yield db_conn_saas
else:
assert db_conn_onprem is not None
yield db_conn_onprem
5 changes: 2 additions & 3 deletions tests/fixtures/script_deployment_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ def deploy_params_saas(saas_url, saas_account_id, saas_database_id, saas_token)


@pytest.fixture(scope="session")
def deploy_params(request,
def deploy_params(backend,
deploy_params_onprem,
deploy_params_saas) -> dict[str, Any]:
if (hasattr(request, 'param') and
(request.param == bfs.path.StorageBackend.saas)):
if backend == bfs.path.StorageBackend.saas:
yield deploy_params_saas
else:
yield deploy_params_onprem
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import pytest
from typing import Dict
from exasol_sagemaker_extension.autopilot_endpoint_deletion_udf import \
AutopilotEndpointDeletionUDF
Expand Down Expand Up @@ -40,14 +39,10 @@ def get_emitted(self):
return self._emitted


@pytest.mark.skipif(not aws_params.aws_secret_access_key,
reason="AWS credentials are not set")
def test_autopilot_regression_endpoint_deletion_udf_real():
_run_test(reg_setup_params)


@pytest.mark.skipif(not aws_params.aws_secret_access_key,
reason="AWS credentials are not set")
def test_autopilot_classification_endpoint_deletion_udf_real():
_run_test(cls_setup_params)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import pytest
from typing import Dict
from exasol_sagemaker_extension.autopilot_endpoint_deployment_udf import \
AutopilotEndpointDeploymentUDF
Expand Down Expand Up @@ -49,14 +48,10 @@ def get_emitted(self):
return self._emitted


@pytest.mark.skipif(not aws_params.aws_secret_access_key,
reason="AWS credentials are not set")
def test_autopilot_regression_endpoint_deployment_udf_real():
_run_test(reg_setup_params)


@pytest.mark.skipif(not aws_params.aws_secret_access_key,
reason="AWS credentials are not set")
def test_autopilot_classification_endpoint_deployment_udf_real():
_run_test(cls_setup_params)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import pytest
from typing import Dict
from exasol_sagemaker_extension.autopilot_job_status_polling_udf import \
AutopilotJobStatusPollingUDF
Expand Down Expand Up @@ -40,14 +39,10 @@ def get_emitted(self):
return self._emitted


@pytest.mark.skipif(not aws_params.aws_secret_access_key,
reason="AWS credentials are not set")
def test_poll_autopilot_regression_training_status_udf_real():
_run_test(reg_setup_params)


@pytest.mark.skipif(not aws_params.aws_secret_access_key,
reason="AWS credentials are not set")
def test_poll_autopilot_classification_training_status_udf_real():
_run_test(cls_setup_params)

Expand Down
5 changes: 0 additions & 5 deletions tests/integration_tests/test_autopilot_prediction_udf_real.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import json
import pytest
import pandas as pd
from typing import Dict
from exasol_sagemaker_extension.autopilot_prediction_udf import \
Expand Down Expand Up @@ -62,8 +61,6 @@ def get_dataframe(self, num_rows='all'):
return return_df


@pytest.mark.skipif(not aws_params.aws_secret_access_key,
reason="AWS credentials are not set")
def test_regression_autopilot_prediction_udf_real():
connection_data = {
"aws_s3_connection": aws_params.aws_conn_name,
Expand Down Expand Up @@ -101,8 +98,6 @@ def test_regression_autopilot_prediction_udf_real():
assert ctx.get_emitted()[0][0].shape == (3, 3)


@pytest.mark.skipif(not aws_params.aws_secret_access_key,
reason="AWS credentials are not set")
def test_classification_autopilot_prediction_udf_real():
connection_data = {
"aws_s3_connection": aws_params.aws_conn_name,
Expand Down
7 changes: 0 additions & 7 deletions tests/integration_tests/test_autopilot_training_udf_real.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import pytest
from typing import Dict
from exasol_sagemaker_extension.autopilot_training_udf import \
AutopilotTrainingUDF
Expand Down Expand Up @@ -60,8 +59,6 @@ def get_emitted(self):
return self._emitted


@pytest.mark.skipif(not aws_params.aws_secret_access_key,
reason="AWS credentials are not set")
def test_autopilot_regression_training_udf_real():
params_dict = {
'setup_params': reg_setup_params,
Expand All @@ -74,8 +71,6 @@ def test_autopilot_regression_training_udf_real():
params_dict['problem_params'])


@pytest.mark.skipif(not aws_params.aws_secret_access_key,
reason="AWS credentials are not set")
def test_autopilot_classification_training_udf_real():
params_dict = {
'setup_params': cls_setup_params,
Expand All @@ -88,8 +83,6 @@ def test_autopilot_classification_training_udf_real():
params_dict['problem_params'])


@pytest.mark.skipif(not aws_params.aws_secret_access_key,
reason="AWS credentials are not set")
def test_autopilot_multi_classification_training_udf_real():
params_dict = {
'setup_params': cls_setup_params,
Expand Down
Loading

0 comments on commit a24a46d

Please sign in to comment.