Esempio n. 1
0
def pytest_configure(config):
    # Create a new event loop
    # as the pytest's loop is not created
    loop = uvloop.new_event_loop()
    ssl_ctx = None
    DB_CERT = environ.get("DB_CERT")
    if DB_CERT:
        ssl_ctx = ssl.create_default_context(cafile=DB_CERT)

    if ssl_ctx:
        loop.run_until_complete(db.set_bind(get_db_url(), ssl=ssl_ctx))
    else:
        loop.run_until_complete(db.set_bind(get_db_url()))
    loop.run_until_complete(db.gino.create_all())
Esempio n. 2
0
async def reset_db():
    await db.set_bind(get_db_url())

    # Clear the DB
    await db.status(
        db.text("""TRUNCATE "organisation" RESTART IDENTITY CASCADE;"""))
    await db.status(db.text("""TRUNCATE "visitor" RESTART IDENTITY CASCADE;""")
                    )
    await db.status(db.text("""TRUNCATE "chat" RESTART IDENTITY CASCADE;"""))
    await db.status(
        db.text("""TRUNCATE "chat_message" RESTART IDENTITY CASCADE;"""))
    await db.status(
        db.text("""TRUNCATE "bookmark_visitor" RESTART IDENTITY CASCADE;"""))
    await db.status(
        db.text("""TRUNCATE "chat_unclaimed" RESTART IDENTITY CASCADE;"""))

    # Re-setup the db
    await setup_db()
Esempio n. 3
0
def run_migrations_offline():
    """Run migrations in 'offline' mode.

    This configures the context with just a URL
    and not an Engine, though an Engine is acceptable
    here as well.  By skipping the Engine creation
    we don't even need a DBAPI to be available.

    Calls to context.execute() here emit the given string to the
    script output.

    """
    # url = config.get_main_option("sqlalchemy.url")
    url = get_db_url()

    context.configure(url=url,
                      target_metadata=target_metadata,
                      literal_binds=True)

    with context.begin_transaction():
        context.run_migrations()
Esempio n. 4
0
# This line sets up loggers basically.
fileConfig(config.config_file_name)

# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
# target_metadata = None
target_metadata = db

# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.

config.set_main_option("sqlalchemy.url", get_db_url())


def run_migrations_offline():
    """Run migrations in 'offline' mode.

    This configures the context with just a URL
    and not an Engine, though an Engine is acceptable
    here as well.  By skipping the Engine creation
    we don't even need a DBAPI to be available.

    Calls to context.execute() here emit the given string to the
    script output.

    """
    # url = config.get_main_option("sqlalchemy.url")
Esempio n. 5
0
    # Register the visitors
    for visitor in _visitors:
        _visitor = deepcopy(visitor)

        # Anonymous users don't have passwords
        if "password" in _visitor:
            _visitor["password"] = hash_password(_visitor["password"])
        await Visitor(**_visitor).create()


if __name__ == "__main__":
    import asyncio
    import uvloop

    from ora_backend.config.db import get_db_url

    ssl_ctx = None
    DB_CERT = environ.get("DB_CERT")
    if DB_CERT:
        ssl_ctx = ssl.create_default_context(cafile=DB_CERT)

    loop = uvloop.new_event_loop()
    asyncio.set_event_loop(loop)
    if ssl_ctx:
        loop.run_until_complete(db.set_bind(get_db_url(), ssl=ssl_ctx))
    else:
        loop.run_until_complete(db.set_bind(get_db_url()))
    loop.run_until_complete(db.gino.create_all())
    loop.run_until_complete(setup_db())