127 lines
3.5 KiB
Python
127 lines
3.5 KiB
Python
|
|
"""
|
||
|
|
Pytest configuration and fixtures for Calejo Control Adapter tests.
|
||
|
|
"""
|
||
|
|
|
||
|
|
import asyncio
|
||
|
|
import pytest
|
||
|
|
import pytest_asyncio
|
||
|
|
from typing import Dict, Any, AsyncGenerator
|
||
|
|
|
||
|
|
from src.database.client import DatabaseClient
|
||
|
|
from src.core.auto_discovery import AutoDiscovery
|
||
|
|
from src.core.safety import SafetyLimitEnforcer
|
||
|
|
from src.core.logging import setup_logging
|
||
|
|
from config.settings import settings
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.fixture(scope="session")
|
||
|
|
def event_loop():
|
||
|
|
"""Create an instance of the default event loop for the test session."""
|
||
|
|
loop = asyncio.get_event_loop_policy().new_event_loop()
|
||
|
|
yield loop
|
||
|
|
loop.close()
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.fixture(scope="session")
|
||
|
|
def test_settings():
|
||
|
|
"""Test settings with test database configuration."""
|
||
|
|
# Override settings for testing
|
||
|
|
settings.db_name = "calejo_test"
|
||
|
|
settings.db_user = "control_reader_test"
|
||
|
|
settings.environment = "testing"
|
||
|
|
settings.log_level = "WARNING" # Reduce log noise during tests
|
||
|
|
return settings
|
||
|
|
|
||
|
|
|
||
|
|
@pytest_asyncio.fixture(scope="session")
|
||
|
|
async def test_db_client(test_settings) -> AsyncGenerator[DatabaseClient, None]:
|
||
|
|
"""Test database client with test database."""
|
||
|
|
client = DatabaseClient(
|
||
|
|
database_url=test_settings.database_url,
|
||
|
|
min_connections=1,
|
||
|
|
max_connections=3
|
||
|
|
)
|
||
|
|
await client.connect()
|
||
|
|
yield client
|
||
|
|
await client.disconnect()
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.fixture
|
||
|
|
def mock_pump_data() -> Dict[str, Any]:
|
||
|
|
"""Mock pump data for testing."""
|
||
|
|
return {
|
||
|
|
"station_id": "TEST_STATION",
|
||
|
|
"pump_id": "TEST_PUMP",
|
||
|
|
"pump_name": "Test Pump",
|
||
|
|
"pump_type": "SUBMERSIBLE",
|
||
|
|
"control_type": "DIRECT_SPEED",
|
||
|
|
"manufacturer": "Test Manufacturer",
|
||
|
|
"model": "Test Model",
|
||
|
|
"rated_power_kw": 50.0,
|
||
|
|
"min_speed_hz": 20.0,
|
||
|
|
"max_speed_hz": 50.0,
|
||
|
|
"default_setpoint_hz": 35.0,
|
||
|
|
"control_parameters": {"speed_ramp_rate": 5.0},
|
||
|
|
"active": True
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.fixture
|
||
|
|
def mock_safety_limits() -> Dict[str, Any]:
|
||
|
|
"""Mock safety limits for testing."""
|
||
|
|
return {
|
||
|
|
"station_id": "TEST_STATION",
|
||
|
|
"pump_id": "TEST_PUMP",
|
||
|
|
"hard_min_speed_hz": 20.0,
|
||
|
|
"hard_max_speed_hz": 50.0,
|
||
|
|
"hard_min_level_m": 1.0,
|
||
|
|
"hard_max_level_m": 4.0,
|
||
|
|
"emergency_stop_level_m": 4.5,
|
||
|
|
"dry_run_protection_level_m": 0.8,
|
||
|
|
"hard_max_power_kw": 60.0,
|
||
|
|
"hard_max_flow_m3h": 300.0,
|
||
|
|
"max_speed_change_hz_per_min": 5.0
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.fixture
|
||
|
|
def mock_station_data() -> Dict[str, Any]:
|
||
|
|
"""Mock station data for testing."""
|
||
|
|
return {
|
||
|
|
"station_id": "TEST_STATION",
|
||
|
|
"station_name": "Test Station",
|
||
|
|
"location": "Test Location",
|
||
|
|
"latitude": 45.4642035,
|
||
|
|
"longitude": 9.189982,
|
||
|
|
"timezone": "Europe/Rome",
|
||
|
|
"active": True
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.fixture
|
||
|
|
def mock_pump_plan() -> Dict[str, Any]:
|
||
|
|
"""Mock pump plan for testing."""
|
||
|
|
return {
|
||
|
|
"station_id": "TEST_STATION",
|
||
|
|
"pump_id": "TEST_PUMP",
|
||
|
|
"target_flow_m3h": 250.0,
|
||
|
|
"target_power_kw": 45.0,
|
||
|
|
"target_level_m": 2.5,
|
||
|
|
"suggested_speed_hz": 40.0
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.fixture
|
||
|
|
def mock_feedback_data() -> Dict[str, Any]:
|
||
|
|
"""Mock feedback data for testing."""
|
||
|
|
return {
|
||
|
|
"station_id": "TEST_STATION",
|
||
|
|
"pump_id": "TEST_PUMP",
|
||
|
|
"actual_speed_hz": 39.5,
|
||
|
|
"actual_power_kw": 44.2,
|
||
|
|
"actual_flow_m3h": 248.5,
|
||
|
|
"wet_well_level_m": 2.48,
|
||
|
|
"pump_running": True,
|
||
|
|
"alarm_active": False,
|
||
|
|
"alarm_code": None
|
||
|
|
}
|