import asyncio import datetime import pytest from server import config from server.app import create_app from server.db.session import metadata, engine @pytest.fixture async def db_session(client): async with engine.begin() as conn: await conn.run_sync(metadata.drop_all) await conn.run_sync(metadata.create_all) yield async with engine.begin() as conn: await conn.run_sync(metadata.drop_all) await engine.dispose() @pytest.fixture(scope="session") def event_loop(): loop = asyncio.get_event_loop() yield loop loop.close() @pytest.fixture def auth(): return {"Authorization": config.AUTH_API_KEY} @pytest.fixture def client(loop, aiohttp_client): app = create_app() return loop.run_until_complete(aiohttp_client(app)) @pytest.fixture def patch_datetime_now(monkeypatch): """Patching datetime now for tests.""" fake_datetime = datetime.datetime(2022, 6, 20, 10, 0, 0) class PatchedDatetime(datetime.datetime): @classmethod def now(cls): return fake_datetime monkeypatch.setattr("server.api.users.feed.datetime", PatchedDatetime)