Skip to content

Commit

Permalink
Merge 801c73a into 02b58f3
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego committed Oct 13, 2020
2 parents 02b58f3 + 801c73a commit af5b559
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 19 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Changes
Version master (UNRELEASED)
---------------------------

- Makes the `tmp_shared_volume_path` configurable through environment variable.
- Creates empty workflow workspaces for sample workflows by default.

Version 0.7.0 (UNRELEASED)
---------------------------

- Fixes `bug related to duplicated database session <https://github.com/reanahub/pytest-reana/issues/33>`_.
- Add Black formatter support.
- Create ``__reana`` database schema for ``db`` fixture.
Expand Down
47 changes: 29 additions & 18 deletions pytest_reana/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from mock import Mock, patch
from reana_commons.consumer import BaseConsumer
from reana_db.models import Base, User, Workflow
from reana_db.utils import build_workspace_path
from sqlalchemy import create_engine
from sqlalchemy.schema import CreateSchema
from sqlalchemy_utils import create_database, database_exists
Expand All @@ -48,9 +49,13 @@ def test_dir_exists(tmp_shared_volume_path):
assert os.path.exists(path)
"""
temp_path = str(tmpdir_factory.mktemp("reana"))
yield temp_path
shutil.rmtree(temp_path)
shared_volume_path = os.getenv("SHARED_VOLUME_PATH", "")
temp_path = None
if not os.path.exists(shared_volume_path):
temp_path = str(tmpdir_factory.mktemp("reana"))
yield temp_path or shared_volume_path
if temp_path:
shutil.rmtree(temp_path)


@pytest.fixture()
Expand Down Expand Up @@ -432,37 +437,37 @@ def sample_workflow_workspace(tmp_shared_volume_path):
"""

def _create_sample_workflow_workspace(workflow_id):
test_workspace_path = pkg_resources.resource_filename(
"pytest_reana", "test_workspace"
)
sample_workspace_path = os.path.join(tmp_shared_volume_path, str(workflow_id))
if not os.path.exists(sample_workspace_path):
shutil.copytree(test_workspace_path, sample_workspace_path)
yield sample_workspace_path
shutil.rmtree(test_workspace_path, sample_workspace_path)
else:
yield sample_workspace_path
def _create_sample_workflow_workspace(relative_workspace_path):
empty_workspace = os.path.join(tmp_shared_volume_path, relative_workspace_path)
if not os.path.exists(empty_workspace):
os.makedirs(empty_workspace)
yield empty_workspace

return _create_sample_workflow_workspace


@pytest.fixture()
def sample_yadage_workflow_in_db(app, default_user, session, yadage_workflow_with_name):
def sample_yadage_workflow_in_db(
app, default_user, session, yadage_workflow_with_name, sample_workflow_workspace
):
"""Create a sample workflow in the database.
Scope: function
Adds a sample yadage workflow in the DB.
"""
workflow_id = uuid4()
relative_workspace_path = build_workspace_path(default_user.id_, workflow_id)
next(sample_workflow_workspace(relative_workspace_path))
workflow = Workflow(
id_=uuid4(),
id_=workflow_id,
name="sample_serial_workflow_1",
owner_id=default_user.id_,
reana_specification=yadage_workflow_with_name["reana_specification"],
operational_options={},
type_=yadage_workflow_with_name["reana_specification"]["workflow"]["type"],
logs="",
workspace_path=relative_workspace_path,
)
session.add(workflow)
session.commit()
Expand All @@ -472,21 +477,27 @@ def sample_yadage_workflow_in_db(app, default_user, session, yadage_workflow_wit


@pytest.fixture()
def sample_serial_workflow_in_db(app, default_user, session, serial_workflow):
def sample_serial_workflow_in_db(
app, default_user, session, serial_workflow, sample_workflow_workspace
):
"""Create a sample workflow in the database.
Scope: function
Adds a sample serial workflow in the DB.
"""
workflow_id = uuid4()
relative_workspace_path = build_workspace_path(default_user.id_, workflow_id)
next(sample_workflow_workspace(relative_workspace_path))
workflow = Workflow(
id_=uuid4(),
id_=workflow_id,
name="sample_serial_workflow_1",
owner_id=default_user.id_,
reana_specification=serial_workflow["reana_specification"],
operational_options={},
type_=serial_workflow["reana_specification"]["workflow"]["type"],
logs="",
workspace_path=relative_workspace_path,
)
session.add(workflow)
session.commit()
Expand Down
2 changes: 1 addition & 1 deletion pytest_reana/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@

from __future__ import absolute_import, print_function

__version__ = "0.7.0a1"
__version__ = "0.7.0a2"

0 comments on commit af5b559

Please sign in to comment.