Skip to content

Commit

Permalink
#44 Features from pytest-itde and pytest-saas migrated to pytest-backend
Browse files Browse the repository at this point in the history
  • Loading branch information
ahsimb committed Aug 13, 2024
1 parent ee19f20 commit 66a3c8c
Show file tree
Hide file tree
Showing 10 changed files with 760 additions and 162 deletions.
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.
80 changes: 79 additions & 1 deletion pytest-backend/exasol/pytest_backend/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
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.conftest import itde_pytest_addoption

_BACKEND_OPTION = '--backend'
_BACKEND_ONPREM = 'onprem'
Expand All @@ -33,6 +38,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.""",
)
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 @@ -91,6 +127,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
133 changes: 133 additions & 0 deletions pytest-backend/exasol/pytest_backend/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import os
import pytest
from exasol_integration_test_docker_environment.lib.test_environment.ports import Ports

from exasol.pytest_backend import itde_config

EXASOL = itde_config.OptionGroup(
prefix="exasol",
options=(
{
"name": "host",
"type": str,
"default": "localhost",
"help_text": "Host to connect to",
},
{
"name": "port",
"type": int,
"default": Ports.forward.database,
"help_text": "Port on which the exasol db is listening",
},
{
"name": "username",
"type": str,
"default": "SYS",
"help_text": "Username used to authenticate against the exasol db",
},
{
"name": "password",
"type": str,
"default": "exasol",
"help_text": "Password used to authenticate against the exasol db",
},
),
)

BUCKETFS = itde_config.OptionGroup(
prefix="bucketfs",
options=(
{
"name": "url",
"type": str,
"default": f"http://127.0.0.1:{Ports.forward.bucketfs}",
"help_text": "Base url used to connect to the bucketfs service",
},
{
"name": "username",
"type": str,
"default": "w",
"help_text": "Username used to authenticate against the bucketfs service",
},
{
"name": "password",
"type": str,
"default": "write",
"help_text": "Password used to authenticate against the bucketfs service",
},
),
)

SSH = itde_config.OptionGroup(
prefix="ssh",
options=(
{
"name": "port",
"type": int,
"default": Ports.forward.ssh,
"help_text": "Port on which external processes can access the database via SSH protocol",
},
),
)


ITDE = itde_config.OptionGroup(
prefix="itde",
options=(
{
"name": "db_version",
"type": str,
"default": "8.18.1",
"help_text": "DB version to start, if value is 'external' an existing instance will be used",
},
),
)

OPTION_GROUPS = (EXASOL, BUCKETFS, ITDE, SSH)


def _add_option_group(parser, group):
parser_group = parser.getgroup(group.prefix)
for option in group.options:
parser_group.addoption(
option.cli,
type=option.type,
help=option.help,
)


def itde_pytest_addoption(parser):
for group in OPTION_GROUPS:
_add_option_group(parser, group)


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


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


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


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

0 comments on commit 66a3c8c

Please sign in to comment.