Fix issues

This commit is contained in:
Urtzi Alfaro
2025-07-18 11:51:43 +02:00
parent 9391368b83
commit 592a810762
35 changed files with 3806 additions and 122 deletions

View File

@@ -0,0 +1,82 @@
# ================================================================
# services/data/tests/conftest.py
# ================================================================
"""Test configuration for data service"""
import pytest
import pytest_asyncio
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, async_sessionmaker
from sqlalchemy.pool import StaticPool
from fastapi.testclient import TestClient
import uuid
from datetime import datetime
from app.main import app
from app.core.database import Base, get_db
from app.models.sales import SalesData
from app.models.weather import WeatherData, WeatherForecast
from app.models.traffic import TrafficData
# Test database URL
TEST_DATABASE_URL = "sqlite+aiosqlite:///:memory:"
# Create test engine
test_engine = create_async_engine(
TEST_DATABASE_URL,
connect_args={"check_same_thread": False},
poolclass=StaticPool,
)
TestingSessionLocal = async_sessionmaker(
test_engine,
class_=AsyncSession,
expire_on_commit=False
)
@pytest_asyncio.fixture
async def db():
"""Create test database session"""
async with test_engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)
async with TestingSessionLocal() as session:
yield session
async with test_engine.begin() as conn:
await conn.run_sync(Base.metadata.drop_all)
@pytest.fixture
def client():
"""Create test client"""
async def override_get_db():
async with TestingSessionLocal() as session:
yield session
app.dependency_overrides[get_db] = override_get_db
with TestClient(app) as test_client:
yield test_client
app.dependency_overrides.clear()
@pytest.fixture
def test_tenant_id():
"""Test tenant ID"""
return uuid.uuid4()
@pytest.fixture
def test_sales_data():
"""Sample sales data for testing"""
return {
"date": datetime.now(),
"product_name": "Pan Integral",
"quantity_sold": 25,
"revenue": 37.50,
"location_id": "madrid_centro",
"source": "test"
}
@pytest.fixture
def mock_auth_token():
"""Mock authentication token"""
return "Bearer test-token-123"