mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-12 16:56:02 +00:00
test: add 105 new unit tests for untested core functionality
Add comprehensive tests for B-class issues (core functionality untested): Pipeline: - test_pool.py: QueryPool ID generation, caching, async context (12 tests) - test_ratelimit.py: Fixed timing-sensitive test tolerance - test_pipelinemgr.py: Use real Pydantic StageProcessResult instead of Mock Utils: - test_version.py: Version comparison functions (20 tests) - test_logcache.py: Log page management and retrieval (18 tests) - test_httpclient.py: HTTP session pool management (10 tests) - test_proxy.py: Proxy configuration from env and config (10 tests) - test_image.py: URL parsing and base64 extraction (12 tests) - test_pkgmgr.py: Pip command generation (8 tests) Discover: - test_engine.py: I18nString, Metadata, Component manifest (15 tests) Test count: 1193 → 1298 (+105 tests) Note: Some B-class issues cannot be tested due to circular import bugs filed as GitHub issues #2175 (pipeline) and #2176 (persistence).
This commit is contained in:
192
tests/unit_tests/discover/test_engine.py
Normal file
192
tests/unit_tests/discover/test_engine.py
Normal file
@@ -0,0 +1,192 @@
|
||||
"""
|
||||
Unit tests for discover engine utilities.
|
||||
|
||||
Tests I18nString, Metadata, and Component utilities.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from langbot.pkg.discover.engine import I18nString, Metadata, Component
|
||||
|
||||
|
||||
class TestI18nString:
|
||||
"""Tests for I18nString Pydantic model."""
|
||||
|
||||
def test_create_with_english_only(self):
|
||||
"""Create I18nString with only English."""
|
||||
i18n = I18nString(en_US="Hello")
|
||||
|
||||
assert i18n.en_US == "Hello"
|
||||
assert i18n.zh_Hans is None
|
||||
|
||||
def test_create_with_multiple_languages(self):
|
||||
"""Create I18nString with multiple languages."""
|
||||
i18n = I18nString(
|
||||
en_US="Hello",
|
||||
zh_Hans="你好",
|
||||
zh_Hant="你好",
|
||||
ja_JP="こんにちは",
|
||||
)
|
||||
|
||||
assert i18n.en_US == "Hello"
|
||||
assert i18n.zh_Hans == "你好"
|
||||
assert i18n.zh_Hant == "你好"
|
||||
assert i18n.ja_JP == "こんにちは"
|
||||
|
||||
def test_to_dict_with_english_only(self):
|
||||
"""to_dict returns only non-None fields."""
|
||||
i18n = I18nString(en_US="Hello")
|
||||
|
||||
result = i18n.to_dict()
|
||||
|
||||
assert result == {"en_US": "Hello"}
|
||||
|
||||
def test_to_dict_with_multiple_languages(self):
|
||||
"""to_dict returns all non-None fields."""
|
||||
i18n = I18nString(
|
||||
en_US="Hello",
|
||||
zh_Hans="你好",
|
||||
)
|
||||
|
||||
result = i18n.to_dict()
|
||||
|
||||
assert result == {"en_US": "Hello", "zh_Hans": "你好"}
|
||||
|
||||
def test_to_dict_excludes_none(self):
|
||||
"""to_dict excludes None values."""
|
||||
i18n = I18nString(
|
||||
en_US="Hello",
|
||||
zh_Hans=None,
|
||||
ja_JP="こんにちは",
|
||||
)
|
||||
|
||||
result = i18n.to_dict()
|
||||
|
||||
assert "zh_Hans" not in result
|
||||
assert "en_US" in result
|
||||
assert "ja_JP" in result
|
||||
|
||||
def test_to_dict_all_languages(self):
|
||||
"""to_dict with all supported languages."""
|
||||
i18n = I18nString(
|
||||
en_US="Hello",
|
||||
zh_Hans="你好",
|
||||
zh_Hant="你好",
|
||||
ja_JP="こんにちは",
|
||||
th_TH="สวัสดี",
|
||||
vi_VN="Xin chào",
|
||||
es_ES="Hola",
|
||||
)
|
||||
|
||||
result = i18n.to_dict()
|
||||
|
||||
assert len(result) == 7
|
||||
|
||||
|
||||
class TestMetadata:
|
||||
"""Tests for Metadata Pydantic model."""
|
||||
|
||||
def test_create_minimal(self):
|
||||
"""Create Metadata with required fields only."""
|
||||
from langbot.pkg.discover.engine import I18nString
|
||||
|
||||
metadata = Metadata(
|
||||
name="test-component",
|
||||
label=I18nString(en_US="Test Component"),
|
||||
)
|
||||
|
||||
assert metadata.name == "test-component"
|
||||
assert metadata.label.en_US == "Test Component"
|
||||
|
||||
def test_create_with_all_fields(self):
|
||||
"""Create Metadata with all optional fields."""
|
||||
from langbot.pkg.discover.engine import I18nString
|
||||
|
||||
metadata = Metadata(
|
||||
name="test-component",
|
||||
label=I18nString(en_US="Test"),
|
||||
description=I18nString(en_US="A test component"),
|
||||
version="1.0.0",
|
||||
icon="test-icon",
|
||||
author="Test Author",
|
||||
repository="https://github.com/test/repo",
|
||||
)
|
||||
|
||||
assert metadata.version == "1.0.0"
|
||||
assert metadata.icon == "test-icon"
|
||||
assert metadata.author == "Test Author"
|
||||
|
||||
|
||||
class TestComponentManifest:
|
||||
"""Tests for Component manifest detection."""
|
||||
|
||||
def test_is_component_manifest_valid(self):
|
||||
"""is_component_manifest returns True for valid manifest."""
|
||||
manifest = {
|
||||
'apiVersion': 'v1',
|
||||
'kind': 'Component',
|
||||
'metadata': {'name': 'test'},
|
||||
'spec': {},
|
||||
}
|
||||
|
||||
assert Component.is_component_manifest(manifest) is True
|
||||
|
||||
def test_is_component_manifest_missing_apiversion(self):
|
||||
"""is_component_manifest returns False without apiVersion."""
|
||||
manifest = {
|
||||
'kind': 'Component',
|
||||
'metadata': {'name': 'test'},
|
||||
'spec': {},
|
||||
}
|
||||
|
||||
assert Component.is_component_manifest(manifest) is False
|
||||
|
||||
def test_is_component_manifest_missing_kind(self):
|
||||
"""is_component_manifest returns False without kind."""
|
||||
manifest = {
|
||||
'apiVersion': 'v1',
|
||||
'metadata': {'name': 'test'},
|
||||
'spec': {},
|
||||
}
|
||||
|
||||
assert Component.is_component_manifest(manifest) is False
|
||||
|
||||
def test_is_component_manifest_missing_metadata(self):
|
||||
"""is_component_manifest returns False without metadata."""
|
||||
manifest = {
|
||||
'apiVersion': 'v1',
|
||||
'kind': 'Component',
|
||||
'spec': {},
|
||||
}
|
||||
|
||||
assert Component.is_component_manifest(manifest) is False
|
||||
|
||||
def test_is_component_manifest_missing_spec(self):
|
||||
"""is_component_manifest returns False without spec."""
|
||||
manifest = {
|
||||
'apiVersion': 'v1',
|
||||
'kind': 'Component',
|
||||
'metadata': {'name': 'test'},
|
||||
}
|
||||
|
||||
assert Component.is_component_manifest(manifest) is False
|
||||
|
||||
def test_is_component_manifest_empty(self):
|
||||
"""is_component_manifest returns False for empty dict."""
|
||||
manifest = {}
|
||||
|
||||
assert Component.is_component_manifest(manifest) is False
|
||||
|
||||
def test_is_component_manifest_extra_fields_ok(self):
|
||||
"""is_component_manifest accepts extra fields."""
|
||||
manifest = {
|
||||
'apiVersion': 'v1',
|
||||
'kind': 'Component',
|
||||
'metadata': {'name': 'test'},
|
||||
'spec': {},
|
||||
'extraField': 'ignored',
|
||||
}
|
||||
|
||||
assert Component.is_component_manifest(manifest) is True
|
||||
Reference in New Issue
Block a user