Ejemplo n.º 1
0
def app(request):
    """Yield the application instance."""
    database = getattr(request.module, 'database', 'db.sqlite3')
    read_only = getattr(request.module, 'read_only', False)
    exclude_tables = getattr(request.module, 'exclude_tables', None)
    test_database_path = os.path.join('tests', 'data', 'test_db.sqlite3')
    pristine_database_path = os.path.join('tests', 'data', database)

    shutil.copy(pristine_database_path, test_database_path)

    model_module = getattr(request.module, 'model_module', None)
    user_models = []
    if model_module:
        module = importlib.import_module(model_module)
        for name, obj in inspect.getmembers(module):
            if inspect.isclass(obj):
                if name not in ('Model', 'AutomapModel'):
                    user_models.append(obj)

    application = create_app(
        'sqlite+pysqlite:///{}'.format(
            test_database_path),
        include_models=user_models,
        exclude_tables=exclude_tables,
        read_only=read_only)
    application.testing = True

    yield application

    with application.app_context():
        db.session.remove()
        db.drop_all()
    os.unlink(test_database_path)
Ejemplo n.º 2
0
def main(parser=parser):
    """Main entry point for script."""
    args = parser.parse_args()
    app = create_app(args.URI, read_only=args.read_only, schema=args.schema)
    if args.enable_cors:
        from flask_cors import CORS
        CORS(app)
    if args.debug:
        app.config['DEBUG'] = True
    if args.local_only:
        host = '127.0.0.1'
    else:
        host = '0.0.0.0'
    app.config['SECRET_KEY'] = '42'
    app.run(host=host, port=int(args.port))
Ejemplo n.º 3
0
from flask_sandman import create_app

app = create_app('sqlite+pysqlite:///tests/data/db.sqlite3')


def main():
    app.run(debug=True)


if __name__ == '__main__':
    main()
Ejemplo n.º 4
0
from user_models import User, Blog, Post
from flask_sandman import create_app

app = create_app('sqlite+pysqlite:///blog.sqlite3',
                 include_models=[User, Blog, Post])

if __name__ == '__main__':
    app.run(debug=True)
Ejemplo n.º 5
0
from flask_sandman import create_app

app = create_app('sqlite+pysqlite:///db.sqlite3')

if __name__ == '__main__':
    app.run(debug=True)