-
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.
#47 Calling backend tests indirectly
- Loading branch information
Showing
2 changed files
with
25 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,35 @@ | ||
from textwrap import dedent | ||
import pytest | ||
|
||
import pyexasol | ||
import exasol.bucketfs as bfs | ||
from exasol.pytest_backend import (BACKEND_OPTION, BACKEND_ONPREM, BACKEND_SAAS) | ||
|
||
pytest_plugins = ["pytester"] | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"test_case,cli_args,num_passed,num_skipped", | ||
"test_code", | ||
[ | ||
( | ||
dedent(""" | ||
def test_onprem_only(backend, use_onprem, use_saas): | ||
assert backend == 'onprem' | ||
assert use_onprem | ||
assert not use_saas | ||
"""), | ||
["--backend", "onprem"], | ||
1, 1 | ||
), | ||
( | ||
dedent(""" | ||
def test_saas_only(backend, use_onprem, use_saas): | ||
assert backend == 'saas' | ||
assert not use_onprem | ||
assert use_saas | ||
"""), | ||
["--backend", "saas"], | ||
1, 1 | ||
), | ||
( | ||
dedent(""" | ||
def test_default(backend, use_onprem, use_saas): | ||
assert use_onprem | ||
assert use_saas | ||
"""), | ||
[], | ||
2, 0 | ||
), | ||
( | ||
dedent(""" | ||
def test_no_backend(use_onprem, use_saas): | ||
assert use_onprem | ||
assert use_saas | ||
"""), | ||
[], | ||
1, 0 | ||
), | ||
], ids=["onprem_only", "saas_only", "default", "no_backend"]) | ||
def test_pass_options_via_cli(pytester, test_case, cli_args, num_passed, num_skipped): | ||
""" | ||
This test could also be called a unit test and verifies that the CLI | ||
arguments are registered correctly, can be passed to pytest, and are | ||
accessible within external test cases. | ||
""" | ||
pytester.makepyfile(test_case) | ||
result = pytester.runpytest(*cli_args) | ||
dedent(""" | ||
import pyexasol | ||
def test_backend_aware_database_params(backend_aware_database_params): | ||
conn = pyexasol.connect(**backend_aware_database_params) | ||
res = conn.execute('SELECT SESSION_ID FROM SYS.EXA_ALL_SESSIONS;').fetchall() | ||
assert res | ||
"""), | ||
dedent(""" | ||
import exasol.bucketfs as bfs | ||
def test_backend_aware_bucketfs_params(backend_aware_bucketfs_params): | ||
bfs_path = bfs.path.build_path(**backend_aware_bucketfs_params, path='plugin_test') | ||
file_content = b'In God We Trust' | ||
bfs_path.write(file_content) | ||
data_back = b''.join(bfs_path.read()) | ||
bfs_path.rm() | ||
assert data_back == file_content | ||
"""), | ||
], ids=["database", "bucketfs"] | ||
) | ||
def test_pytest_backend(pytester, test_code): | ||
pytester.makepyfile(test_code) | ||
result = pytester.runpytest(BACKEND_OPTION, BACKEND_ONPREM, BACKEND_OPTION, BACKEND_SAAS) | ||
assert result.ret == pytest.ExitCode.OK | ||
result.assert_outcomes(passed=num_passed, skipped=num_skipped) | ||
|
||
|
||
def test_backend_aware_database_params(backend_aware_database_params): | ||
conn = pyexasol.connect(**backend_aware_database_params) | ||
res = conn.execute('SELECT SESSION_ID FROM SYS.EXA_ALL_SESSIONS;').fetchall() | ||
assert res | ||
|
||
|
||
def test_backend_aware_bucketfs_params(backend_aware_bucketfs_params): | ||
bfs_path = bfs.path.build_path(**backend_aware_bucketfs_params, path='plugin_test') | ||
file_content = b'In God We Trust' | ||
bfs_path.write(file_content) | ||
data_back = b''.join(bfs_path.read()) | ||
bfs_path.rm() | ||
assert data_back == file_content | ||
result.assert_outcomes(passed=2, skipped=0) |