-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* #10: Added pytest fixtures for usage in integration tests of external projects * Use pyyaml for reading project short tag from error_code_config.yml * Added ip-whitelisting to fixture operational_saas_database_id * Verified fixture in test_operational_database * Replaced bash script in justfile by python * Added developer instructions * Updated README file * moved developer instructions to Developer guide. Co-authored-by: Torsten Kilias <[email protected]>
- Loading branch information
Showing
16 changed files
with
418 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Pytest-Plugins for Exasol | ||
|
||
Welcome to the official repository for Exasol pytest-plugins! | ||
|
||
This collection of plugins is designed to enhance and simplify the testing experience for projects related to Exasol. | ||
|
||
By providing a centralized location for pytest plugins, we aim to foster collaboration, ensure consistency, and improve the quality of testing practices within the organization. | ||
|
||
## Introduction | ||
|
||
[pytest](https://pytest.org) is a powerful testing framework for [python](https://www.python.org), and with the help of these plugins, developers can extend its functionality to better suit the testing requirements of Exasol-related projects. | ||
|
||
Whether you're looking to use database interactions, enhance test reporting, or streamline your testing pipeline, our plugins are here to help. | ||
|
||
## Plugins | ||
|
||
| Plugin | Description | PYPI | | ||
|----------------------|----------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------| | ||
| `pytest-exasol-itde` | Fixture to enable simple usage with Exasol's project [ITDE](https://github.com/exasol/integration-test-docker-environment) | [pytest-exasol-itde](https://pypi.org/project/pytest-exasol-itde/) | | ||
| `pytest-exasol-saas` | Fixture to enable simple usage with Exasol's project [saas-api-python](https://github.com/exasol/saas-api-python/) | [pytest-exasol-saas](https://pypi.org/project/pytest-exasol-saas/) | | ||
|
||
|
||
## Installation | ||
|
||
To ensure you're using the latest features and bug fixes, we recommend installing the plugins directly from PyPI using your preferred package manager. This approach simplifies the process of keeping your testing environment up-to-date. | ||
|
||
For example, to install the `pytest-exasol-itde` plugin, you could use the following command: | ||
|
||
|
||
```shell | ||
pip install pytest-exasol-itde | ||
``` | ||
|
||
To install a specific version of a plugin, simply specify the version number: | ||
|
||
```shell | ||
pip install "pytest-exasol-itde==x.y.z" | ||
``` | ||
|
||
Replace x.y.z with the desired version number. | ||
|
||
## Development | ||
|
||
See [Developer Guide](doc/developer-guide.md). |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Developer Guide Exasol pytest-plugins | ||
|
||
## Dependencies | ||
|
||
Before you can start developing in this workspace, please ensure you have the following tools installed either globally or at a workspace level. | ||
|
||
* [Python](https://www.python.org) | ||
* [Just](https://github.com/casey/just) | ||
|
||
## Run Tests | ||
|
||
### Slow Tests | ||
|
||
Some of the test cases verify connecting to a SaaS database instance and | ||
execution will take about 20 minutes. | ||
|
||
These test cases are only executed by the following GitHub workflows | ||
* `ci-main.yml` | ||
* `ci-slow.yml` | ||
|
||
Both of these workflows can be run manually, workflow `ci-main.yml` is executed automatically at the 7th day of each month. | ||
|
||
For merging a pull request to branch `main` workflow `ci-slow.yml` needs to be run and terminate successfully. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import os | ||
from pathlib import Path | ||
|
||
import pytest | ||
from exasol.saas.client import openapi | ||
from exasol.saas.client.api_access import ( | ||
OpenApiAccess, | ||
create_saas_client, | ||
timestamp_name, | ||
) | ||
|
||
import exasol.pytest_saas.project_short_tag as pst | ||
|
||
|
||
def pytest_addoption(parser): | ||
parser.addoption( | ||
f"--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( | ||
f"--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( | ||
f"--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.""", | ||
) | ||
|
||
|
||
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 saas_database( | ||
request, api_access, database_name | ||
) -> openapi.models.database.Database: | ||
""" | ||
Note: The SaaS instance database returned by this fixture initially | ||
will not be operational. The startup takes about 20 minutes. | ||
""" | ||
db_id = request.config.getoption("--saas-database-id") | ||
if db_id: | ||
yield api_access.get_database(db_id) | ||
return | ||
with api_access.database(database_name) as db: | ||
yield db | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def operational_saas_database_id(api_access, saas_database) -> str: | ||
db = saas_database | ||
api_access.add_allowed_ip() | ||
api_access.wait_until_running(db.id) | ||
return db.id |
Oops, something went wrong.