Skip to content

Commit

Permalink
Merge 244f01b into e464c9d
Browse files Browse the repository at this point in the history
  • Loading branch information
mvidalgarcia committed Jul 21, 2020
2 parents e464c9d + 244f01b commit 6090941
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Version master (UNRELEASED)
- Adds announcement configmap configuration to display on the UI.
- Adds Black formatter support.
- Stops exposing unused Invenio-Accounts views.
- Starts up Postgres DB container to run tests for componentes installing reana-db.

Version 0.6.1 (2020-06-09)
--------------------------
Expand Down
31 changes: 30 additions & 1 deletion reana/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,20 @@ def is_component_runnable_example(component):
return False


def does_component_need_db(component):
"""Return whether the component needs DB to run tests.
Useful to determine which components need a Postgres DB container to run the tests.
:param component: standard component name
:type component: str
:return: True/False whether the component needs DB
:rtype: bool
"""
return component in (COMPONENTS_USING_SHARED_MODULE_DB + ["reana-db"])


def construct_workflow_name(example, workflow_engine):
"""Construct suitable workflow name for given REANA example.
Expand Down Expand Up @@ -1923,6 +1937,13 @@ def python_unit_tests(component): # noqa: D301
cmd_activate_venv = "source ~/.virtualenvs/_{}/bin/activate".format(
component
)
if does_component_need_db(component):
run_command(
f"docker stop postgres__{component}\n"
f"docker run --rm --name postgres__{component} -p 5432:5432 "
"-e POSTGRES_PASSWORD=mysecretpassword -d postgres:9.6.2"
)

for cmd in [
"virtualenv ~/.virtualenvs/_{}".format(component),
"{} && which python".format(cmd_activate_venv),
Expand All @@ -1934,10 +1955,18 @@ def python_unit_tests(component): # noqa: D301
" pip install . --upgrade".format(cmd_activate_venv),
"git clean -d -ff -x",
'{} && pip install ".[tests]" --upgrade'.format(cmd_activate_venv),
"{} && python setup.py test".format(cmd_activate_venv),
"{} && {} python setup.py test".format(
cmd_activate_venv,
"REANA_SQLALCHEMY_DATABASE_URI=postgresql+psycopg2://postgres:mysecretpassword@localhost/postgres"
if does_component_need_db(component)
else "",
),
"rm -rf ~/.virtualenvs/_{}".format(component),
]:
run_command(cmd, component)

if does_component_need_db(component):
run_command(f"docker stop postgres__{component}")
else:
msg = (
"Ignoring this component that does not contain"
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
history = open("CHANGES.rst").read()

tests_require = [
"pytest-reana>=0.7.0.dev20200417",
"pytest-reana>=0.7.0.dev20200707",
]

extras_require = {
Expand Down
8 changes: 8 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ def test_is_component_runnable_example():
assert is_component_runnable_example("reana") is False


def test_does_component_need_db():
"""Tests for does_component_need_db()."""
from reana.cli import does_component_need_db

assert does_component_need_db("reana-server")
assert not does_component_need_db("reana")


def test_select_components():
"""Tests for select_components()."""
from reana.cli import (
Expand Down

0 comments on commit 6090941

Please sign in to comment.