-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
66a3c8c
#44 Features from pytest-itde and pytest-saas migrated to pytest-backend
ahsimb ba88fd3
#44 Moved itde fixtures to __init__.py
ahsimb 0029faa
#44 Rearranged itde stuff
ahsimb e188de6
#44 Rearranged itde stuff
ahsimb a9c25e1
#44 Rearranged itde stuff
ahsimb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
from collections import ChainMap | ||
from dataclasses import dataclass | ||
from typing import ( | ||
Generic, | ||
Optional, | ||
TypeVar, | ||
) | ||
|
||
T = TypeVar("T") | ||
|
||
|
||
@dataclass(frozen=True) | ||
class Option(Generic[T]): | ||
name: str | ||
prefix: str | ||
type: T | ||
default: Optional[T] = None | ||
help_text: str = "" | ||
|
||
@property | ||
def env(self): | ||
"""Environment variable name""" | ||
|
||
def normalize(name): | ||
name = name.replace("-", "_") | ||
name = name.upper() | ||
return name | ||
|
||
return f"{normalize(self.prefix)}_{normalize(self.name)}" | ||
|
||
@property | ||
def cli(self): | ||
"""Cli argument name""" | ||
|
||
def normalize(name): | ||
name = name.replace("_", "-") | ||
name = name.lower() | ||
return name | ||
|
||
return f"--{normalize(self.prefix)}-{normalize(self.name)}" | ||
|
||
@property | ||
def pytest(self): | ||
"""Pytest option name""" | ||
|
||
def normalize(name): | ||
name = name.replace("-", "_") | ||
name = name.lower() | ||
return name | ||
|
||
return f"{normalize(self.prefix)}_{normalize(self.name)}" | ||
|
||
@property | ||
def help(self): | ||
"""Help text including information about default value.""" | ||
if not self.default: | ||
return f"{self.help_text}." | ||
return f"{self.help_text} (default: {self.default})." | ||
|
||
|
||
class OptionGroup: | ||
""" | ||
Wraps a set of pytest options. | ||
""" | ||
|
||
def __init__(self, prefix, options): | ||
self._prefix = prefix | ||
self._options = tuple(Option(prefix=prefix, **kwargs) for kwargs in options) | ||
self._default = {o.name: o.default for o in self._options} | ||
self._env = {} | ||
self._cli = {} | ||
self._kwargs = ChainMap(self._cli, self._env, self._default) | ||
|
||
@property | ||
def prefix(self): | ||
"""The option group prefix.""" | ||
return self._prefix | ||
|
||
@property | ||
def options(self): | ||
"""A tuple of all options which are part of this group.""" | ||
return self._options | ||
|
||
def kwargs(self, environment, cli_arguments): | ||
""" | ||
Given the default values, the passed environment and cli arguments it will | ||
take care of the prioritization for the option values in regard of their | ||
source(s) and return a kwargs dictionary with all options and their | ||
appropriate value. | ||
""" | ||
env = { | ||
o.name: o.type(environment[o.env]) | ||
for o in self._options | ||
if o.env in environment | ||
} | ||
cli = { | ||
o.name: getattr(cli_arguments, o.pytest) | ||
for o in self.options | ||
if hasattr(cli_arguments, o.pytest) | ||
and getattr(cli_arguments, o.pytest) is not None | ||
} | ||
self._env.update(env) | ||
self._cli.update(cli) | ||
return self._kwargs |
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,168 @@ | ||
import os | ||
from dataclasses import dataclass | ||
import pytest | ||
|
||
from exasol_integration_test_docker_environment.lib.test_environment.ports import Ports | ||
import exasol.pytest_backend.config as config | ||
|
||
|
||
@dataclass | ||
class OnpremDBConfig: | ||
"""Exasol database configuration""" | ||
|
||
host: str | ||
port: int | ||
username: str | ||
password: str | ||
|
||
|
||
@dataclass | ||
class OnpremBfsConfig: | ||
"""Bucketfs configuration""" | ||
|
||
url: str | ||
username: str | ||
password: str | ||
|
||
|
||
@dataclass | ||
class SshConfig: | ||
"""SSH configuration""" | ||
|
||
port: int | ||
|
||
|
||
@dataclass | ||
class ItdeConfig: | ||
"""Itde configuration settings""" | ||
|
||
db_version: str | ||
|
||
|
||
_ONPREM_DB_OPTIONS = 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", | ||
}, | ||
), | ||
) | ||
|
||
_ONPREM_BFS_OPTIONS = 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_OPTIONS = 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_OPTIONS = 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", | ||
}, | ||
), | ||
) | ||
|
||
_ITDE_OPTION_GROUPS = (_ONPREM_DB_OPTIONS, _ONPREM_BFS_OPTIONS, _ITDE_OPTIONS, _SSH_OPTIONS) | ||
|
||
|
||
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 _ITDE_OPTION_GROUPS: | ||
_add_option_group(parser, group) | ||
|
||
|
||
@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) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should do the same for you