Skip to content

Commit

Permalink
#18: Implemented keep alive for saas-database (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
ckunki authored Jun 3, 2024
1 parent 7e74fd8 commit d727175
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
8 changes: 8 additions & 0 deletions pytest-saas/doc/changes/unreleased.md
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
# Unreleased

## Feature

* #18: Implemented keep alive for saas-database

## Bugfixes

* #19: Fixed removing ip whitelist rule at the end of the test session
15 changes: 8 additions & 7 deletions pytest-saas/exasol/pytest_saas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@

def pytest_addoption(parser):
parser.addoption(
f"--saas-database-id",
"--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",
"--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",
"--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
Expand Down Expand Up @@ -86,16 +86,17 @@ def saas_database(
will not be operational. The startup takes about 20 minutes.
"""
db_id = request.config.getoption("--saas-database-id")
keep = request.config.getoption("--keep-saas-database")
if db_id:
yield api_access.get_database(db_id)
return
with api_access.database(database_name) as db:
with api_access.database(database_name, keep) 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
with api_access.allowed_ip():
api_access.wait_until_running(db.id)
yield db.id
24 changes: 22 additions & 2 deletions pytest-saas/test/integration/pytest_saas_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_id_of_existing_database(request, pytester, capsys):
because that there is no database with the specified ID.
"""
testname = request.node.name
pytester.makepyfile(** _testfile( f"""
pytester.makepyfile(** _testfile(f"""
def {testname}(saas_database):
pass
"""))
Expand All @@ -124,9 +124,29 @@ def {testname}(saas_database):
@pytest.mark.slow
def test_operational_database(request, pytester):
testname = request.node.name
pytester.makepyfile(** _testfile( f"""
pytester.makepyfile(** _testfile(f"""
def {testname}(operational_saas_database_id):
assert operational_saas_database_id is not None
"""))
result = pytester.runpytest()
assert result.ret == pytest.ExitCode.OK


def test_keep_database(request, pytester, api_access, capsys):
testname = request.node.name
pytester.makepyfile(** _testfile(f"""
def {testname}(saas_database):
db = saas_database
print(f"\\ndatabase-id: {{db.id}}")
"""))
id = None
try:
result = pytester.runpytest("--keep-saas-database", "-s")
assert result.ret == pytest.ExitCode.OK
captured = capsys.readouterr()
for line in captured.out.splitlines():
if line.startswith("database-id: "):
id = line.split()[1]
finally:
if id:
api_access.delete_database(id)

0 comments on commit d727175

Please sign in to comment.