#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ 测试系统设置修改功能 """ import requests import json # 测试获取系统设置 def test_get_settings(): print("=== 测试获取系统设置 ===") try: response = requests.get('http://localhost:5000/api/admin/settings') if response.status_code == 200: settings = response.json() print("获取设置成功") for setting in settings: if setting['key'] in ['daily_quota', 'max_file_size']: print(f"{setting['key']}: {setting['value']} ({type(setting['value'])})") else: print(f"获取设置失败: {response.status_code}") print(response.text) except Exception as e: print(f"获取设置出错: {e}") # 测试更新每日配额 def test_update_daily_quota(): print("\n=== 测试更新每日配额 ===") try: # 注意:这里需要管理员权限,实际测试需要JWT token data = { 'daily_quota': 10 } response = requests.put('http://localhost:5000/api/admin/settings', json=data, headers={'Content-Type': 'application/json'}) print(f"更新每日配额响应: {response.status_code}") print(response.text) except Exception as e: print(f"更新每日配额出错: {e}") # 测试更新文件大小 def test_update_max_file_size(): print("\n=== 测试更新文件大小 ===") try: # 注意:这里需要管理员权限,实际测试需要JWT token data = { 'max_file_size': 20 * 1024 * 1024 # 20MB in bytes } response = requests.put('http://localhost:5000/api/admin/settings', json=data, headers={'Content-Type': 'application/json'}) print(f"更新文件大小响应: {response.status_code}") print(response.text) except Exception as e: print(f"更新文件大小出错: {e}") if __name__ == '__main__': print("开始测试系统设置功能...") test_get_settings() test_update_daily_quota() test_update_max_file_size() print("\n测试完成!")