Пример #1
0
def app():
    app = create_app('config/test.cfg')
    # app.client_session = app_session
    yield app
    client = AsyncIOMotorClient(app.config.MOTOR_URI)
    db = client.get_database()
    client.drop_database(db)
Пример #2
0
async def test_db():
    """Creates a temporary database, sets a TTL index and
    returns a pymongo client.
    """
    client = AsyncIOMotorClient(MONGO_URL)
    client.test_db.secrets.create_index('delete_at', expireAfterSeconds=0)

    yield client.test_db

    client.drop_database('test_db')
    client.close()
Пример #3
0
def db():
    test_db_name = f'test_{DB_NAME}'
    try:
        client = AsyncIOMotorClient(str(MONGODB_URL),
                                    maxPoolSize=MAX_CONNECTIONS_COUNT,
                                    minPoolSize=MIN_CONNECTIONS_COUNT)
        db = client[test_db_name]

        yield db
    finally:
        client.drop_database(test_db_name)
        client.close()
Пример #4
0
# globals
loop = asyncio.get_event_loop()
loop.set_debug(True)

# reconnect?
# mongo = AsyncIOMotorClient('mongodb://0.0.0.0:27017', serverSelectionTimeoutMS=1000)
mongo = AsyncIOMotorClient('mongodb://db:27017', serverSelectionTimeoutMS=5000)
try:
    loop.run_until_complete(mongo.server_info())
    logging.info('connected to mongodb')
except ServerSelectionTimeoutError:
    sys.exit('Cannot connect to mongodb')

db = mongo.test
mongo.drop_database(db)
# loop.run_until_complete(db.jobs.drop())
# loop.run_until_complete(db.devices.drop())

redis = RedisPubSub()
root = resource.Site()
reg = Registrar(loop, root, db)

root.add_resource(('.well-known', 'core'),
                  resource.WKCResource(root.get_resources_as_linkheader))
root.add_resource(('obs', ), reg)
root.add_resource(('test', ), Test())
asyncio.Task(aiocoap.Context.create_server_context(root))

try:
    loop.run_forever()
Пример #5
0
def override_db():
    main.app.dependency_overrides[get_db] = create_fake_db
    yield
    client = AsyncIOMotorClient(DB_SERVER)
    client.drop_database(TEST_DB_NAME)
Пример #6
0
async def fake_db():
    client = AsyncIOMotorClient(DB_SERVER)
    db = client[TEST_DB_NAME]
    yield db
    client.drop_database(TEST_DB_NAME)