Skip to content

Commit

Permalink
fixtures: SHARED_VOLUME_PATH through env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego Rodriguez committed Oct 13, 2020
1 parent 02b58f3 commit 4be38bb
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 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 @@ -431,38 +436,35 @@ def sample_workflow_workspace(tmp_shared_volume_path):
the ``tests/test_workspace`` directory.
"""

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,13 +474,16 @@ 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(),
name="sample_serial_workflow_1",
Expand All @@ -487,6 +492,7 @@ def sample_serial_workflow_in_db(app, default_user, session, serial_workflow):
operational_options={},
type_=serial_workflow["reana_specification"]["workflow"]["type"],
logs="",
workspace_path=relative_workspace_path,
)
session.add(workflow)
session.commit()
Expand Down

0 comments on commit 4be38bb

Please sign in to comment.