pytest-exasol-extension 0.1.0__py3-none-any.whl → 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- exasol/pytest_extension/__init__.py +125 -45
- pytest_exasol_extension-0.2.0.dist-info/METADATA +108 -0
- pytest_exasol_extension-0.2.0.dist-info/RECORD +6 -0
- pytest_exasol_extension-0.1.0.dist-info/METADATA +0 -56
- pytest_exasol_extension-0.1.0.dist-info/RECORD +0 -6
- {pytest_exasol_extension-0.1.0.dist-info → pytest_exasol_extension-0.2.0.dist-info}/WHEEL +0 -0
- {pytest_exasol_extension-0.1.0.dist-info → pytest_exasol_extension-0.2.0.dist-info}/entry_points.txt +0 -0
|
@@ -1,54 +1,15 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
from typing import Any, Callable
|
|
3
|
-
import json
|
|
4
3
|
import random
|
|
5
4
|
import string
|
|
5
|
+
from urllib.parse import urlparse
|
|
6
6
|
import pyexasol
|
|
7
7
|
import pytest
|
|
8
8
|
|
|
9
9
|
from exasol.pytest_backend import BACKEND_ONPREM, BACKEND_SAAS
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
filtered_kwargs = {k: v for k, v in bucketfs_params.items()
|
|
14
|
-
if (k in selected) and (v is not None)}
|
|
15
|
-
return json.dumps(filtered_kwargs)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
def _create_bucketfs_connection(pyexasol_connection: pyexasol.ExaConnection,
|
|
19
|
-
conn_name: str,
|
|
20
|
-
conn_to: str,
|
|
21
|
-
conn_user: str,
|
|
22
|
-
conn_password: str) -> None:
|
|
23
|
-
|
|
24
|
-
query = (f"CREATE OR REPLACE CONNECTION {conn_name} "
|
|
25
|
-
f"TO '{conn_to}' "
|
|
26
|
-
f"USER '{conn_user}' "
|
|
27
|
-
f"IDENTIFIED BY '{conn_password}'")
|
|
28
|
-
pyexasol_connection.execute(query)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
def _create_bucketfs_connection_onprem(pyexasol_connection: pyexasol.ExaConnection,
|
|
32
|
-
conn_name: str,
|
|
33
|
-
bucketfs_params: dict[str, Any]) -> None:
|
|
34
|
-
conn_to = _to_json_str(bucketfs_params, [
|
|
35
|
-
'backend', 'url', 'service_name', 'bucket_name', 'path', 'verify'])
|
|
36
|
-
conn_user = _to_json_str(bucketfs_params, ['username'])
|
|
37
|
-
conn_password = _to_json_str(bucketfs_params, ['password'])
|
|
38
|
-
|
|
39
|
-
_create_bucketfs_connection(pyexasol_connection, conn_name,
|
|
40
|
-
conn_to, conn_user, conn_password)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
def _create_bucketfs_connection_saas(pyexasol_connection: pyexasol.ExaConnection,
|
|
44
|
-
conn_name: str,
|
|
45
|
-
bucketfs_params: dict[str, Any]) -> None:
|
|
46
|
-
conn_to = _to_json_str(bucketfs_params, ['backend', 'url', 'path'])
|
|
47
|
-
conn_user = _to_json_str(bucketfs_params, ['account_id', 'database_id'])
|
|
48
|
-
conn_password = _to_json_str(bucketfs_params, ['pat'])
|
|
49
|
-
|
|
50
|
-
_create_bucketfs_connection(pyexasol_connection, conn_name,
|
|
51
|
-
conn_to, conn_user, conn_password)
|
|
10
|
+
from exasol.python_extension_common.cli.std_options import StdParams
|
|
11
|
+
from exasol.python_extension_common.connections.bucketfs_location import (
|
|
12
|
+
create_bucketfs_conn_object_onprem, create_bucketfs_conn_object_saas)
|
|
52
13
|
|
|
53
14
|
|
|
54
15
|
@pytest.fixture(scope="session")
|
|
@@ -105,10 +66,129 @@ def bucketfs_connection_factory(backend,
|
|
|
105
66
|
else:
|
|
106
67
|
bucketfs_params = backend_aware_bucketfs_params
|
|
107
68
|
if backend == BACKEND_ONPREM:
|
|
108
|
-
|
|
69
|
+
create_bucketfs_conn_object_onprem(pyexasol_connection, conn_name, bucketfs_params)
|
|
109
70
|
elif backend == BACKEND_SAAS:
|
|
110
|
-
|
|
71
|
+
create_bucketfs_conn_object_saas(pyexasol_connection, conn_name, bucketfs_params)
|
|
111
72
|
else:
|
|
112
73
|
raise ValueError(f'Unsupported backend {backend}')
|
|
113
74
|
|
|
114
75
|
return func
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
@pytest.fixture(scope="session")
|
|
79
|
+
def onprem_database_std_params(use_onprem,
|
|
80
|
+
backend_aware_onprem_database,
|
|
81
|
+
exasol_config) -> dict[str, Any]:
|
|
82
|
+
if use_onprem:
|
|
83
|
+
return {
|
|
84
|
+
StdParams.dsn.name: f'{exasol_config.host}:{exasol_config.port}',
|
|
85
|
+
StdParams.db_user.name: exasol_config.username,
|
|
86
|
+
StdParams.db_password.name: exasol_config.password,
|
|
87
|
+
StdParams.use_ssl_cert_validation.name: False
|
|
88
|
+
}
|
|
89
|
+
return {}
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
@pytest.fixture(scope="session")
|
|
93
|
+
def onprem_bucketfs_std_params(use_onprem,
|
|
94
|
+
backend_aware_onprem_database,
|
|
95
|
+
bucketfs_config) -> dict[str, Any]:
|
|
96
|
+
if use_onprem:
|
|
97
|
+
parsed_url = urlparse(bucketfs_config.url)
|
|
98
|
+
host, port = parsed_url.netloc.split(":")
|
|
99
|
+
return {
|
|
100
|
+
StdParams.bucketfs_host.name: host,
|
|
101
|
+
StdParams.bucketfs_port.name: port,
|
|
102
|
+
StdParams.bucketfs_use_https.name: parsed_url.scheme.lower() == 'https',
|
|
103
|
+
StdParams.bucketfs_user.name: bucketfs_config.username,
|
|
104
|
+
StdParams.bucketfs_password.name: bucketfs_config.password,
|
|
105
|
+
StdParams.bucketfs_name.name: 'bfsdefault',
|
|
106
|
+
StdParams.bucket.name: 'default',
|
|
107
|
+
StdParams.use_ssl_cert_validation.name: False
|
|
108
|
+
}
|
|
109
|
+
return {}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
@pytest.fixture(scope="session")
|
|
113
|
+
def saas_std_params(use_saas,
|
|
114
|
+
saas_host,
|
|
115
|
+
saas_pat,
|
|
116
|
+
saas_account_id,
|
|
117
|
+
backend_aware_saas_database_id) -> dict[str, Any]:
|
|
118
|
+
if use_saas:
|
|
119
|
+
return {
|
|
120
|
+
StdParams.saas_url.name: saas_host,
|
|
121
|
+
StdParams.saas_account_id.name: saas_account_id,
|
|
122
|
+
StdParams.saas_database_id.name: backend_aware_saas_database_id,
|
|
123
|
+
StdParams.saas_token.name: saas_pat
|
|
124
|
+
}
|
|
125
|
+
return {}
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
@pytest.fixture(scope="session")
|
|
129
|
+
def database_std_params(backend,
|
|
130
|
+
onprem_database_std_params,
|
|
131
|
+
saas_std_params) -> dict[str, Any]:
|
|
132
|
+
"""
|
|
133
|
+
This is a collection of StdParams parameters required to open a
|
|
134
|
+
database connection for either DockerDB or SaaS test database.
|
|
135
|
+
"""
|
|
136
|
+
if backend == BACKEND_ONPREM:
|
|
137
|
+
return onprem_database_std_params
|
|
138
|
+
elif backend == BACKEND_SAAS:
|
|
139
|
+
return saas_std_params
|
|
140
|
+
else:
|
|
141
|
+
ValueError(f'Unknown backend {backend}')
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
@pytest.fixture(scope="session")
|
|
145
|
+
def bucketfs_std_params(backend,
|
|
146
|
+
onprem_bucketfs_std_params,
|
|
147
|
+
saas_std_params) -> dict[str, Any]:
|
|
148
|
+
"""
|
|
149
|
+
This is a collection of StdParams parameters required to connect
|
|
150
|
+
to the BucketFS on either DockerDB or SaaS test database.
|
|
151
|
+
"""
|
|
152
|
+
if backend == BACKEND_ONPREM:
|
|
153
|
+
return onprem_bucketfs_std_params
|
|
154
|
+
elif backend == BACKEND_SAAS:
|
|
155
|
+
return saas_std_params
|
|
156
|
+
else:
|
|
157
|
+
ValueError(f'Unknown backend {backend}')
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def _cli_params_to_args(cli_params) -> str:
|
|
161
|
+
def arg_string(k: str, v: Any):
|
|
162
|
+
k = k.replace("_", "-")
|
|
163
|
+
if isinstance(v, bool):
|
|
164
|
+
return f'--{k}' if v else f'--no-{k}'
|
|
165
|
+
return f'--{k} "{v}"'
|
|
166
|
+
|
|
167
|
+
return ' '.join(arg_string(k, v) for k, v in cli_params.items())
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
@pytest.fixture(scope='session')
|
|
171
|
+
def database_cli_args(database_std_params) -> str:
|
|
172
|
+
"""
|
|
173
|
+
CLI argument string for testing a command that involves connecting to the database.
|
|
174
|
+
"""
|
|
175
|
+
return _cli_params_to_args(database_std_params)
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
@pytest.fixture(scope='session')
|
|
179
|
+
def bucketfs_cli_args(bucketfs_std_params) -> str:
|
|
180
|
+
"""
|
|
181
|
+
CLI argument string for testing a command that involves connecting to the BucketFS .
|
|
182
|
+
"""
|
|
183
|
+
return _cli_params_to_args(bucketfs_std_params)
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
@pytest.fixture(scope='session')
|
|
187
|
+
def cli_args(database_std_params, bucketfs_std_params):
|
|
188
|
+
"""
|
|
189
|
+
CLI argument string for testing a command that involves connecting to both
|
|
190
|
+
the database and the BucketFS.
|
|
191
|
+
"""
|
|
192
|
+
std_params = dict(database_std_params)
|
|
193
|
+
std_params.update(bucketfs_std_params)
|
|
194
|
+
return _cli_params_to_args(database_std_params)
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: pytest-exasol-extension
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary:
|
|
5
|
+
Author: Mikhail Beck
|
|
6
|
+
Author-email: mikhail.beck@exasol.com
|
|
7
|
+
Requires-Python: >=3.10,<4
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Requires-Dist: exasol-python-extension-common (>=0.7.0,<1)
|
|
13
|
+
Requires-Dist: pyexasol (>=0.26.0,<1)
|
|
14
|
+
Requires-Dist: pytest (>=7,<9)
|
|
15
|
+
Requires-Dist: pytest-exasol-backend (>=0.2.0)
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
|
|
18
|
+
# pytest-exasol-extension Plugin
|
|
19
|
+
|
|
20
|
+
The `pytest-exasol-extension` plugin provides pytest fixtures for preparing a database for the extension tests.
|
|
21
|
+
The fixtures are backend agnostic. They run for the selected backends
|
|
22
|
+
(see the documentation for the `pytest-exasol-backend` plugin).
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
The pytest-exasol-extension plugin can be installed using pip:
|
|
27
|
+
|
|
28
|
+
```shell
|
|
29
|
+
pip install pytest-exasol-extension
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Usage in Tests
|
|
33
|
+
|
|
34
|
+
Below is an example of a test that requires a database connection with an open test schema.
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
import pytest
|
|
38
|
+
|
|
39
|
+
@pytest.fixture(scope="session")
|
|
40
|
+
def db_schema_name() -> str:
|
|
41
|
+
"""Let's override a randomly generated db schema for the test, giving it a meaningful name."""
|
|
42
|
+
return 'MY_TEST_SCHEMA'
|
|
43
|
+
|
|
44
|
+
def test_something(pyexasol_connection):
|
|
45
|
+
...
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Next, is an example of a test that needs to store a bucket-fs connection object in the database.
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
def test_something_else(bucketfs_connection_factory):
|
|
52
|
+
bucketfs_connection_factory('my_connection_name,' 'some_path/in_the_bucket')
|
|
53
|
+
...
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
The following fixtures are used to test various deployment scenarios where the connection parameters
|
|
57
|
+
for the Database and the BucketFS are supplied in a command line. The first two fixtures provide dictionaries
|
|
58
|
+
of standard cli parameters (`StdParams`) defined in the `exasol-python-extension-common`.
|
|
59
|
+
|
|
60
|
+
`database_std_params` - the Database connection parameters.
|
|
61
|
+
`bucketfs_std_params` - the BucketFs connection parameters.
|
|
62
|
+
|
|
63
|
+
The next two fixtures - `database_cli_args` and `bucketfs_cli_args` - give the same parameters as the previous two
|
|
64
|
+
but in the form of command line arguments. They are helpful for testing the CLI directly, for example using the
|
|
65
|
+
click.CliRunner as in the samples below. There is also a fixture - `cli_args` - that combines these two argument
|
|
66
|
+
strings.
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
import click
|
|
70
|
+
from click.testing import CliRunner
|
|
71
|
+
from exasol.python_extension_common.cli.std_options import (StdParams, StdTags, select_std_options)
|
|
72
|
+
from exasol.pytest_backend import (BACKEND_ONPREM, BACKEND_SAAS)
|
|
73
|
+
|
|
74
|
+
def test_db_connection_cli(backend, database_cli_args):
|
|
75
|
+
if backend == BACKEND_ONPREM:
|
|
76
|
+
tags = StdTags.DB | StdTags.ONPREM
|
|
77
|
+
elif backend == BACKEND_SAAS:
|
|
78
|
+
tags = StdTags.DB | StdTags.SAAS
|
|
79
|
+
else:
|
|
80
|
+
ValueError(f'Unknown backend {backend}')
|
|
81
|
+
|
|
82
|
+
def test_something_with_db(**kwargs):
|
|
83
|
+
pass
|
|
84
|
+
|
|
85
|
+
opts = select_std_options(tags)
|
|
86
|
+
cmd = click.Command('whatever', params=opts, callback=test_something_with_db)
|
|
87
|
+
runner = CliRunner()
|
|
88
|
+
runner.invoke(cmd, args=database_cli_args, catch_exceptions=False, standalone_mode=False)
|
|
89
|
+
|
|
90
|
+
def test_bucketfs_connection_cli(backend, bucketfs_cli_args):
|
|
91
|
+
if backend == BACKEND_ONPREM:
|
|
92
|
+
tags = StdTags.BFS | StdTags.ONPREM
|
|
93
|
+
elif backend == BACKEND_SAAS:
|
|
94
|
+
tags = StdTags.BFS | StdTags.SAAS
|
|
95
|
+
else:
|
|
96
|
+
ValueError(f'Unknown backend {backend}')
|
|
97
|
+
|
|
98
|
+
def test_something_with_bucketfs(**kwargs):
|
|
99
|
+
pass
|
|
100
|
+
|
|
101
|
+
opts = select_std_options(tags)
|
|
102
|
+
cmd = click.Command('whatever', params=opts, callback=test_something_with_bucketfs)
|
|
103
|
+
runner = CliRunner()
|
|
104
|
+
runner.invoke(cmd, args=bucketfs_cli_args, catch_exceptions=False, standalone_mode=False)
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Note, that by default the tests will run twice - once for each backend.
|
|
108
|
+
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
exasol/pytest_extension/__init__.py,sha256=M3NG7hCnPLc1f8jWCvOdIdPgvIbcoj-ckE2C3MZidS4,7135
|
|
2
|
+
exasol/pytest_extension/version.py,sha256=4nqSPlb5zgkyYIODu1QrqRckkyoRUBp7vS7rvymvQ0k,404
|
|
3
|
+
pytest_exasol_extension-0.2.0.dist-info/METADATA,sha256=UdCuBCHogJza1gcxtWmoSkQLqszPEaoK4NRpUk0fbWc,3856
|
|
4
|
+
pytest_exasol_extension-0.2.0.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
|
5
|
+
pytest_exasol_extension-0.2.0.dist-info/entry_points.txt,sha256=7OAFswb2haZ4in-vuf3tRBHb0GAZSZZ2BJn-DStsfys,40
|
|
6
|
+
pytest_exasol_extension-0.2.0.dist-info/RECORD,,
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: pytest-exasol-extension
|
|
3
|
-
Version: 0.1.0
|
|
4
|
-
Summary:
|
|
5
|
-
Author: Mikhail Beck
|
|
6
|
-
Author-email: mikhail.beck@exasol.com
|
|
7
|
-
Requires-Python: >=3.10,<4
|
|
8
|
-
Classifier: Programming Language :: Python :: 3
|
|
9
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
10
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
-
Requires-Dist: pyexasol (>=0.26.0,<1)
|
|
13
|
-
Requires-Dist: pytest (>=7,<9)
|
|
14
|
-
Requires-Dist: pytest-exasol-backend (>=0.2.0)
|
|
15
|
-
Description-Content-Type: text/markdown
|
|
16
|
-
|
|
17
|
-
# pytest-exasol-extension Plugin
|
|
18
|
-
|
|
19
|
-
The `pytest-exasol-extension` plugin provides pytest fixtures for preparing a database for the extension tests.
|
|
20
|
-
The fixtures are backend agnostic. They run for the selected backends
|
|
21
|
-
(see the documentation for the `pytest-exasol-backend` plugin).
|
|
22
|
-
|
|
23
|
-
## Installation
|
|
24
|
-
|
|
25
|
-
The pytest-exasol-extension plugin can be installed using pip:
|
|
26
|
-
|
|
27
|
-
```shell
|
|
28
|
-
pip install pytest-exasol-extension
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
## Usage in Tests
|
|
32
|
-
|
|
33
|
-
Below is an example of a test that requires a database connection with an open test schema.
|
|
34
|
-
|
|
35
|
-
```python
|
|
36
|
-
import pytest
|
|
37
|
-
|
|
38
|
-
@pytest.fixture(scope="session")
|
|
39
|
-
def db_schema_name() -> str:
|
|
40
|
-
"""Let's override a randomly generated db schema for the test, giving it a meaningful name."""
|
|
41
|
-
return 'MY_TEST_SCHEMA'
|
|
42
|
-
|
|
43
|
-
def test_something(pyexasol_connection):
|
|
44
|
-
...
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
Next, is an example of a test that needs to store a bucket-fs connection object in the database.
|
|
48
|
-
|
|
49
|
-
```python
|
|
50
|
-
def test_something_else(bucketfs_connection_factory):
|
|
51
|
-
bucketfs_connection_factory('my_connection_name,' 'some_path/in_the_bucket')
|
|
52
|
-
...
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
Note, that by default the tests will run twice - once for each backend.
|
|
56
|
-
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
exasol/pytest_extension/__init__.py,sha256=sJjK3oIx9f1rJuVkl8fWocZPhr3fjekCTNxbGKAY0GM,4698
|
|
2
|
-
exasol/pytest_extension/version.py,sha256=4nqSPlb5zgkyYIODu1QrqRckkyoRUBp7vS7rvymvQ0k,404
|
|
3
|
-
pytest_exasol_extension-0.1.0.dist-info/METADATA,sha256=-yIvImipjQNYBO-bkyfQlkAGi1gVqlra0Qf6BPxm4a0,1643
|
|
4
|
-
pytest_exasol_extension-0.1.0.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
|
5
|
-
pytest_exasol_extension-0.1.0.dist-info/entry_points.txt,sha256=7OAFswb2haZ4in-vuf3tRBHb0GAZSZZ2BJn-DStsfys,40
|
|
6
|
-
pytest_exasol_extension-0.1.0.dist-info/RECORD,,
|
|
File without changes
|
{pytest_exasol_extension-0.1.0.dist-info → pytest_exasol_extension-0.2.0.dist-info}/entry_points.txt
RENAMED
|
File without changes
|