Skip to content
Snippets Groups Projects
conftest.py 1.45 KiB
Newer Older
  • Learn to ignore specific revisions
  • import pytest
    
    import aiohttp
    
    from aioresponses import aioresponses
    
    from unittest.mock import AsyncMock
    
    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
    
    
    
    @pytest.fixture
    
    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():
    
    async def factories(populated_db, loop):
    
        real = {}
        for name, klass, table in fact.ALL:
            real[name] = klass
    
        return real