2025-11-10 15:46:40 +01:00
|
|
|
import pytest
|
2025-11-13 23:05:26 +01:00
|
|
|
import pytest_asyncio
|
2025-11-10 15:46:40 +01:00
|
|
|
import asyncio
|
2025-11-13 22:53:40 +01:00
|
|
|
from tortoise import Tortoise
|
|
|
|
|
|
2025-11-13 23:22:05 +01:00
|
|
|
|
|
|
|
|
@pytest_asyncio.fixture(scope="session")
|
|
|
|
|
async def init_db():
|
|
|
|
|
"""Initialize the database for testing."""
|
2025-11-13 22:53:40 +01:00
|
|
|
await Tortoise.init(
|
|
|
|
|
db_url="sqlite://:memory:",
|
2025-11-13 23:22:05 +01:00
|
|
|
modules={"models": ["mywebdav.models"], "billing": ["mywebdav.billing.models"]},
|
2025-11-13 22:53:40 +01:00
|
|
|
)
|
|
|
|
|
await Tortoise.generate_schemas()
|
2025-11-13 23:22:05 +01:00
|
|
|
yield
|
|
|
|
|
await Tortoise.close_connections()
|
2025-11-13 22:53:40 +01:00
|
|
|
|
|
|
|
|
|
2025-11-13 23:22:05 +01:00
|
|
|
@pytest_asyncio.fixture(autouse=True)
|
|
|
|
|
async def setup_db(init_db):
|
|
|
|
|
"""Ensure database is initialized before each test."""
|
|
|
|
|
# The init_db fixture handles the setup
|
2025-11-13 22:53:40 +01:00
|
|
|
yield
|