diff --git a/test/integration/cli/test_language_container_deployer_cli.py b/test/integration/cli/test_language_container_deployer_cli.py index 7ecab2f..77b9e81 100644 --- a/test/integration/cli/test_language_container_deployer_cli.py +++ b/test/integration/cli/test_language_container_deployer_cli.py @@ -17,10 +17,10 @@ @pytest.fixture(scope='session') -def onprem_params(backend_aware_onprem_database, - exasol_config, - bucketfs_config, - language_alias) -> dict[str, Any]: +def onprem_cli_args(backend_aware_onprem_database, + exasol_config, + bucketfs_config, + language_alias) -> dict[str, Any]: parsed_url = urlparse(bucketfs_config.url) host, port = parsed_url.netloc.split(":") @@ -36,41 +36,37 @@ def onprem_params(backend_aware_onprem_database, StdParams.bucketfs_name.name: 'bfsdefault', StdParams.bucket.name: 'default', StdParams.use_ssl_cert_validation.name: False, - StdParams.path_in_bucket.name: 'container', - StdParams.language_alias.name: language_alias } @pytest.fixture(scope='session') -def saas_params(saas_host, - saas_pat, - saas_account_id, - backend_aware_saas_database_id, - language_alias) -> dict[str, Any]: +def saas_cli_args(saas_host, + saas_pat, + saas_account_id, + backend_aware_saas_database_id, + ) -> dict[str, Any]: return { StdParams.saas_url.name: saas_host, StdParams.saas_account_id.name: saas_account_id, StdParams.saas_database_id.name: backend_aware_saas_database_id, StdParams.saas_token.name: saas_pat, - StdParams.path_in_bucket.name: 'container', - StdParams.language_alias.name: language_alias } -def make_args_string(**kwargs) -> str: - return ' '.join(f'--{k} "{v}"' for k, v in kwargs.items()) - +@pytest.fixture(scope='session') +def slc_cli_args(language_alias) -> dict[str, Any]: + return { + StdParams.alter_system: True, + StdParams.allow_override: True, + StdParams.wait_for_completion: True, + StdParams.path_in_bucket.name: 'container', + StdParams.language_alias.name: language_alias + } -def test_slc_deployer_cli_onprem_url(use_onprem, - container_version, - container_name, - container_url_formatter, - language_alias, - db_schema, - onprem_params): - if not use_onprem: - pytest.skip("The test is not configured to use ITDE.") +@pytest.fixture +def deploy_command(container_name, + container_url_formatter) -> click.Command: ver_formatter = ParameterFormatters() ver_formatter.set_formatter(CONTAINER_URL_ARG, container_url_formatter) ver_formatter.set_formatter(CONTAINER_NAME_ARG, container_name) @@ -81,36 +77,58 @@ def test_slc_deployer_cli_onprem_url(use_onprem, cli_callback = LanguageContainerDeployerCli( container_url_arg=CONTAINER_URL_ARG, container_name_arg=CONTAINER_NAME_ARG) - extra_params = {StdParams.version.name: container_version} - args = make_args_string(**onprem_params, **extra_params) - cmd = click.Command('deploy_slc', params=opts, callback=cli_callback) + return click.Command('deploy_slc', params=opts, callback=cli_callback) + + +def make_args_string(**kwargs) -> str: + def arg_string(k: str, v: Any): + k = k.replace("_", "-") + if isinstance(v, bool): + return f'--{k}' if v else f'--no-{k}' + return f'--{k} "{v}"' + + return ' '.join(arg_string(k, v) for k, v in kwargs.items()) + + +def run_deploy_command(deploy_command: click.Command, + arg_string: str, + language_alias: str, + db_schema: str, + **db_kwargs): runner = CliRunner() - runner.invoke(cmd, args=args) + runner.invoke(deploy_command, args=arg_string, catch_exceptions=False) - with open_pyexasol_connection(**onprem_params) as conn: + with open_pyexasol_connection(**db_kwargs) as conn: create_schema(conn, db_schema) assert_udf_running(conn, language_alias, db_schema) +def test_slc_deployer_cli_onprem_url(use_onprem, + container_version, + language_alias, + db_schema, + deploy_command, + onprem_cli_args, + slc_cli_args): + if not use_onprem: + pytest.skip("The test is not configured to use ITDE.") + + extra_cli_args = {StdParams.version.name: container_version} + arg_string = make_args_string(**onprem_cli_args, **slc_cli_args, **extra_cli_args) + run_deploy_command(deploy_command, arg_string, language_alias, db_schema, **onprem_cli_args) + + def test_slc_deployer_cli_onprem_file(use_onprem, container_path, language_alias, db_schema, - onprem_params): + deploy_command, + onprem_cli_args, + slc_cli_args): if not use_onprem: pytest.skip("The test is not configured to use ITDE.") - opts = select_std_options( - [StdTags.DB | StdTags.ONPREM, StdTags.BFS | StdTags.ONPREM, StdTags.SLC]) - cli_callback = LanguageContainerDeployerCli() - extra_params = {StdParams.container_file.name: container_path} - args = make_args_string(**onprem_params, **extra_params) - - cmd = click.Command('deploy_slc', params=opts, callback=cli_callback) - runner = CliRunner() - runner.invoke(cmd, args=args) - - with open_pyexasol_connection(**onprem_params) as conn: - create_schema(conn, db_schema) - assert_udf_running(conn, language_alias, db_schema) + extra_cli_args = {StdParams.container_file.name: container_path} + arg_string = make_args_string(**onprem_cli_args, **slc_cli_args, **extra_cli_args) + run_deploy_command(deploy_command, arg_string, language_alias, db_schema, **onprem_cli_args)