# Path: recruit_app/app.py
# def create_app(config_object=ProdConfig):
#     '''An application factory, as explained here:
#         http://flask.pocoo.org/docs/patterns/appfactories/
# 
#     :param config_object: The configuration object to use.
#     '''
#     app = Flask(__name__)
#     app.config.from_object(config_object)
#     register_extensions(app)
#     register_blueprints(app)
#     register_errorhandlers(app)
#     admin = Admin()
#     register_admin(admin, db)
#     # register_search(app)
#     admin.init_app(app)
#     # admin needs to be initialized oddly for tests to work.
#     register_tasks()
# 
#     return app
# 
# Path: recruit_app/database.py
# class CRUDMixin(object):
# class Model(CRUDMixin, db.Model):
# class SurrogatePK(object):
# class TimeMixin(object):
#     def create(cls, **kwargs):
#     def update(self, commit=True, **kwargs):
#     def save(self, commit=True):
#     def delete(self, commit=True):
#     def get_by_id(cls, id):
# def ReferenceCol(tablename, nullable=True, pk_name='id', **kwargs):
# 
# Path: recruit_app/settings.py
# class TestConfig(Config):
#     ENV = 'test'
#     TESTING = True
#     DEBUG = True
#     BCRYPT_LOG_ROUNDS = 1  # For faster tests
#     WTF_CSRF_ENABLED = False  # Allows form testing
#     ASSETS_DEBUG = True
#     CACHE_TYPE = 'redis'
#     SQLALCHEMY_DATABASE_URI = os_env.get('TEST_DATABASE_URL', 'postgresql://recruit@localhost:5432/recruit')
# 
# Path: tests/factories.py
# class UserFactory(BaseFactory):
#     """User factory."""
# 
#     email = Sequence(lambda n: 'user{0}@example.com'.format(n))
#     password = PostGenerationMethodCall('set_password', 'example')
#     active = True
# 
#     class Meta:
#         """Factory configuration."""
# 
#         model = User


import pytest
from webtest import TestApp
from sqlalchemy.engine import reflection
from sqlalchemy.schema import (
    MetaData,
    Table,
    DropTable,
    ForeignKeyConstraint,
    DropConstraint,
    )
from recruit_app.app import create_app
from recruit_app.database import db as _db
from recruit_app.settings import TestConfig
from .factories import UserFactory

    for table_name in inspector.get_table_names():
        fks = []
        for fk in inspector.get_foreign_keys(table_name):
            if not fk['name']:
                continue
            fks.append(
                ForeignKeyConstraint((), (), name=fk['name'])
                )
        t = Table(table_name, metadata, *fks)
        tbs.append(t)
        all_fks.extend(fks)

    for fkc in all_fks:
        db.engine.execute(DropConstraint(fkc))

    for table in tbs:
        db.engine.execute(DropTable(table))


@pytest.yield_fixture(scope='function')
def db(app):
    """A database for the tests."""
    _db.app = app
    with app.app_context():
        _db.create_all()

    yield _db

    # Explicitly close DB connection

# Path: recruit_app/app.py
# def create_app(config_object=ProdConfig):
#     '''An application factory, as explained here:
#         http://flask.pocoo.org/docs/patterns/appfactories/
# 
#     :param config_object: The configuration object to use.
#     '''
#     app = Flask(__name__)
#     app.config.from_object(config_object)
#     register_extensions(app)
#     register_blueprints(app)
#     register_errorhandlers(app)
#     admin = Admin()
#     register_admin(admin, db)
#     # register_search(app)
#     admin.init_app(app)
#     # admin needs to be initialized oddly for tests to work.
#     register_tasks()
# 
#     return app
# 
# Path: recruit_app/database.py
# class CRUDMixin(object):
# class Model(CRUDMixin, db.Model):
# class SurrogatePK(object):
# class TimeMixin(object):
#     def create(cls, **kwargs):
#     def update(self, commit=True, **kwargs):
#     def save(self, commit=True):
#     def delete(self, commit=True):
#     def get_by_id(cls, id):
# def ReferenceCol(tablename, nullable=True, pk_name='id', **kwargs):
# 
# Path: recruit_app/settings.py
# class TestConfig(Config):
#     ENV = 'test'
#     TESTING = True
#     DEBUG = True
#     BCRYPT_LOG_ROUNDS = 1  # For faster tests
#     WTF_CSRF_ENABLED = False  # Allows form testing
#     ASSETS_DEBUG = True
#     CACHE_TYPE = 'redis'
#     SQLALCHEMY_DATABASE_URI = os_env.get('TEST_DATABASE_URL', 'postgresql://recruit@localhost:5432/recruit')
# 
# Path: tests/factories.py
# class UserFactory(BaseFactory):
#     """User factory."""
# 
#     email = Sequence(lambda n: 'user{0}@example.com'.format(n))
#     password = PostGenerationMethodCall('set_password', 'example')
#     active = True
# 
#     class Meta:
#         """Factory configuration."""
# 
#         model = User


# Path: tests/conftest.py
import pytest
from webtest import TestApp
from sqlalchemy.engine import reflection
from sqlalchemy.schema import (
    MetaData,
    Table,
    DropTable,
    ForeignKeyConstraint,
    DropConstraint,
    )
from recruit_app.app import create_app
from recruit_app.database import db as _db
from recruit_app.settings import TestConfig
from .factories import UserFactory


    for table_name in inspector.get_table_names():
        fks = []
        for fk in inspector.get_foreign_keys(table_name):
            if not fk['name']:
                continue
            fks.append(
                ForeignKeyConstraint((), (), name=fk['name'])
                )
        t = Table(table_name, metadata, *fks)
        tbs.append(t)
        all_fks.extend(fks)

    for fkc in all_fks:
        db.engine.execute(DropConstraint(fkc))

    for table in tbs:
        db.engine.execute(DropTable(table))


@pytest.yield_fixture(scope='function')
def db(app):
    """A database for the tests."""
    _db.app = app
    with app.app_context():
        _db.create_all()

    yield _db

    # Explicitly close DB connection

    _db.session.close()