diff --git a/reana_workflow_controller/config.py b/reana_workflow_controller/config.py index afb78c55..87aa1046 100644 --- a/reana_workflow_controller/config.py +++ b/reana_workflow_controller/config.py @@ -15,6 +15,8 @@ from reana_workflow_controller.version import __version__ +from reana_db.config import SQLALCHEMY_DATABASE_URI + SQLALCHEMY_TRACK_MODIFICATIONS = False """Track modifications flag.""" diff --git a/reana_workflow_controller/rest/workflows.py b/reana_workflow_controller/rest/workflows.py index f26c198c..e50863a8 100644 --- a/reana_workflow_controller/rest/workflows.py +++ b/reana_workflow_controller/rest/workflows.py @@ -169,7 +169,7 @@ def get_workflows(): # noqa verbose = json.loads(request.args.get("verbose", "false").lower()) block_size = request.args.get("block_size") if not user: - return jsonify({"message": "User {} does not exist".format(user)}), 404 + return jsonify({"message": "User {} does not exist".format(user_uuid)}), 404 workflows = [] for workflow in user.workflows: workflow_response = { diff --git a/run-tests.sh b/run-tests.sh index bd99c029..29964ee5 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -1,16 +1,72 @@ -#!/bin/sh +#!/bin/bash # # This file is part of REANA. -# Copyright (C) 2017, 2018, 2019 CERN. +# Copyright (C) 2017, 2018, 2019, 2020 CERN. # # REANA is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. -pydocstyle reana_workflow_controller && \ -black --check . && \ -FLASK_APP=reana_workflow_controller/app.py python ./scripts/generate_openapi_spec.py && \ -diff -q -w temp_openapi.json docs/openapi.json && \ -check-manifest --ignore ".travis-*" && \ -sphinx-build -qnN docs docs/_build/html && \ -python setup.py test && \ +# Quit on errors +set -o errexit + +# Quit on unbound symbols +set -o nounset + +export REANA_SQLALCHEMY_DATABASE_URI=postgresql+psycopg2://postgres:mysecretpassword@localhost/postgres + +# Verify that db container is running before continuing +_check_ready() { + RETRIES=40 + while ! $2 + do + echo "==> [INFO] Waiting for $1, $((RETRIES--)) remaining attempts..." + sleep 2 + if [ $RETRIES -eq 0 ] + then + echo "==> [ERROR] Couldn't reach $1" + exit 1 + fi + done +} + +_db_check() { + docker exec --user postgres reana-postgres bash -c "pg_isready" &>/dev/null; +} + +clean_old_db_container() { + OLD="$(docker ps --all --quiet --filter=name=reana-postgres)" + if [ -n "$OLD" ]; then + echo '==> [INFO] Cleaning old DB container...' + docker stop reana-postgres + fi +} + +start_db_container() { + echo '==> [INFO] Starting DB container...' + docker run --rm --name reana-postgres -p 5432:5432 -e POSTGRES_PASSWORD=mysecretpassword -d postgres:9.6.2 + _check_ready "Postgres" _db_check +} + +stop_db_container() { + echo '==> [INFO] Stopping DB container...' + docker stop reana-postgres +} + +check_black() { + echo '==> [INFO] Checking Black compliance...' + black --check . +} + +pydocstyle reana_workflow_controller +check_black +FLASK_APP=reana_workflow_controller/app.py python ./scripts/generate_openapi_spec.py +diff -q -w temp_openapi.json docs/openapi.json +check-manifest --ignore ".travis-*" +sphinx-build -qnNW docs docs/_build/html +clean_old_db_container +start_db_container +python setup.py test +stop_db_container +sphinx-build -qnNW -b doctest docs docs/_build/doctest docker build -t reanahub/reana-workflow-controller . +echo '==> [INFO] All tests passed! ✅' diff --git a/setup.py b/setup.py index 49bc318a..f6fa9b95 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ history = open("CHANGES.rst").read() tests_require = [ - "pytest-reana>=0.7.0.dev20191219,<0.8.0", + "pytest-reana>=0.7.0.dev20200707,<0.8.0", ] extras_require = { diff --git a/tests/conftest.py b/tests/conftest.py index eead3412..4babf46f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -29,11 +29,11 @@ def base_app(tmp_shared_volume_path): "SECRET_KEY": "SECRET_KEY", "TESTING": True, "SHARED_VOLUME_PATH": tmp_shared_volume_path, - "SQLALCHEMY_DATABASE_URI": "sqlite:///testdb.db", "SQLALCHEMY_TRACK_MODIFICATIONS": False, + "FLASK_ENV": "development", "ORGANIZATIONS": ["default"], } - app_ = create_app(config_mapping) + app_ = create_app(config_mapping=config_mapping) return app_ diff --git a/tests/test_utils.py b/tests/test_utils.py index 9cc7fa20..b88ac43c 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -119,6 +119,7 @@ def test_workspace_deletion( workflow_job = Job(id_=uuid.uuid4(), workflow_uuid=workflow.id_) job_cache_entry = JobCache(job_id=workflow_job.id_) session.add(workflow_job) + session.commit() session.add(job_cache_entry) session.commit() diff --git a/tests/test_views.py b/tests/test_views.py index ad7fa5b3..6fd5653a 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -1097,6 +1097,7 @@ def test_workspace_deletion( workflow_job = Job(id_=uuid.uuid4(), workflow_uuid=workflow.id_) job_cache_entry = JobCache(job_id=workflow_job.id_) session.add(workflow_job) + session.commit() session.add(job_cache_entry) session.commit()