test: add unit tests for handler-base
- tests/conftest.py: Pytest fixtures and configuration - tests/unit/test_config.py: Settings tests - tests/unit/test_nats_client.py: NATS client tests - tests/unit/test_health.py: Health server tests - tests/unit/test_clients.py: Service client tests - pytest.ini: Pytest configuration
This commit is contained in:
47
tests/unit/test_config.py
Normal file
47
tests/unit/test_config.py
Normal file
@@ -0,0 +1,47 @@
|
||||
"""
|
||||
Unit tests for handler_base.config module.
|
||||
"""
|
||||
import os
|
||||
import pytest
|
||||
|
||||
|
||||
class TestSettings:
|
||||
"""Tests for Settings configuration."""
|
||||
|
||||
def test_default_settings(self, settings):
|
||||
"""Test that default settings are loaded correctly."""
|
||||
assert settings.service_name == "test-service"
|
||||
assert settings.service_version == "1.0.0-test"
|
||||
assert settings.otel_enabled is False
|
||||
|
||||
def test_settings_from_env(self, monkeypatch):
|
||||
"""Test that settings can be loaded from environment variables."""
|
||||
monkeypatch.setenv("SERVICE_NAME", "env-service")
|
||||
monkeypatch.setenv("SERVICE_VERSION", "2.0.0")
|
||||
monkeypatch.setenv("NATS_URL", "nats://custom:4222")
|
||||
|
||||
# Need to reimport to pick up env changes
|
||||
from handler_base.config import Settings
|
||||
s = Settings()
|
||||
|
||||
assert s.service_name == "env-service"
|
||||
assert s.service_version == "2.0.0"
|
||||
assert s.nats_url == "nats://custom:4222"
|
||||
|
||||
def test_embeddings_settings(self):
|
||||
"""Test EmbeddingsSettings extends base correctly."""
|
||||
from handler_base.config import EmbeddingsSettings
|
||||
|
||||
s = EmbeddingsSettings()
|
||||
assert hasattr(s, "embeddings_model")
|
||||
assert hasattr(s, "embeddings_batch_size")
|
||||
assert s.embeddings_model == "bge"
|
||||
|
||||
def test_llm_settings(self):
|
||||
"""Test LLMSettings has expected defaults."""
|
||||
from handler_base.config import LLMSettings
|
||||
|
||||
s = LLMSettings()
|
||||
assert s.llm_max_tokens == 2048
|
||||
assert s.llm_temperature == 0.7
|
||||
assert 0 <= s.llm_top_p <= 1
|
||||
Reference in New Issue
Block a user