File size: 1,743 Bytes
82f9be0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
"""
实体信息测试
"""
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() |