Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#44 Features from pytest-itde and pytest-saas migrated to pytest-backend #45

Merged
merged 5 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
default: 'pytest-saas'
type: choice
options:
- "pytest-backend"
- "pytest-saas"
- "pytest-itde"
version:
Expand Down
2 changes: 1 addition & 1 deletion pytest-backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ SaaS backends. This eliminates the need to build different sets of tests for dif

## Installation

The pytest-exasol-saas plugin can be installed using pip:
The pytest-exasol-backend plugin can be installed using pip:

```shell
pip install pytest-exasol-backend
Expand Down
6 changes: 5 additions & 1 deletion pytest-backend/doc/changes/changes_0.1.0.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 0.1.0 - 2024-08-07
# 0.1.0 - 2024-08-14

## Summary

Expand All @@ -7,3 +7,7 @@
## Feature

* #37: Added the pytest-backend project

## Refactoring

* #44: Features from the pytest-itde and pytest-saas are moved to the pytest-backend in the view of deprecating the former two plugins.
118 changes: 117 additions & 1 deletion pytest-backend/exasol/pytest_backend/__init__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
from __future__ import annotations
from typing import Any
import os
from datetime import timedelta
from contextlib import ExitStack
import ssl
from urllib.parse import urlparse
import pytest

from exasol_integration_test_docker_environment.lib import api
from exasol.saas import client as saas_client
from exasol.saas.client.api_access import (
OpenApiAccess,
create_saas_client,
get_connection_params
get_connection_params,
timestamp_name
)
import exasol.pytest_backend.project_short_tag as pst
from exasol.pytest_backend.itde_config import (
itde_pytest_addoption,
ONPREM_DB_OPTIONS, OnpremDBConfig,
ONPREM_BFS_OPTIONS, OnpremBfsConfig,
SSH_OPTIONS, SshConfig,
ITDE_OPTIONS, ItdeConfig
)

_BACKEND_OPTION = '--backend'
Expand All @@ -33,6 +44,37 @@ def pytest_addoption(parser):
but this is the same as the default.
""",
)
parser.addoption(
"--project-short-tag",
help="""Short tag aka. "abbreviation" for your current project.
See docstring in project_short_tag.py for more details.
pytest plugin for exasol-saas-api will include this short tag into
the names of created database instances.""",
)
Nicoretti marked this conversation as resolved.
Show resolved Hide resolved
parser.addoption(
"--saas-database-id",
help="""ID of the instance of an existing SaaS database to be
used during the current pytest session instead of creating a
dedicated instance temporarily.""",
)
parser.addoption(
"--keep-saas-database",
action="store_true",
default=False,
help="""Keep the SaaS database instance created for the current
pytest session for subsequent inspection or reuse.""",
)
parser.addoption(
"--saas-max-idle-hours",
action="store",
default=saas_client.Limits.AUTOSTOP_DEFAULT_IDLE_TIME.total_seconds() / 3600,
help="""
The SaaS cluster would normally stop after a certain period of inactivity.
The default period is 2 hours. For some tests, this period is too short.
Use this parameter to set a sufficient idle period in the number of hours.
"""
)
itde_pytest_addoption(parser)


@pytest.fixture(scope='session', params=[_BACKEND_ONPREM, _BACKEND_SAAS])
Expand Down Expand Up @@ -61,6 +103,38 @@ def use_saas(request) -> bool:
return _is_backend_selected(request, _BACKEND_SAAS)


@pytest.fixture(scope="session")
def exasol_config(request) -> OnpremDBConfig:
"""Returns the configuration settings of the exasol db for this session."""
cli_arguments = request.config.option
kwargs = ONPREM_DB_OPTIONS.kwargs(os.environ, cli_arguments)
return OnpremDBConfig(**kwargs)


@pytest.fixture(scope="session")
def bucketfs_config(request) -> OnpremBfsConfig:
"""Returns the configuration settings of the bucketfs for this session."""
cli_arguments = request.config.option
kwargs = ONPREM_BFS_OPTIONS.kwargs(os.environ, cli_arguments)
return OnpremBfsConfig(**kwargs)


@pytest.fixture(scope="session")
def ssh_config(request) -> SshConfig:
"""Returns the configuration settings for SSH access in this session."""
cli_arguments = request.config.option
kwargs = SSH_OPTIONS.kwargs(os.environ, cli_arguments)
return SshConfig(**kwargs)


@pytest.fixture(scope="session")
def itde_config(request) -> ItdeConfig:
"""Returns the configuration settings of the ITDE for this session."""
cli_arguments = request.config.option
kwargs = ITDE_OPTIONS.kwargs(os.environ, cli_arguments)
return ItdeConfig(**kwargs)


@pytest.fixture(scope="session")
def backend_aware_onprem_database(request,
use_onprem,
Expand Down Expand Up @@ -91,6 +165,48 @@ def backend_aware_onprem_database(request,
yield


def _env(var: str) -> str:
result = os.environ.get(var)
if result:
return result
raise RuntimeError(f"Environment variable {var} is empty.")


@pytest.fixture(scope="session")
def saas_host() -> str:
return _env("SAAS_HOST")


@pytest.fixture(scope="session")
def saas_pat() -> str:
return _env("SAAS_PAT")


@pytest.fixture(scope="session")
def saas_account_id() -> str:
return _env("SAAS_ACCOUNT_ID")


@pytest.fixture(scope="session")
def project_short_tag(request):
return (
request.config.getoption("--project-short-tag")
or os.environ.get("PROJECT_SHORT_TAG")
or pst.read_from_yaml(request.config.rootpath)
)


@pytest.fixture(scope="session")
def database_name(project_short_tag):
return timestamp_name(project_short_tag)


@pytest.fixture(scope="session")
def api_access(saas_host, saas_pat, saas_account_id) -> OpenApiAccess:
with create_saas_client(saas_host, saas_pat) as client:
yield OpenApiAccess(client, saas_account_id)


@pytest.fixture(scope="session")
def backend_aware_saas_database_id(request,
use_saas,
Expand Down
Loading
Loading