Skip to content

Commit

Permalink
#47 Calling backend tests indirectly
Browse files Browse the repository at this point in the history
  • Loading branch information
ahsimb committed Aug 20, 2024
1 parent 22e25de commit b68fa23
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 70 deletions.
4 changes: 0 additions & 4 deletions pytest-backend/noxconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
)

from nox import Session
from exasol.pytest_backend import (BACKEND_OPTION, BACKEND_ONPREM, BACKEND_SAAS)


@dataclass(frozen=True)
Expand All @@ -27,9 +26,6 @@ def pre_integration_tests_hook(
_session: Session, _config: Config, _context: MutableMapping[str, Any]
) -> bool:
"""Implement if project specific behaviour is required"""
fwd_args = _context.get('fwd-args', [])
fwd_args.extend([BACKEND_OPTION, BACKEND_ONPREM, BACKEND_OPTION, BACKEND_SAAS])
_context['fwd-args'] = fwd_args
return True

@staticmethod
Expand Down
91 changes: 25 additions & 66 deletions pytest-backend/test/integration/pytest_backend_test.py
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)

0 comments on commit b68fa23

Please sign in to comment.