# Path: gengine/metadata.py
# def init_session(override_session=None, replace=False):
#     global DBSession
#     if DBSession.target and not replace:
#         return
#     if override_session:
#         DBSession.target = override_session
#     else:
#         DBSession.target = scoped_session(get_sessionmaker())
# 
# def get_sessionmaker(bind=None):
#     return sessionmaker(
#         extension=ZopeTransactionExtension(),
#         class_=MySession,
#         bind=bind
#     )
# 
# Path: gengine/app/tests/db.py
# def setupDB():
# def unsetupDB():


import unittest
import os
from sqlalchemy.engine import create_engine
from sqlalchemy.sql.schema import Table
from sqlalchemy.orm.scoping import scoped_session
from gengine.metadata import init_session, get_sessionmaker
from gengine.app.tests import db
        from gengine.app.cache import clear_all_caches
        from gengine.metadata import Base
        from alembic.config import Config
        from alembic import command
        from gengine.app import model
                "host": dsn["host"],
                "port": dsn["port"],
                "database": dsn["database"],
            }
        )
        init_session(override_session=scoped_session(get_sessionmaker(bind=self.engine)), replace=True)
        Base.metadata.bind = self.engine

        Base.metadata.drop_all(self.engine)
        self.engine.execute("DROP SCHEMA IF EXISTS public CASCADE")
        self.engine.execute("CREATE SCHEMA IF NOT EXISTS public")


        alembic_cfg = Config(attributes={
            'engine': self.engine,
            'schema': 'public'
        })
        script_location = os.path.join(
            os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))),
            'app/alembic'
        )
        alembic_cfg.set_main_option("script_location", script_location)


        tables = [t for name, t in model.__dict__.items() if isinstance(t, Table)]
        Base.metadata.create_all(self.engine, tables=tables)

        command.stamp(alembic_cfg, "head")

    def tearDown(self):

# Path: gengine/metadata.py
# def init_session(override_session=None, replace=False):
#     global DBSession
#     if DBSession.target and not replace:
#         return
#     if override_session:
#         DBSession.target = override_session
#     else:
#         DBSession.target = scoped_session(get_sessionmaker())
# 
# def get_sessionmaker(bind=None):
#     return sessionmaker(
#         extension=ZopeTransactionExtension(),
#         class_=MySession,
#         bind=bind
#     )
# 
# Path: gengine/app/tests/db.py
# def setupDB():
# def unsetupDB():


# Path: gengine/app/tests_old/base.py
import unittest
import os
from sqlalchemy.engine import create_engine
from sqlalchemy.sql.schema import Table
from sqlalchemy.orm.scoping import scoped_session
from gengine.metadata import init_session, get_sessionmaker
from gengine.app.tests import db
        from gengine.app.cache import clear_all_caches
        from gengine.metadata import Base
        from alembic.config import Config
        from alembic import command
        from gengine.app import model

                "host": dsn["host"],
                "port": dsn["port"],
                "database": dsn["database"],
            }
        )
        init_session(override_session=scoped_session(get_sessionmaker(bind=self.engine)), replace=True)
        Base.metadata.bind = self.engine

        Base.metadata.drop_all(self.engine)
        self.engine.execute("DROP SCHEMA IF EXISTS public CASCADE")
        self.engine.execute("CREATE SCHEMA IF NOT EXISTS public")


        alembic_cfg = Config(attributes={
            'engine': self.engine,
            'schema': 'public'
        })
        script_location = os.path.join(
            os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))),
            'app/alembic'
        )
        alembic_cfg.set_main_option("script_location", script_location)


        tables = [t for name, t in model.__dict__.items() if isinstance(t, Table)]
        Base.metadata.create_all(self.engine, tables=tables)

        command.stamp(alembic_cfg, "head")

    def tearDown(self):

        self.db.stop()