tech-bid-manageV1.120260424/tests/test_qwen_image_client.py
2026-04-24 14:44:38 +08:00

30 lines
892 B
Python

"""qwen-image 客户端:响应解析与提示词拼装(无网络)。"""
import unittest
from utils import qwen_image_client as qic
class TestQwenImageClient(unittest.TestCase):
def test_extract_image_url(self):
payload = {
'output': {
'choices': [
{'message': {'content': [{'image': 'https://example.com/a.png'}]}}
]
}
}
self.assertEqual(qic._extract_image_url(payload), 'https://example.com/a.png')
def test_extract_image_url_empty(self):
self.assertIsNone(qic._extract_image_url({}))
def test_build_attachment_prompt_truncates(self):
long_body = 'x' * 2000
p = qic.build_attachment_figure_prompt('标题', long_body)
self.assertLessEqual(len(p), 900)
self.assertIn('标题', p)
if __name__ == '__main__':
unittest.main()