文件
nahaichuan/tests/test_dedicated_page_illustrations.py

66 行
3.4 KiB
Python

"""
全站独立页面精美视觉配图规范专项测试 (Dedicated Page Illustrations Test)
严格遵循 TDD 模式:
1. 验证软件定制独立页、APP定制独立页、智能体独立页、联系我们页均配有专属高品质视窗图;
2. 验证新版服务页摄影配图真实存在、尺寸满足首屏展示要求,并提供 WebP 兼容版本;
3. 验证联系我们页矢量配图符合浅色专业风规范。
"""
import os
import unittest
from PIL import Image
ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
RASTER_ROOT = os.path.join(ROOT_DIR, 'public', 'assets', 'addons', 'official', 'images')
SHOWCASE_ROOT = os.path.join(RASTER_ROOT, 'showcases')
SERVICE_HEROES = {
'software': ('software/structure-v2.jpg', 1440, 960),
'app': ('app/terminals.jpg', 1440, 960),
'agent': ('agent/landscape-v2.jpg', 1920, 640),
}
class TestDedicatedPageIllustrations(unittest.TestCase):
def test_illustration_assets_exist(self):
"""测试专属配图文件存在、格式有效且尺寸满足展示要求"""
for key, (relative_path, minimum_width, minimum_height) in SERVICE_HEROES.items():
with self.subTest(page=key):
jpg_path = os.path.join(RASTER_ROOT, relative_path)
webp_path = os.path.splitext(jpg_path)[0] + '.webp'
self.assertTrue(os.path.isfile(jpg_path), f"缺少专属精美配图: {relative_path}")
self.assertTrue(os.path.isfile(webp_path), f"缺少 WebP 兼容版本: {relative_path}")
with Image.open(jpg_path) as hero:
width, height = hero.size
self.assertGreaterEqual(width, minimum_width, f"{relative_path} 宽度不足首屏要求")
self.assertGreaterEqual(height, minimum_height, f"{relative_path} 高度不足首屏要求")
self.assertGreater(os.path.getsize(jpg_path), 50_000, f"{relative_path} 文件过小")
contact_path = os.path.join(SHOWCASE_ROOT, 'contact_headquarters.svg')
with open(contact_path, encoding='utf-8') as stream:
contact_content = stream.read()
self.assertIn('<svg', contact_content, 'contact_headquarters.svg 必须是有效矢量 SVG')
def test_pages_embed_dedicated_illustrations(self):
"""测试各独立页面均正确嵌入对应的精美配图"""
pages = {
'software': ('official_product/service_software.html', 'images/software/structure-v2.jpg'),
'app': ('official_product/service_app.html', 'images/app/terminals.jpg'),
'agent': ('official_product/service_agent.html', 'images/agent/landscape-v2.jpg'),
'contact_pc': ('official_online_message/list.html', 'contact_headquarters.svg'),
'contact_m': ('official_online_message/list_e.html', 'contact_headquarters.svg'),
}
template_dir = os.path.join(ROOT_DIR, 'addons', 'official', 'view', 'web')
for key, (template_relative_path, image_name) in pages.items():
with self.subTest(page=key):
template_path = os.path.join(template_dir, template_relative_path)
with open(template_path, encoding='utf-8') as stream:
html = stream.read()
self.assertIn(image_name, html, f"页面 {template_relative_path} 必须正确引用专属配图 {image_name}")
if __name__ == '__main__':
unittest.main()