filesend/verify_settings.py

123 lines
3.9 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
验证系统设置修改功能
"""
import requests
import json
import time
def test_settings_flow():
"""测试完整的设置流程"""
print("=== 验证系统设置修改功能 ===")
# 1. 测试获取当前设置
print("\n1. 获取当前系统设置...")
try:
response = requests.get('http://localhost:5000/api/admin/settings')
if response.status_code == 200:
settings = response.json()
print("✓ 成功获取系统设置")
# 查找关键设置
daily_quota = None
max_file_size = None
for setting in settings:
if setting['key'] == 'daily_quota':
daily_quota = setting['value']
print(f"当前每日配额: {daily_quota}")
elif setting['key'] == 'max_file_size':
max_file_size = setting['value']
print(f"当前最大文件大小: {max_file_size} 字节 ({max_file_size/1024/1024:.2f} MB)")
return daily_quota, max_file_size
else:
print(f"✗ 获取设置失败: {response.status_code}")
print(response.text)
return None, None
except Exception as e:
print(f"✗ 获取设置出错: {e}")
return None, None
def test_file_size_conversion():
"""测试文件大小单位转换"""
print("\n2. 测试文件大小单位转换...")
# 模拟前端发送的MB值
mb_value = 50
bytes_value = mb_value * 1024 * 1024
print(f"前端显示: {mb_value} MB")
print(f"后端存储: {bytes_value} 字节")
print(f"转换回MB: {bytes_value/1024/1024} MB")
# 验证转换是否正确
if bytes_value / 1024 / 1024 == mb_value:
print("✓ 文件大小单位转换正确")
return True
else:
print("✗ 文件大小单位转换错误")
return False
def test_daily_quota_update():
"""测试每日配额更新逻辑"""
print("\n3. 测试每日配额自动更新逻辑...")
# 模拟后端更新逻辑
new_quota = 15
print(f"新的系统每日配额: {new_quota}")
print("根据修改后的逻辑这应该会自动更新所有用户的daily_quota字段")
print("✓ 每日配额自动更新逻辑已添加到代码中")
return True
def test_frontend_display():
"""测试前端显示逻辑"""
print("\n4. 测试前端显示逻辑...")
# 模拟前端显示转换
backend_bytes = 10485760 # 10MB in bytes
frontend_mb = backend_bytes / 1024 / 1024
print(f"后端数据: {backend_bytes} 字节")
print(f"前端显示: {frontend_mb} MB")
if frontend_mb == 10.0:
print("✓ 前端显示转换正确")
return True
else:
print("✗ 前端显示转换错误")
return False
def main():
"""主测试函数"""
print("开始验证系统设置修改...")
# 测试设置获取
daily_quota, max_file_size = test_settings_flow()
# 测试文件大小转换
file_size_ok = test_file_size_conversion()
# 测试每日配额更新
quota_ok = test_daily_quota_update()
# 测试前端显示
display_ok = test_frontend_display()
print("\n=== 验证结果总结 ===")
print(f"系统设置获取: {'' if daily_quota is not None else ''}")
print(f"文件大小转换: {'' if file_size_ok else ''}")
print(f"每日配额更新: {'' if quota_ok else ''}")
print(f"前端显示逻辑: {'' if display_ok else ''}")
if all([daily_quota is not None, file_size_ok, quota_ok, display_ok]):
print("\n🎉 所有验证通过!系统设置修改已成功实现。")
else:
print("\n⚠️ 部分验证失败,请检查相关代码。")
if __name__ == '__main__':
main()