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 7, 2020
1 parent 8236df4 commit cda22fd
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 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 @@ -101,11 +101,13 @@ def create_ninja_turtle()
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)
Base.metadata.drop_all(bind=engine)


@pytest.fixture()
Expand Down

0 comments on commit cda22fd

Please sign in to comment.