Esempio n. 1
0
async def test_pool_by_dsn(event_loop):
    """ test creation using DSN """
    pool = AsyncPool(DRIVER, dsn=DSN, loop=event_loop)
    pytest.assume(pool.is_connected() is False)
    await pool.connect()
    pytest.assume(pool.is_connected() is True)
    db = await pool.acquire()
    result, error = await db.test_connection('helloworld')
    pytest.assume(not error)
    pytest.assume(result == 'helloworld')
    user = {
        "Name": "Pradeep",
        "Company": "SCTL",
        "Address": "Mumbai",
        "Location": "RCP",
    }
    await db.set_hash("user", user)
    pytest.assume(await db.exists("user") == 1)
    result = await db.get_hash("user")
    # print(result, await db.exists("user"))
    pytest.assume(result["Name"] == "Pradeep")
    await db.delete("user")
    pytest.assume(await db.exists("user") == 0)
    await pool.close()
    assert pool.is_closed() is True
Esempio n. 2
0
async def test_pool_by_dsn(event_loop):
    """ test creation using DSN """
    pool = AsyncPool(DRIVER, dsn=DSN, loop=event_loop)
    pytest.assume(pool.is_connected() is False)
    await pool.connect()
    pytest.assume(pool.is_connected() is True)
    db = await pool.acquire()
    result, error = await db.test_connection('helloworld')
    pytest.assume(not error)
    pytest.assume(result == 'helloworld')
    await pool.close()
    assert pool.is_closed() is True
Esempio n. 3
0
async def test_many(event_loop):
    pool = AsyncPool(DRIVER, dsn=DSN, loop=event_loop)
    pytest.assume(pool.is_connected() is False)
    await pool.connect()
    pytest.assume(pool.is_connected() is True)
    for lp in range(10000):
        print(f'Test number {lp}')
        async with await pool.acquire() as cnt:
            await cnt.ping()
            await cnt.execute("set", "Test1", "UltraTest")
            result = await cnt.get('Test1')
            pytest.assume(result == "UltraTest")
            await cnt.delete("Test1")
    print('Ending ...')
Esempio n. 4
0
async def test_pool_connect(event_loop):
    pool = AsyncPool("pg", params=PARAMS, loop=event_loop)
    pytest.assume(pool.application_name == 'Navigator')
    await pool.connect()
    pytest.assume(pool.is_connected() == True)
    db = await pool.acquire()
    pytest.assume(db.is_connected() == True)
    result = await pool.execute("SELECT 1")
    pytest.assume(result == 'SELECT 1')
    result, error = await db.test_connection()
    row = result[0]
    pytest.assume(row[0] == 1)
    await pool.release(connection=db)
Esempio n. 5
0
loop.set_exception_handler(default_exception_handler)

params = {
    "user": "******",
    "password": "******",
    "host": "127.0.0.1",
    "port": "5432",
    "database": "navigator_dev",
    "DEBUG": True,
}

pool = AsyncPool('pg', loop=loop, params=params)
loop.run_until_complete(pool.connect())
db = loop.run_until_complete(pool.acquire())

print('Pool Connected: ', pool.is_connected())
db = loop.run_until_complete(pool.acquire())
print('Is Connected: ', db.is_connected())
loop.run_until_complete(db.test_connection())

try:
    print('CREATION of MODEL::')
    mdl = QueryUtil(**{"query_slug": "walmart_stores"})
    mdl.Meta.set_connection(db)
    result = loop.run_until_complete(mdl.fetch(raw_query=False))
    print('RESULT IS: ', result)

    mdl = QueryUtil(**{"program_slug": "walmart", "provider": "db"})
    mdl.Meta.set_connection(loop.run_until_complete(pool.acquire()))
    result = loop.run_until_complete(mdl.select())
    for row in result:
Esempio n. 6
0
async def test_pool_by_params(event_loop):
    pool = AsyncPool(DRIVER, params=params, loop=event_loop)
    pytest.assume(pool.is_connected() is False)
    await pool.connect()
    pytest.assume(pool.is_connected() is True)
    await pool.close()
Esempio n. 7
0
        "Location": "RCP",
    }
    await conn.set_hash("user", user)
    if await conn.exists("user"):
        print(await conn.get_hash("user"))
        await conn.delete("user")
    for lp in range(10000):
        print(f'Test number {lp}')
        async with await rd.acquire() as conn:
            await conn.ping()
            await conn.execute("set", "Test1", "UltraTest")
            await conn.delete("Test1")
    print('Ending ...')


try:
    print("Connected: {}".format(rd.is_connected()))
    with rd as conn:
        loop.run_until_complete(conn.execute("set", "my-key", "UltraValue"))
        value = loop.run_until_complete(conn.execute("get", "my-key"))
        print("raw value:", value)
    # adquire a new connection (with pool)
    r = loop.run_until_complete(rd.acquire())
    loop.run_until_complete(r.execute("set", "my-key", "UltraKey"))
    value = loop.run_until_complete(r.execute("get", "my-key"))
    print("new value:", value)
    loop.run_until_complete(test_redis(r))
finally:
    loop.run_until_complete(rd.close())
    loop.close()