#!/usr/bin/env python
"""批量创建测试用例"""
import requests

test_cases = [
    {
        'module_id': 'module_aabcbfc81c6f4ac9978e77a6642d854c',
        'name': '平台首页-基础访问验证',
        'description': '验证平台首页可以正常打开并显示常用功能',
        'priority': 'high',
        'steps': [
            {'order': 1, 'name': '打开平台首页', 'action': 'navigate', 'params': {'url': 'https://192.168.5.44/'}},
            {'order': 2, 'name': '等待页面加载', 'action': 'wait', 'params': {'selector': 'body', 'timeout': 10000}},
            {'order': 3, 'name': '截图保存', 'action': 'screenshot', 'params': {}}
        ],
        'config': {'timeout': 30000, 'screenshot': True}
    },
    {
        'module_id': 'module_6d79f66611b842acb283ffe15e87a1ed',
        'name': '管理后台-页面访问验证',
        'priority': 'medium',
        'steps': [
            {'order': 1, 'name': '打开页面', 'action': 'navigate', 'params': {'url': 'https://192.168.5.44/'}},
            {'order': 2, 'name': '等待加载', 'action': 'wait', 'params': {'selector': 'body', 'timeout': 10000}},
            {'order': 3, 'name': '截图', 'action': 'screenshot', 'params': {}}
        ],
        'config': {'timeout': 30000, 'screenshot': True}
    },
]

modules_for_cases = [
    ('module_c17732d36604472cb5f771ecc867b641', '集控控制', 'high'),
    ('module_4c636e50394d4d1a81f9883679246636', '会议转录', 'medium'),
    ('module_83e49ea4e70848bd8ce81e58bfed02c3', '信息发布', 'medium'),
    ('module_3520418cd5474f8f896ec2df6d99c439', '终端管理', 'medium'),
    ('module_4ce4e97a2feb453caf99a83eee845e20', '预定数据', 'low'),
    ('module_589a128205cf45418d6fcd35fa02a91f', '使用数据', 'low'),
    ('module_554ebfaac37e49e4a7c066152fb7f89f', '故障数据', 'low'),
    ('module_0f4ead2110e748769b5541bcfe443324', '运维数据', 'low'),
    ('module_b72acf42c27c4d62beea4c43c2d3e1e3', '运维统计', 'low'),
    ('module_6bcc95a2adaf47119b1fc566bbca2175', '巡检报表', 'low'),
    ('module_96014b5cded542569472adec3f14113f', '会议统计', 'low'),
    ('module_79cacf2501874f999e8d7290fb1ac8db', '维护工单', 'medium'),
    ('module_e705cb2eedcd4d41ba51ea7c6fa25451', '运维区域', 'medium'),
    ('module_1bea60dba5894b6ab6e4c7faa7e911db', '运维设备', 'medium'),
    ('module_1159ea4e0f5b4d07b1366542b2ef9742', '视讯设备', 'medium'),
    ('module_cf415bb8fe034dd88e3db41657493dec', '登录界面', 'high'),
]

for mid, mname, pri in modules_for_cases:
    test_cases.append({
        'module_id': mid,
        'name': f'{mname}-页面访问验证',
        'description': f'验证{mname}页面可以正常访问',
        'priority': pri,
        'steps': [
            {'order': 1, 'name': '打开页面', 'action': 'navigate', 'params': {'url': 'https://192.168.5.44/'}},
            {'order': 2, 'name': '等待加载', 'action': 'wait', 'params': {'selector': 'body', 'timeout': 10000}},
            {'order': 3, 'name': '截图', 'action': 'screenshot', 'params': {}}
        ],
        'config': {'timeout': 30000, 'screenshot': True}
    })

created = []
for case in test_cases:
    try:
        resp = requests.post('http://localhost:8001/api/cases', json=case)
        if resp.status_code == 201:
            data = resp.json()
            created.append(data['id'])
            print(f'OK: {case["name"]}')
        else:
            print(f'FAIL: {case["name"]} - {resp.status_code}')
    except Exception as e:
        print(f'ERROR: {case["name"]} - {e}')

print(f'\nTotal created: {len(created)} cases')
