import asyncio import pytest import config from app import create_app from server.core.cache.backends import mongodb, redis @pytest.fixture def client(loop, aiohttp_client): return loop.run_until_complete(aiohttp_client(create_app())) @pytest.fixture def auth_header(): return {"Authorization": config.VENDORAPI_APPKEY} @pytest.fixture async def mongo_session(request, loop): mongo_client = mongodb.init() async def cleanup(): collections = await mongo_client[config.MONGODB_DATABASE].list_collections() collections_names = [c["name"] for c in collections if not c["name"].startswith("system.")] await asyncio.gather(*[mongo_client[config.MONGODB_DATABASE][c].delete_many({}) for c in collections_names]) await cleanup() @request.addfinalizer async def teardown(): await cleanup() return mongodb.mongo_client @pytest.fixture async def redis_session(request, loop): redis_client = redis.init() await redis_client.flushdb() @request.addfinalizer async def teardown(): await redis_client.flushdb() return redis.redis_client