Newer
Older
import aiopg
from aioresponses import aioresponses
from unittest.mock import AsyncMock
from funkwhale_network.db import DB
from funkwhale_network import server
from funkwhale_network import settings
from . import factories as fact
pytest_plugins = "aiohttp.pytest_plugin"
@pytest.fixture
def client(loop, aiohttp_client, populated_db, db_pool):
app = aiohttp.web.Application(middlewares=settings.MIDDLEWARES)
server.prepare_app(app, pool=db_pool)
yield loop.run_until_complete(aiohttp_client(app))
@pytest.fixture
async def db_pool(loop):
await db.create_pool()
async def populated_db(loop):
async with DB() as db:
await db.create()
yield db.get_cursor()
await db.clear()
@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
@pytest.fixture
def responses():
with aioresponses() as m:
yield m
@pytest.fixture
async def session(loop):
async with aiohttp.ClientSession() as session:
yield session
@pytest.fixture
async def coroutine_mock():
return AsyncMock
@pytest.fixture
async def factories(populated_db, loop):
real = {}
for name, klass, table in fact.ALL:
real[name] = klass
return real