clone / tests /unit /test_entities.py
tanbushi's picture
update
82f9be0
"""
实体信息测试
"""
import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
import unittest
from src.core import EntityInfo
class TestEntityInfo(unittest.TestCase):
"""测试EntityInfo类"""
def test_entity_creation(self):
"""测试实体创建"""
entity = EntityInfo(
id="test-001",
name="Test Entity",
redis_host="localhost",
redis_port=6379,
redis_db=0,
channel="test-channel"
)
self.assertEqual(entity.id, "test-001")
self.assertEqual(entity.name, "Test Entity")
self.assertEqual(entity.redis_host, "localhost")
self.assertEqual(entity.redis_port, 6379)
self.assertEqual(entity.redis_db, 0)
self.assertEqual(entity.channel, "test-channel")
def test_auto_uuid_generation(self):
"""测试UUID自动生成"""
entity = EntityInfo(
id="", # 空ID应该自动生成UUID
name="Test Entity",
redis_host="localhost",
redis_port=6379,
redis_db=0,
channel="test-channel"
)
self.assertIsNotNone(entity.id)
self.assertNotEqual(entity.id, "")
def test_auto_channel_assignment(self):
"""测试channel自动赋值"""
entity = EntityInfo(
id="test-001",
name="Test Entity",
redis_host="localhost",
redis_port=6379,
redis_db=0,
channel="" # 空channel应该自动使用ID
)
self.assertEqual(entity.channel, "test-001")
if __name__ == "__main__":
unittest.main()