Newer
Older
import aiohttp
from aioresponses import aioresponses
import funkwhale_network
from funkwhale_network import db
pytest_plugins = "aiohttp.pytest_plugin"
@pytest.fixture
def client(loop, aiohttp_client, populated_db, db_pool):
app = aiohttp.web.Application(middlewares=funkwhale_network.MIDDLEWARES)
funkwhale_network.prepare_app(app, pool=db_pool)
yield loop.run_until_complete(aiohttp_client(app))
@pytest.fixture
def config(loop):
return {
"db_dsn": os.environ.get(
"DB_DSN",
"user=postgres password=postgres dbname=funkwhale_network_test host=127.0.0.1",
)
}
@pytest.fixture
async def db_pool(config):
pool = await db.get_pool(config["db_dsn"])
yield pool
pool.close()
await pool.wait_closed()
@pytest.fixture
async def populated_db(db_pool):
async with db_pool.acquire() as conn:
await db.create(conn)
yield conn
await db.clear(conn)
@pytest.fixture
async def db_conn(db_pool):
async with db_pool.acquire() as conn:
yield conn
@pytest.fixture
async def db_cursor(db_conn):
async with db_conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor) as cursor:
yield cursor