133 lines
4.5 KiB
Python
133 lines
4.5 KiB
Python
"""
|
|
Tests for Dashboard Pydantic models
|
|
"""
|
|
|
|
import pytest
|
|
|
|
from src.dashboard.api import (
|
|
SystemConfig,
|
|
DatabaseConfig,
|
|
OPCUAConfig,
|
|
ModbusConfig,
|
|
RESTAPIConfig,
|
|
MonitoringConfig,
|
|
SecurityConfig
|
|
)
|
|
|
|
|
|
class TestDashboardModels:
|
|
"""Test dashboard Pydantic models"""
|
|
|
|
def test_database_config_defaults(self):
|
|
"""Test DatabaseConfig with default values"""
|
|
config = DatabaseConfig()
|
|
assert config.db_host == "localhost"
|
|
assert config.db_port == 5432
|
|
assert config.db_name == "calejo"
|
|
assert config.db_user == "calejo"
|
|
assert config.db_password == ""
|
|
|
|
def test_opcua_config_defaults(self):
|
|
"""Test OPCUAConfig with default values"""
|
|
config = OPCUAConfig()
|
|
assert config.enabled == True
|
|
assert config.host == "localhost"
|
|
assert config.port == 4840
|
|
|
|
def test_modbus_config_defaults(self):
|
|
"""Test ModbusConfig with default values"""
|
|
config = ModbusConfig()
|
|
assert config.enabled == True
|
|
assert config.host == "localhost"
|
|
assert config.port == 502
|
|
assert config.unit_id == 1
|
|
|
|
def test_rest_api_config_defaults(self):
|
|
"""Test RESTAPIConfig with default values"""
|
|
config = RESTAPIConfig()
|
|
assert config.enabled == True
|
|
assert config.host == "0.0.0.0"
|
|
assert config.port == 8080
|
|
assert config.cors_enabled == True
|
|
|
|
def test_monitoring_config_defaults(self):
|
|
"""Test MonitoringConfig with default values"""
|
|
config = MonitoringConfig()
|
|
assert config.health_monitor_port == 9090
|
|
assert config.metrics_enabled == True
|
|
|
|
def test_security_config_defaults(self):
|
|
"""Test SecurityConfig with default values"""
|
|
config = SecurityConfig()
|
|
assert config.jwt_secret_key == ""
|
|
assert config.api_key == ""
|
|
|
|
def test_system_config_creation(self):
|
|
"""Test SystemConfig creation with all components"""
|
|
system_config = SystemConfig(
|
|
database=DatabaseConfig(),
|
|
opcua=OPCUAConfig(),
|
|
modbus=ModbusConfig(),
|
|
rest_api=RESTAPIConfig(),
|
|
monitoring=MonitoringConfig(),
|
|
security=SecurityConfig()
|
|
)
|
|
|
|
assert system_config.database.db_host == "localhost"
|
|
assert system_config.opcua.port == 4840
|
|
assert system_config.modbus.port == 502
|
|
assert system_config.rest_api.port == 8080
|
|
assert system_config.monitoring.health_monitor_port == 9090
|
|
|
|
def test_database_config_custom_values(self):
|
|
"""Test DatabaseConfig with custom values"""
|
|
config = DatabaseConfig(
|
|
db_host="custom_host",
|
|
db_port=5433,
|
|
db_name="custom_db",
|
|
db_user="custom_user",
|
|
db_password="custom_password"
|
|
)
|
|
assert config.db_host == "custom_host"
|
|
assert config.db_port == 5433
|
|
assert config.db_name == "custom_db"
|
|
assert config.db_user == "custom_user"
|
|
assert config.db_password == "custom_password"
|
|
|
|
def test_opcua_config_disabled(self):
|
|
"""Test OPCUAConfig with disabled server"""
|
|
config = OPCUAConfig(enabled=False, port=4841)
|
|
assert config.enabled == False
|
|
assert config.port == 4841
|
|
|
|
def test_modbus_config_custom_values(self):
|
|
"""Test ModbusConfig with custom values"""
|
|
config = ModbusConfig(enabled=False, port=503, unit_id=2)
|
|
assert config.enabled == False
|
|
assert config.port == 503
|
|
assert config.unit_id == 2
|
|
|
|
def test_rest_api_config_custom_values(self):
|
|
"""Test RESTAPIConfig with custom values"""
|
|
config = RESTAPIConfig(
|
|
enabled=False,
|
|
host="127.0.0.1",
|
|
port=8081,
|
|
cors_enabled=False
|
|
)
|
|
assert config.enabled == False
|
|
assert config.host == "127.0.0.1"
|
|
assert config.port == 8081
|
|
assert config.cors_enabled == False
|
|
|
|
def test_monitoring_config_custom_values(self):
|
|
"""Test MonitoringConfig with custom values"""
|
|
config = MonitoringConfig(health_monitor_port=9091, metrics_enabled=False)
|
|
assert config.health_monitor_port == 9091
|
|
assert config.metrics_enabled == False
|
|
|
|
def test_security_config_custom_values(self):
|
|
"""Test SecurityConfig with custom values"""
|
|
config = SecurityConfig(jwt_secret_key="custom_secret", api_key="custom_api_key")
|
|
assert config.jwt_secret_key == "custom_secret"
|
|
assert config.api_key == "custom_api_key" |