Skip to content

Commit

Permalink
tests: create __reana db schema in app fixture
Browse files Browse the repository at this point in the history
partially addresses reanahub/reana#348
  • Loading branch information
mvidalgarcia committed Jul 10, 2020
1 parent 8236df4 commit 8d68dab
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ The list of contributors in alphabetical order:
- `Diego Rodriguez <https://orcid.org/0000-0003-0649-2002>`_
- `Dinos Kousidis <https://orcid.org/0000-0002-4914-4289>`_
- `Jan Okraska <https://orcid.org/0000-0002-1416-3244>`_
- `Marco Vidal <https://orcid.org/0000-0002-9363-4971>`_
- `Rokas Maciulaitis <https://orcid.org/0000-0003-1064-6967>`_
- `Tibor Simko <https://orcid.org/0000-0001-7202-5803>`_
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Version master (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.

Version 0.6.0 (2019-12-19)
--------------------------
Expand Down
15 changes: 10 additions & 5 deletions pytest_reana/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@

import pkg_resources
import pytest
from kombu import Connection, Exchange, Producer, Queue
from kombu import Connection, Exchange, Queue
from kubernetes import client
from mock import ANY, Mock, patch
from mock import Mock, patch
from reana_commons.consumer import BaseConsumer
from reana_db.models import Base, User, Workflow
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy_utils import create_database, database_exists, drop_database
from sqlalchemy.schema import CreateSchema
from sqlalchemy_utils import create_database, database_exists


@pytest.yield_fixture(scope="module")
Expand Down Expand Up @@ -98,14 +98,19 @@ def create_ninja_turtle()
assert res.status_code == 200
"""
from reana_db.database import Session

engine = create_engine(base_app.config["SQLALCHEMY_DATABASE_URI"])
base_app.session.bind = engine
with base_app.app_context():
if not engine.dialect.has_schema(engine, "__reana"):
engine.execute(CreateSchema("__reana"))
if not database_exists(engine.url):
create_database(engine.url)
Base.metadata.create_all(bind=engine)
yield base_app
drop_database(engine.url)
Session.close() # close hanging connections
Base.metadata.drop_all(bind=engine)


@pytest.fixture()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
'pydocstyle==3.0.0 ; python_version=="2.7"',
"pytest-cache>=1.0,<2.0",
"pytest-cov>=2.8.0,<3.0",
"pytest>=3.8.0,<5.0.0",
"pytest>=4.6.0,<5.0.0",
"reana-commons[kubernetes]>=0.7.0.dev20200203",
"reana-db>=0.7.0.dev20200206",
"swagger_spec_validator>=2.1.0,<3.0",
Expand Down

0 comments on commit 8d68dab

Please sign in to comment.