-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fixtures: shared volume path through env variable #66
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ | |
from kubernetes import client | ||
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 | ||
|
@@ -48,9 +48,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() | ||
|
@@ -99,6 +103,7 @@ def create_ninja_turtle() | |
|
||
""" | ||
from reana_db.database import Session | ||
from reana_db.models import Base | ||
|
||
engine = create_engine(base_app.config["SQLALCHEMY_DATABASE_URI"]) | ||
base_app.session.bind = engine | ||
|
@@ -134,6 +139,8 @@ def test_default_user_exists(default) | |
|
||
|
||
""" | ||
from reana_db.models import User | ||
|
||
default_user_id = "00000000-0000-0000-0000-000000000000" | ||
user = User.query.filter_by(id_=default_user_id).first() | ||
if not user: | ||
|
@@ -432,37 +439,39 @@ 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. | ||
""" | ||
from reana_db.models import Workflow | ||
|
||
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() | ||
|
@@ -472,21 +481,29 @@ 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. | ||
""" | ||
from reana_db.models import Workflow | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved REANA-DB imports form global scope to the fixtures to make REANA-Client pass on Python2.7 builds, currently failing because of this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you're missing |
||
|
||
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() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,4 @@ | |
|
||
from __future__ import absolute_import, print_function | ||
|
||
__version__ = "0.7.0a1" | ||
__version__ = "0.8.0a1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See how this is being used in reanahub/reana-workflow-controller#338 (this line).